高版本gradle集成aspectj

之前低版本gradle集成aspectj可以成功,但是最近用gradle7.3以上去集成时一直报错,提示找不到插件。尝试了很久,最终找到了解决方案,这里记录下。

由于android-aspectj 原作者不维护了,现在高版本的支持插件是

arduino 复制代码
'io.github.wurensen.android-aspectjx'

下面是新插件具体的集成步骤:

  • 在project 工程目录下的build.gradle中添加
arduino 复制代码
classpath 'io.github.wurensen:gradle-android-plugin-aspectjx:3.3.2'
  • 在app的build.gradle中添加,注意一定要放在application插件的下方,否则会报错
arduino 复制代码
apply plugin: 'io.github.wurensen.android-aspectjx'
  • 在library的build.gradle中添加(组件开发模式中,需要放在需要开启aop的模块中)
arduino 复制代码
implementation 'org.aspectj:aspectjrt:1.9.7'

下面是全部代码:

project build.gradle

arduino 复制代码
buildscript {
    ext.kotlin_version = '1.7.10'
    repositories {
        mavenCentral()

        //jcenter()
    }
    dependencies {
        
        classpath 'com.android.tools.build:gradle:7.3.1'
       
        classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.10'
       
        classpath 'io.github.wurensen:gradle-android-plugin-aspectjx:3.3.2'
    }
}

app build.gradle

arduino 复制代码
apply plugin: 'com.android.application'
apply plugin: 'io.github.wurensen.android-aspectjx'
apply plugin: 'kotlin-android'

android {
    
    compileSdkVersion 34
    buildToolsVersion "34.0.0"
    defaultConfig {
        targetSdkVersion 34
        minSdkVersion 31
       
    }
 
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    **** 
   
}
 dependencies {
     **** 
 }

library build.gradle

bash 复制代码
plugins {
    id 'com.android.library'
    id 'org.jetbrains.kotlin.android'
}

android {
    namespace 'com.xiaomi.xms.ai.recorder'
    compileSdk 34

    defaultConfig {
        minSdk 31

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        consumerProguardFiles "consumer-rules.pro"
    }

   *****
}

dependencies {
    implementation 'androidx.core:core-ktx:1.13.1'
    implementation 'org.aspectj:aspectjrt:1.9.7'
}
相关推荐
我命由我123455 天前
Android 开发问题:EditText 控件的 android:imeOptions=“actionDone“ 属性不生效
android·java·java-ee·android studio·android jetpack·android-studio·android runtime
我命由我123455 天前
Android 开发问题:获取到的 Android ID 发生了变化
android·java·开发语言·java-ee·android studio·android jetpack·android runtime
我命由我123455 天前
Android 开发问题:Unable to find explicit activity class
android·java·java-ee·android studio·android jetpack·android-studio·android runtime
终将老去的穷苦程序员8 天前
基于Android Studio开发的安卓图书借阅管理系统
java·sqlite·android studio·android-studio
问心无愧05139 天前
ctf show web入门107
android·前端·笔记·android studio
我命由我123459 天前
Android 开发问题:View 的 getWidth、getHeight 方法返回的值都为 0
android·java·java-ee·android studio·android jetpack·android-studio·android runtime
星间都市山脉9 天前
Android STS(Security Test Suite)完整介绍与测试流程
android·java·linux·windows·ubuntu·android studio·androidx
Ycocol9 天前
AS同一个目录下的类导入导入其他类爆红无法跳转但是可以编译
android·ide·android studio
我命由我123459 天前
由 ImageView 获取到的 Drawable 对象,它的 intrinsicWidth、intrinsicWidth 与实际图片的尺寸
java·开发语言·java-ee·android studio·android jetpack·android-studio·android runtime
测试开发-学习笔记11 天前
Android studio安装
android·ide·android studio