【发布时间】:2018-03-30 01:16:19
【问题描述】:
我在更新 Android Gradle 插件和 Android Studio 后收到此错误。
我已经检查了这个问题 (Android Studio build.gradle warning message),但我无法运行该项目。
【问题讨论】:
标签: android-studio gradle plugins
我在更新 Android Gradle 插件和 Android Studio 后收到此错误。
我已经检查了这个问题 (Android Studio build.gradle warning message),但我无法运行该项目。
【问题讨论】:
标签: android-studio gradle plugins
逐步解决方案
1- 转到 build.gradle(module app)
2- 在依赖中,你会看到这样的代码
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:support-v4:23.3.0'
compile 'com.android.support:design:23.3.0'
3- 现在您必须仅将 compile 替换为 implementation,并将 testCompile 替换为 testImplementation。像这样
implementation fileTree(dir: 'libs', include: ['*.jar'])
testImplementation 'junit:junit:4.12'
implementation 'com.android.support:appcompat-v7:23.3.0'
implementation 'com.android.support:support-v4:23.3.0'
implementation 'com.android.support:design:23.3.0'
4- 就是这样。现在点击立即同步按钮。
注意-不要更改代码中指定的数字或版本。
【讨论】:
这里是完整的解决方案:
步骤
1) 在 gradle 文件中使用新的依赖配置 用实现替换 compile 例如:
dependencies {
compile 'com.android.support:support-v4:27.0.3'
}
应该是:
dependencies {
implementation 'com.android.support:support-v4:27.0.3'
}
b) 将testCompile 替换为testImplementation
例如:
testCompile 'junit:junit:4.12'
应该是
testImplementation 'junit:junit:4.12'
c) 对于库,将 compile 替换为 api
2) 将 build.gradle 文件中的类路径 com.google.gms:google-services 升级为类路径 'com.google.gms:google-services:3.2.0'(使用最新的)
3) 文件 -> 使缓存无效
仍然无法正常工作:然后尝试以下步骤
1)关闭项目。
2) 删除 .gradle 文件夹。
3)再次打开项目
现在可以了
【讨论】:
查看 build.gradle 中的依赖项。在您编译的任何地方,更改为实现。 例如:
dependencies {
compile 'com.android.support:support-v4:27.0.3'
}
应该是:
dependencies {
implementation 'com.android.support:support-v4:27.0.3'
}
【讨论】:
只需转到您的应用>>“Gradle Scripts”并打开 build.gradle(Project:"your project name") 并更改此行 (classpath 'com.google.gms:google-services:3.1. 0')到(类路径'com.google.gms:google-services:3.2.0')。当前版本 4.0.1
【讨论】:
说明:
由于 compile 在 2018 年已过时,您必须按如下方式更改此配置: 1. 打开 build.gradle(module:app) 应用文件并在其中进行以下更改。 2. 将 compile 替换为 api 任何 api ref。 like: volley, GitHubdependancy.strong 文本使用和 3. 使用 implementation 替换 compile 以防使用 play-services-maps、appcompat-v7 等 Android 库。
示例: 老办法
dependencies {
testCompile'junit:junit:4.12'
compile 'com.android.volley:volley:1.1.0'
改成:
dependencies {
testImplementation 'junit:junit:4.12'
implementation 'com.android.volley:volley:1.1.0'
如果问题仍然存在:
打开build.gradle(项目:yourproject)文件 并将 google gms 服务更改为最新的
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
如果 gradle 同步仍然失败:
打开 gradle-wrapper.properties 文件并将其替换为以下内容:
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
【讨论】: