高版本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'
}
相关推荐
明道源码12 小时前
Android Studio 应用运行到真机设备
android·ide·android studio
生莫甲鲁浪戴12 小时前
Android Studio新手开发第二十五天
android·ide·android studio
Varpb12 小时前
android studio-设置android模拟器屏幕自动旋转
android·android studio
Jeled1 天前
「高级 Android 架构师成长路线」的第 1 阶段 —— 强化体系与架构思维(Clean Architecture 实战)
android·kotlin·android studio·1024程序员节
G果1 天前
安卓APP页面之间传参(Android studio 开发)
android·java·android studio
明道源码2 天前
Android Studio 创建 Android 模拟器
android·ide·android studio
明道源码2 天前
Android Studio 使用教程
android·ide·android studio
生莫甲鲁浪戴2 天前
Android Studio新手开发第二十七天
前端·javascript·android studio
消失的旧时光-19432 天前
iFlutter --> Flutter 开发者 的 IntelliJ IDEA / Android Studio 插件
flutter·android studio·intellij-idea
生莫甲鲁浪戴3 天前
Android Studio新手开发第二十六天
android·前端·android studio