Android uses aspectjx to step on the pit

1. Add to build.gradle in the root directory:

classpath 'com.hujiang.aspectjx:gradle-android-plugin-aspectjx:2.0.10'

 2. If you use kotlin code, you need to add it to the head of the project's app's build.gradle:

apply plugin: 'com.hujiang.android-aspectjx'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'

 3. Add the following dependencies to the project:

implementation "org.aspectj:aspectjrt:1.9.5"

4. If the project depends on many libraries and conflicts are caused, it is necessary to eliminate conflicts with which libraries and filter out duplicate packages. aspectj provides aspectjx{} to filter conflicting packages, as follows:

aspectjx {
    exclude "**/module-info.class"
    exclude "META-INF.versions.9.module-info"
    exclude "META-INF/versions/9/*.class"
    exclude 'com.google', 'com.squareup', 'org.apache'
}

 5. If the aspectjx library has been introduced into the project, the code of the library must be used in the project, otherwise an error will be reported and the application will crash, and the system will throw an exception that the specified class cannot be found.

Guess you like

Origin blog.csdn.net/weixin_44715716/article/details/121923544