wurensen / gradle_plugin_android_aspectjx

A Android gradle plugin that effects AspectJ on Android project and can hook methods in Kotlin, aar and jar file.
Apache License 2.0
363 stars 50 forks source link

不兼容Arctic Fox,AGP7.0.4:Failed to apply plugin 'android-aspectjx' #13

Closed KevinLee089 closed 2 years ago

KevinLee089 commented 2 years ago

An exception occurred applying plugin request [id: 'android-aspectjx']

Failed to apply plugin 'android-aspectjx'. Build was configured to prefer settings repositories over project repositories but repository 'MavenLocal' was added by plugin 'android-aspectjx'

wurensen commented 2 years ago

agp还没适配7.x版本,降级到4.x吧

KevinLee089 commented 2 years ago

也不用降级,AGP7.x版本project的build.gradle没有allprojects节点了,迁移到了settings.gradle。把这部分写回allprojects即可。以后或许会移除allprojects节点,望尽早兼容

wurensen commented 2 years ago

@KevinLee089 AGP 7.x开始官方不是要弃用transform了?说是采用AsmClassVisitorFactory替换,还没去研究。

549064368 commented 2 years ago

贴出来看看,怎么搞

okmin3 commented 2 years ago

buildscript { repositories { google() mavenCentral() maven { url "https://jitpack.io" } maven { url 'https://maven.aliyun.com/repository/gradle-plugin' } // noinspection JcenterRepositoryObsolete } dependencies { classpath "com.android.tools.build:gradle:7.0.3" classpath 'io.github.wurensen:gradle-android-plugin-aspectjx:2.0.14' } }

allprojects { repositories { google() jcenter() mavenCentral() maven { url "https://jitpack.io" } maven { url 'https://maven.aliyun.com/repository/gradle-plugin' } } }

task clean(type: Delete) { delete rootProject.buildDir }

使用 allprojects 把settings.gradle 里的进行注释,测试能正常工作 //dependencyResolutionManagement

okmin3 commented 2 years ago

@549064368

wurensen commented 2 years ago

@okmin3 @KevinLee089 @549064368 想用plugins方式引入插件,记得把版本升级到2.0.15,然后通过plugins方式引入可以这样配置:

pluginManagement {
    resolutionStrategy {
        // 定义id和插件库映射关系
        def modules = [
                'org.greenrobot.greendao': 'org.greenrobot:greendao-gradle-plugin:3.3.0',
                'android-aspectjx'       : 'io.github.wurensen:gradle-android-plugin-aspectjx:2.0.15',
        ]
        eachPlugin {
            println "id=" + requested.id.id
            def module = modules.get(requested.id.id)
            if (module != null) {
                useModule(module)
            }
        }
    }
    repositories {
        gradlePluginPortal()
        google()
        mavenCentral()
    }
}

这种配置方式,其它未发布到gradle插件仓库的都支持,原理就是自定义插件id对应的解析策略。 使用的地方:

plugins {
    id 'android-aspectjx'
}