尝试将 android studio 中的 java 版本从 jdk1.8 更改为 jdk 1.7 时出现此错误。
错误:
Error:Unable to find method com.google.common.io.CharSource.readLines'(Lcom/google/common/io/LineProcessor;)Ljava/lang/Object;'.
Possible causes for this unexpected error include:
梯度错误
- Gradle 的依赖缓存可能已损坏(这有时会在网络连接超时后发生。) 重新下载依赖和同步项目(需要网络)
- Gradle 构建过程(守护进程)的状态可能已损坏。停止所有 Gradle 守护进程可能会解决这个问题。 停止 Gradle 构建过程(需要重新启动)
- 您的项目可能正在使用与项目中的其他插件或项目请求的 Gradle 版本不兼容的第三方插件。
build.gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
应用:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion '23.0.2'
defaultConfig {
applicationId "com.something.something"
minSdkVersion 21
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile project(path: ':backend', configuration: 'android-endpoints')
}
后端:
// If you would like more information on the gradle-appengine-plugin please refer to the github page
// https://github.com/GoogleCloudPlatform/gradle-appengine-plugin
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.google.appengine:gradle-appengine-plugin:1.9.18'
}
}
repositories {
jcenter();
}
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'appengine'
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
dependencies {
appengineSdk 'com.google.appengine:appengine-java-sdk:1.9.18'
compile 'com.google.appengine:appengine-api-1.0-sdk:1.9.18'
compile 'com.google.appengine:appengine-endpoints:1.9.18'
compile 'com.google.appengine:appengine-endpoints-deps:1.9.18'
compile 'com.googlecode.objectify:objectify:5.0.3'
compile 'javax.servlet:servlet-api:2.5'
compile 'com.ganyo:gcm-server:1.0.2'
}
appengine {
downloadSdk = true
appcfg {
oauth2 = true
}
endpoints {
getClientLibsOnBuild = true
getDiscoveryDocsOnBuild = true
}
}
最佳答案
在 guava-16.0.1.jar 或 + 中添加了重载的 readLines(LineProcessor 处理器) 函数。但是 JAVA 1.8.0.25 使用 guava-14.0.1.jar。所以我们需要将 JAVA 更新到 1.8.0.66(或更低版本,但应该更新 guava jar)。
关于android - Gradle 失败 - 无法找到方法 com.google.common.io.CharSource.readLines,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37497308/