前言:

gradle文档: https://developer.android.google.cn/studio/releases/gradle-plugin?hl=zh-cn
现在的项目是gradle6.7.1,一般来说项目能正常稳定编译我是不想动版本的,但是领导发话了需要升级到最新版本,那就动手吧。
先是查询了下最新的版本 ,没想到版本都更新到gradle8.0了,想着要不要把版本升级到最高呢,查询了下gradle文档发现我的as最高也就支持7.5,如果要升级到8.0需要把as升级下,而且8.0做了很多改动删除了一些方法,kotlin的版本也需要升级,这点我接受不了,既然我最关心的编译速度,7.5版本优化了这块,那就先升级到7.5吧!

步骤1:

将gradle插件版本改成 classpath ‘com.android.tools.build:gradle:7.4.2’
注:去官网查询匹配的插件版本号
image.png

步骤2:

替换gradle版本image.png

步骤3:

将插件引用改成Plugins模块引用,这一步可不做,没发现具体好处,只是官方推荐。

运行后报错,一个一个解决

错误1

提示android.enableBuildCache已经弃用,直接删除就行


An exception occurred applying plugin request [id: 'com.android.application']
> 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).

* Try:
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
错误2

看提示是说ribbonizeDebug需要添加注解,但这是一个插件包我改不了里面的代码,开始觉得是gradle下载问题,最后尝试一些下载方式还是不行,最后怀疑是这个插件引用的gradle版本太老了,想了半天没什么办法只能去网上查询了一个比较新的开源库。

Some problems were found with the configuration of task ':app:ribbonizeDebug' (type 'RibbonizerTask').
  - In plugin 'com.github.gfx.ribbonizer' type 'com.github.gfx.ribbonizer.plugin.RibbonizerTask' property 'androidManifestFiles' is missing an input or output annotation.

* Try:
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Exception is:
org.gradle.internal.execution.WorkValidationException: Some problems were found with the configuration of task ':app:ribbonizeDebug' (type 'RibbonizerTask').
  - In plugin 'com.github.gfx.ribbonizer' type 'com.github.gfx.ribbonizer.plugin.RibbonizerTask' property 'androidManifestFiles' is missing an input or output annotation.
    
    Reason: A property without annotation isn't considered during up-to-date checking.
    
    Possible solutions:
      1. Add an input or output annotation.
      2. Mark it as @Internal.
    
    Please refer to https://docs.gradle.org/7.5/userguide/validation_problems.html#missing_annotation for more details about this problem.
  - In plugin 'com.github.gfx.ribbonizer' type 'com.github.gfx.ribbonizer.plugin.RibbonizerTask' property 'filterBuilders' is missing an input or output annotation.
    
    Reason: A property without annotation isn't considered during up-to-date checking.
    
    Possible solutions:
      1. Add an input or output annotation.
      2. Mark it as @Internal.
错误3

debug编译正常,release编译报错。提示lint错误,查询后发现gradle7.0发布了一些对linting的更改

/builds/locuslabs/android-team/locuslabs-android-sdk/app/src/main/AndroidManifest.xml:21: Error: MainActivity must extend android.app.Activity [Instantiatable]
            android:name="com.locuslabs.appsdk.MainActivity"
                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   Explanation for issues of type "Instantiatable":
   Activities, services, broadcast receivers etc. registered in the manifest
   file (or for custom views, in a layout file) must be "instantiatable" by
   the system, which means that the class must be public, it must have an
   empty public constructor, and if it's an inner class, it must be a static
   inner class.
1 errors, 0 warnings
Lint found fatal errors while assembling a release target.
To proceed, either fix the issues identified by lint, or modify your build script as follows:
...
android {
    lintOptions {
        checkReleaseBuilds false
        // Or, if you prefer, you can continue to check for errors in release builds,
        // but continue the build even when errors are found:
        abortOnError false
    }
}

好吧直接添加忽略,问题得到解决:

android {
    lintOptions {
        disable "Instantiatable"
    }
}
最后

我也有点纠结,版本的更新如果不仔细看文档其实我们不知道更新了什么,但如果让我一条一条去看我又嫌弃太多太麻烦,我现在是稍微百度预览下其他人的经验,最后在决定是不是需要更新。你是不是这样操作的呢还是你又更好的方法,请留言互相学习下。

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐