我在使用Gradle构建时遇到问题。在我的项目中,我使用了自己制作的注释处理器。该处理器在最后一轮处理中生成一些源文件。在生成的文件中,特定的一个类(左轮手枪)由项目代码引用。问题是Gradle似乎同时启动了注释处理器和编译。这会产生错误,因为生成的类没有准备就绪,因此找不到。
为了验证这一点,我添加了一些调试日志记录。
Note: Starting Revolver Injector generation
Note: Starting Revolver Component Provider generation
Note: Starting Revolver Injector generation
Note: Starting Revolver Component Provider generation
E:\workspace\Android Studio\fix-in-produzione\branches\videocurriculum-client-android\app\src\main\java\co\aurasphere\videocurriculum\view\activity\NetworkBaseActivity.java:14: error: cannot find symbol
import co.aurasphere.revolver.Revolver;
^
symbol: class Revolver
location: package co.aurasphere.revolver
Note: Starting Revolver Injector generation
warning: File for type 'co.aurasphere.revolver.Revolver' created in the last round will not be subject to annotation processing.
Note: Starting Revolver Component Provider generation
warning: File for type 'co.aurasphere.revolver.RevolverComponentProvider' created in the last round will not be subject to annotation processing.
1 error
2 warnings
正如您所看到的,在错误发生后,注释处理器会有更多输出(标有"注意:")。
这与Maven完美配合,曾经与Gradle 1.5配合使用。现在我使用的是Gradle 2.14。
有人可以向我解释是否有变化和/或我该如何解决这个问题?
这些是我的gradle文件:
main.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
mavenLocal()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
app.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.3"
dataBinding{
enabled true
}
defaultConfig {
applicationId "co.aurasphere.videocurriculum"
minSdkVersion 15
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_6
incremental false
}
}
repositories {
mavenLocal()
}
preBuild.dependsOn clean
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
// Revolver
compile 'co.aurasphere.revolver:revolver:0.0.1'
annotationProcessor 'co.aurasphere.revolver:revolver-compiler:0.0.1-SNAPSHOT'
// Butterknife dependencies
annotationProcessor 'com.jakewharton:butterknife-compiler:8.0.1'
compile 'com.jakewharton:butterknife:8.0.1'
// Retrofit
compile 'com.squareup.retrofit:retrofit:2.0.0-beta2'
compile 'com.squareup.retrofit:converter-gson:2.0.0-beta2'
compile 'com.squareup.okhttp:logging-interceptor:2.7.5'
// Otto
compile 'com.squareup:otto:1.3.8'
// Support libraries
compile 'com.android.support:appcompat-v7:24.0.0'
compile 'com.android.support:design:24.2.1'
compile 'com.android.support:support-v4:24.0.0'
compile 'com.android.support:recyclerview-v7:24.0.0'
}
谢谢。