栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Android~老项目项目升级Gradle&AGP 7.0踩坑

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Android~老项目项目升级Gradle&AGP 7.0踩坑

结合最近对公司项目做了一下升级,踩了点坑。记录一下,方便后续有人参考。

module模块build.gradle变化
  • apply plugin变成了plugins
  • 对部分android闭包下面的属性也做了缩短优化,但但可以不修改。
  • apply from 还可正常使用,plugins的顺序还要放前面。
  • 去除dexOptions, 删除javaCompileOptions注解处理器配置否则项目无法正常sync,使用kapt替换。
plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
    id 'kotlin-android'
    id 'kotlin-kapt'
    id 'com.google.firebase.crashlytics' apply false
    id 'com.google.gms.google-services'
}
//apply plugin: 'com.android.application'
//apply plugin: 'kotlin-android'
//apply plugin: 'kotlin-android-extensions'
//apply plugin: 'kotlin-kapt'
//apply plugin: 'com.google.firebase.crashlytics'
apply from: 'config.gradle'
android {
    compileSdk 31
    defaultConfig {
        versionCode 1
        versionName '1.0'
        minSdk 21
        targetSdk 31
	}
//    dexOptions {
//        preDexLibraries true
//        maxProcessCount 8
//        threadCount 8
//        javaMaxHeapSize "6g"
//        jumboMode true
//    }
}

项目gradle
  • seeting.gradle新增了插件管理
  • 如果使用了http,需要在maven中配置allowInsecureProtocol = true
pluginManagement {
    repositories {
        gradlePluginPortal()
        google()
        mavenCentral()
    }
}
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
    }
}

maven {
		url 'http://maven.aliyun.com/nexus/content/groups/public/'
		allowInsecureProtocol = true
}
问题记录

A problem occurred evaluating project ‘:app’.
Failed to apply plugin ‘com.android.internal.application’.
The option ‘android.enableBuildCache’ is deprecated.
The current default is ‘false’.
It was removed in version 7.0 of the Android Gradle plugin.
The Android-specific build caches were superseded by the Gradle build cache (https://docs.gradle.org/current/userguide/build_cache.html).

  1. gradle.properties文件,把 android.enableBuildCache=true 和 android.buildCacheDir=./build/buildCache/注销掉。

Firebase Crashlytics - java.lang.IllegalStateException: The Crashlytics build ID is missing.

  1. 遇到问题,脚本能正常编译后运行程序启动奔溃,有如下日志,原来是crashlytics没有被启动apply false 改为true。

Method ‘buildStarted’ from class ‘BuildTraceListener’ does not override method from its superclass or interfaces but is annotated with @Override.

  1. Gradle 7.0移除了BuildListener.buildStarted(Gradle),直接删除buildStarted方法即可。
    改用BuildListener.beforeSettings(Settings)代替。

java.lang.RuntimeException: Manifest merger failed with multiple errors

  1. 打开每个模块的清单文件切到Merged Manifest视图查看合并错误。

using Jetifier. Reason: AmbiguousStringJetifierException, message: The given
Execution failed for task ‘:app:javaPreCompileDebug’.
Could not resolve all files for configuration ‘:app:debugAnnotationProcessorClasspath’.
Failed to transform butterknife-compiler-8.8.1.jar (com.jakewharton:butterknife-compiler:8.8.1) to match attributes {artifactType=processed-jar, org.gradle.category=library, org.gradle.libraryelements=jar, org.gradle.status=release, org.gradle.usage=java-runtime}.
Execution failed for JetifyTransform: /Users/mahui/.gradle/caches/modules-2/files-2.1/com.jakewharton/butterknife-compiler/8.8.1/b2f4505a1babb7b7c11abbbf8ea4c90b18c3aeac/butterknife-compiler-8.8.1.jar.
Failed to transform ‘/Users/mahui/.gradle/caches/modules-2/files-2.1/com.jakewharton/butterknife-compiler/8.8.1/b2f4505a1babb7b7c11abbbf8ea4c90b18c3aeac/butterknife-compiler-8.8.1.jar’ using Jetifier. Reason: AmbiguousStringJetifierException, message: The given artifact contains a string literal with a package reference ‘android.support.v4.content’ that cannot be safely rewritten. Libraries using reflection such as annotation processors need to be updated manually to add support for androidx… (Run with --stacktrace for more details.)
This is a known exception, and Jetifier won’t be able to jetify this library.
Suggestions:
- If you believe this library doesn’t need to be jetified (e.g., if it already supports AndroidX, or if it doesn’t use support libraries/AndroidX at all), add android.jetifier.blacklist = {comma-separated list of regular expressions (or simply names) of the libraries that you don’t want to be jetified} to the gradle.properties file.
- If you believe this library needs to be jetified (e.g., if it uses old support libraries and breaks your app if it isn’t jetified), contact the library’s authors to update this library to support AndroidX and use the supported version once it is released.
If you need further help, please leave a comment at https://issuetracker.google.com/issues/140747218.

  1. 出现了support和androidx迁移遗留问题,虽然我们项目已经迁移了androidx,但可能不彻底。这边暂时的解决办法是根据提示信息在gradle.properties配置文件中增加:android.jetifier.ignorelist=bundletool-1.6.0.jar,同步一下重新编译居然通过了。
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/979534.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号