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窗口打印。