Android Studio Processor 自定义注解器不执行以及 Messager 日志看不到的问题

AndroidStudio版本:3.5.2

gradle版本:5.4.1

tools:com.android.tools.build:gradle:3.5.3

 

网上搜了下,都说是需要将要编译注解的library添加

annotationProcessor即可。

可是我看了我的项目结构,已经添加了这些依赖:

app.build

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"
    defaultConfig {
        applicationId "com.magic.ppjoke"
        minSdkVersion 22
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility "1.8"
        targetCompatibility "1.8"
    }

}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.navigation:navigation-fragment:2.0.0'
    implementation 'androidx.navigation:navigation-ui:2.0.0'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

    implementation project(':libnavannotation')
    annotationProcessor project(":libnavcompiler")
}
 

libnavcompiler.build

apply plugin: 'java-library'

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation project(':libnavannotation')
    implementation 'com.alibaba:fastjson:1.2.59'
    api 'com.google.auto.service:auto-service:1.0-rc6'
    annotationProcessor 'com.google.auto.service:auto-service:1.0-rc6'
}

sourceCompatibility = "8"
targetCompatibility = "8"

然而....依然没有打印我使用Messger打印的日志

messager = processingEnvironment.getMessager();
                messager.printMessage(Diagnostic.Kind.NOTE, "[resourcePath]" + resourcePath);

最后发现是因为我的jdk版本使用的是AndroidStudio默认的,所以才没有执行。

打开ProjectStructure后,设置为JDK1.8即可。

 

设置完后,文件成功生成,日志也在Build窗口打印。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章