前言:本文章就不详细说明AspectJ是什么玩意了,查到这篇文章的都极有可能是在Android Studio中配置AspectJ出现问题,本文就是解决问题的详细方案,目标Gradle版本7.3.3, 不过本文应该适用于7.x.x的版本 !!
前言:本文章就不详细说明AspectJ是什么玩意了,查到这篇文章的都极有可能是在Android Studio中配置AspectJ出现问题,本文就是解决问题的详细方案,目标Gradle版本7.3.3, 不过本文应该适用于7.x.x的版本
buildscript { repositories { Google() jcenter() } dependencies { classpath "com.android.tools.build:gradle:4.1.3" classpath 'com.hujiang.aspectjx:gradle-android-plugin-aspectjx:2.0.10' }}allprojects { repositories { google() jcenter() Maven { url "https://jitpack.io" } }}
以上代码变成了项目setting.gradle里面的:
pluginManagement { repositories { gradlePluginPortal() google() mavenCentral() }}dependencyResolutionManagement {// repositoriesMode.set(RepositoriesMode.FaiL_ON_PROJECT_REPOS) repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS) repositories { google() mavenCentral() }}
导致大家不知道classpath如何引入,其实只需要在项目级build.gradle里面添加:
buildscript { dependencies { classpath 'com.hujiang.aspectjx:gradle-android-plugin-aspectjx:2.0.10' }}
注意:一定要在plugins{}模块上面写,这是gradle配置的基本格式
plugins { id 'com.android.application' version '7.1.3' apply false id 'com.android.library' version '7.1.3' apply false}
apply plugin: 'android-aspectjx'
注意:一定要是application加才有效,library加了插件引用是无效的。 在组件化中,哪个组件需要用到AspectJx就加这个插件引用。
aspectjx { exclude 'androidx', 'com.google', 'com.squareup', 'com.alipay', 'com.taobao', 'org.apache', 'org.jetbrains.Kotlin', "module-info", 'versions.9'}
注意:aspectjx{}块与android{}同级
dependencies { api "org.aspectj:aspectjrt:1.9.5"}
api或者implementation看自己需求就行了,都可以的
buildscript { dependencies { classpath 'com.hujiang.aspectjx:gradle-android-plugin-aspectjx:2.0.10' }}plugins { id 'com.android.application' version '7.1.3' apply false id 'com.android.library' version '7.1.3' apply false}
pluginManagement { repositories {// maven {// url 'Https://maven.aliyun.com/repository/jcenter' //阿里云的jcenter仓库废弃了// } maven { url 'https://maven.aliyun.com/repository/google' } maven { url 'https://maven.aliyun.com/repository/public' } maven { url 'https://maven.aliyun.com/repository/mapr-public' } maven { url 'https://jitpack.io' } gradlePluginPortal() google() mavenCentral() }}dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS) repositories {// maven {// url 'https://maven.aliyun.com/repository/jcenter' //阿里云的jcenter仓库废弃了// } maven { url 'https://maven.aliyun.com/repository/google' } maven { url 'https://maven.aliyun.com/repository/public' } maven { url 'https://maven.aliyun.com/repository/mapr-public' } maven { url 'https://jitpack.io' } google() mavenCentral() }}
plugins { id 'com.android.application'}apply plugin: 'android-aspectjx'android { defaultConfig { }}aspectjx { exclude 'androidx', 'com.google', 'com.squareup', 'com.alipay', 'com.taobao', 'org.apache', 'org.jetbrains.kotlin', "module-info", 'versions.9'}
plugins { id 'com.android.library'}android {}dependencies { api "org.aspectj:aspectjrt:1.9.5"}
aspectjx { // 排除一些第三方库的包名(Gson、 LeakCanary 和 AOP 有冲突) // 否则就会起冲突:ClassNotFoundException: Didn't find class on path: DexPathList //我遇到的 Execution failed for task ':app:dexBuilderDebug'. //> java.util.zip.ZipException: zip file is empty exclude 'androidx', 'com.google', 'com.squareup', 'com.alipay', 'com.taobao', 'org.apache', 'org.jetbrains.kotlin', "module-info", 'versions.9'}
plugins { //下面俩个插件要是为7.2.1会导致在引入 apply plugin 'android-aspectjx' 不兼容,报错 //> Failed to apply plugin 'android-aspectjx'. // > No such property: FD_INTERMEDIATES for class: com.android.builder.model.AndroidProject //亲测改成7.1.3就没问题 id 'com.android.application' version '7.1.3' apply false id 'com.android.library' version '7.1.3' apply false}
//> 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'// repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) 必须换成这个,否则会报上面这个错 repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)
buildscript { dependencies { classpath 'com.hujiang.aspectjx:gradle-android-plugin-aspectjx:2.0.10' }}
来源地址:https://blog.csdn.net/XJ200012/article/details/129152157
--结束END--
本文标题: Android gradle7.3.3配置AspectJX(AspectJ),一步一个坑,成功开启AOP编程之路
本文链接: https://lsjlt.com/news/372139.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0