升级AGP 7.x以后,引入带冒号‘:‘的插件规则

升级到AGP7.x后,插件的使用规则有变化,插件id只支持. _ -【点、下划线、中划线】三种特殊字符,对于包含 ':'的插件,比如: com.alibaba:arouter-register:1.0.2,在plugins闭包中使用,编译报错:

plugin id ‘com.alibaba:arouter-register’ is invalid: Plugin id contains invalid char ‘:’ (only ASCII alphanumeric characters, ‘.’, ‘_’ and ‘-’ characters are valid)

正确的使用姿势需要以下两步:

1. 将’:‘换成 ‘.’,当然,换成’_‘和’-'也行

//rootProject :build.gradle
plugins{
    ...
    id 'com.alibaba.arouter-register'  version "1.0.2"
}

2.在settings.gradle中动态将 com.alibaba.arouter-register替换成原始的插件形式进行依赖.

settings.gradle
pluginManagement {
    repositories {
        gradlePluginPortal()
        ...
    }
    resolutionStrategy {
        eachPlugin {
            if (requested.id.id == 'com.alibaba.arouter.register') {
                useModule('com.alibaba:arouter-register:1.0.2')
            }
        }
    }
}

重新sync以下就ok了。

arouter-register是alibaba提供的一个gradle插件,实现了AutoRegister框架【字节码插桩ASM】,在编译阶段就能完成路由表的初始化操作,减少初始化耗时

你可能感兴趣的:(android,android,studio,groovy,gradle,agp7.x)