我已将注释处理器添加到我的 Android 项目中。它运行没有错误并产生预期的结果。但是,我有两个问题阻碍了我的开发。
首先,每次我制作项目时,我都必须先清理,否则我就会得到
error: Bad service configuration file, or exception thrown while constructing Processor object: javax.annotation.processing.Processor: Error reading configuration file
第二个是当我尝试清洁时,我得到
Error:Execution failed for task ':processor:clean'.
Unable to delete file: D:\Users\Tony\AndroidProjects\Minder\processor\build\libs\processor.jar
这似乎是因为运行注释处理器的 JVM 永远不会终止。如果我进入任务管理器(在 Windows 上工作)并关闭“Java Platform SE 二进制”进程,我就可以毫无错误地进行清理。清理后,一切运行正常。
这是我的应用程序模块的 gradle.build:
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "us.bridgeses.minder"
minSdkVersion 16
targetSdkVersion 22
versionCode 22
versionName "2.0-beta"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
applicationIdSuffix '.debug'
versionNameSuffix '-debug'
}
}
packagingOptions {
exclude 'LICENSE.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/services/javax.annotation.processing.Processor'
}
}
dependencies {
compile project(':processor')
compile project(':annotations')
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.android.support:support-v4:22.2.1'
compile 'com.getbase:floatingactionbutton:1.10.0'
compile 'com.google.code.gson:gson:2.3.1'
compile 'org.reflections:reflections:0.9.10'
compile 'com.h6ah4i.android.materialshadowninepatch:materialshadowninepatch:0.6.3'
androidTestCompile 'junit:junit:4.11'
androidTestCompile('com.android.support.test:testing-support-lib:0.1') {
exclude group: 'junit' // junit:junit-dep conflicts with junit:unit
}
testCompile 'org.robolectric:robolectric:3.0'
testCompile 'org.robolectric:shadows-support-v4:3.0'
}
最佳答案
作为完成注释处理器的解决方案,您可以使用编译器
的.jar
文件而不是整个项目。使用 jar 将使您能够毫无问题地清理项目。只需将 compiler.jar
添加到 libs 文件夹,并将 compile project(':processor')
替换为 apt files('libs/compiler.jar')
。
但我找不到修改编译器
项目和测试更改的解决方案,无需clean
并终止“Java Platform SE二进制”进程
关于java - 注解处理后,JVM 永远不会终止;每次构建之前必须清洁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32801640/