当前位置: 首页 > 工具软件 > AndResGuard > 使用案例 >

解决AndResGuard在gradle 7.0上报错的问题

督宏旷
2023-12-01

当Android Studio升级到Aretic Fox版本后,APG的版本也升级到了7.0,而gradle的版本也要随之升级到7.0了(参考官方文档

AndResGuard在gradle升级到7.0后会出现错误,如下

Some problems were found with the configuration of task ':app:resguardProdRelease' (type 'AndResGuardTask').
  - In plugin 'AndResGuard' type 'com.tencent.gradle.AndResGuardTask' property 'android' is missing an input or output annotation.

看错误是没有适配gradle 7.0的,我们着手修改这个问题。
下载源码,按以下步骤修改
1、升级gradle版本到7.0
2、compile改为implementation
3、修改AndResGuardTask,有四处代码需要添加Internal注解

……
  @Internal
  AndResGuardExtension configuration
  @Internal
  def android
  @Internal
  def buildConfigs = []
  ……
  @Internal
  def getZipAlignPath() {
    ……
  }
……

4、修改版本号

ANDRESGUARD_VESSION=1.2.22

5、运行以下两个命令发布版本到本地maven

gradlew task ":AndResGuard-gradle-plugin:buildAndPublishLocalMaven"

gradlew task ":AndResGuard-core:buildAndPublishLocalMaven"

6、在自己项目中引入发布的版本

buildscript {
    apply from: 'config.gradle'
    repositories {
        ……
        // 本地maven
        mavenLocal()
    }
    dependencies {
   		……
        classpath 'com.tencent.mm:AndResGuard-gradle-plugin:1.2.22'
    }
}

源码已放到github,地址https://github.com/jklwan/AndResGuardCompat

PS:其实gradle不升级到7.0也可以,因为Internal在3.0就可以使用了https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/Internal.html

 类似资料: