升级我们项目的 API 版本等级已经是必须提上日程了,同时 AS 版本等级、Gradle 版本也是我们升级绕不开的一环,总不能 API 等级提高了,项目还基于低版本的 Gradle 吧。下文我们将简单讲讲,在升级 Gradle 版本时需要注意的一些问题,以及出现相关问题时的解决方法,愿各位小伙伴都愉快的升级。
Could not find com.android.tools.build:gradle:3.1.3. Searched in the following locations: https://jcenter.bintray.com/com/android/tools/build/gradle/3.1.3/gradle-3.1.3.pom https://jcenter.bintray.com/com/android/tools/build/gradle/3.1.3/gradle-3.1.3.jar Required by: project : Add Google Maven repository and sync project Open File Enable embedded Maven repository and sync project
按照提示操作,添加 Google 仓库依赖即可。
2、修改因 Gradle 版本升级导致的异常
1. 修改输出apk文件名:
1 2
Cannot set the value of read-only property 'outputFile' for ApkVariantOutputImpl_Decorated{apkData=Main{type=MAIN, fullName=uerblybUerb, filters=[]}} of type com.android.build.gradle.internal.api.ApkVariantOutputImpl. Open File
Cannot choose between the following configurations of project :mainnavigatetabbar: - debugApiElements - debugRuntimeElements - releaseApiElements - releaseRuntimeElements All of them match the consumer attributes: - Configuration 'debugApiElements': - Found com.android.build.api.attributes.BuildTypeAttr 'debug' but wasn't required. - Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required. - Found com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but wasn't required. - Found org.gradle.usage 'java-api' but wasn't required. - Configuration 'debugRuntimeElements': - Found com.android.build.api.attributes.BuildTypeAttr 'debug' but wasn't required. - Found com.android.build.api.attributes.VariantAttr 'debug' but wasn't required. - Found com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but wasn't required. - Found org.gradle.usage 'java-runtime' but wasn't required. - Configuration 'releaseApiElements': - Found com.android.build.api.attributes.BuildTypeAttr 'release' but wasn't required. - Found com.android.build.api.attributes.VariantAttr 'release' but wasn't required. - Found com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but wasn't required. - Found org.gradle.usage 'java-api' but wasn't required. - Configuration 'releaseRuntimeElements': - Found com.android.build.api.attributes.BuildTypeAttr 'release' but wasn't required. - Found com.android.build.api.attributes.VariantAttr 'release' but wasn't required. - Found com.android.build.gradle.internal.dependency.AndroidTypeAttr 'Aar' but wasn't required. - Found org.gradle.usage 'java-runtime' but wasn't required.
The specified Android SDK Build Tools version (23.0.3) is ignored, as it is below the minimum supported version (27.0.3) for Android Gradle Plugin 3.1.3. Android SDK Build Tools 27.0.3 will be used. To suppress this warning, remove "buildToolsVersion '23.0.3'" from your build.gradle file, as each version of the Android Gradle Plugin now has a default version of the build tools. Update Build Tools version and sync project Open File
Unable to resolve dependency for ':app@xxxxXXXX(flavor + buildtype)/compileClasspath': Could not resolve project :xxxxxx(依赖的模块). Open File Show Details
5. AAPT2 检查错误:
1 2 3 4 5
FAILURE: Build failed with an exception.
* What went wrong: Execution failed for task ':app:mergeUerblUerbResources'. > Error: java.util.concurrent.ExecutionException: com.android.builder.internal.aapt.v2.Aapt2Exception: AAPT2 error: check logs for details