我目前正在开发一个android库,这个库是用androidnotations开发的,并且使用了一些片段。当它被编译为android应用程序时,代码很好,一切正常。当它被编译为android库时,它会崩溃,因为它找不到任何androidnotations生成的类。
我用@EActivity(resName="activity_name")
而不是@EActivity(R.layout.activity_name)
注释了每个活动,这纠正了一些错误。
我遇到的问题是,在其中一些活动中,我会动态地创建一些这样的片段(例如):
PhotoFragment fragment = PhotoFragment_.builder().someParams("a string param").build();
当我尝试编译为android库时,这个调用失败,因为它找不到动态生成的
PhotoFragment_
类。有没有办法让它起作用?或者通过改变我创建片段的方式,或者通过配置AndroidAnnotations?2016年4月20日编辑
my
build.gradle
(模块级):apply plugin: 'com.android.library'
apply plugin: 'android-apt'
def AAVersion = '4.0.0'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
// Barcode library (ZXing)
compile 'com.journeyapps:zxing-android-embedded:3.0.2'
compile 'com.google.zxing:core:3.2.0'
// Android Annotations
apt "org.androidannotations:androidannotations:$AAVersion"
compile "org.androidannotations:androidannotations-api:$AAVersion"
// Android Bootstrap
compile 'com.beardedhen:androidbootstrap:2.1.0'
// Gson
compile 'com.google.code.gson:gson:2.4'
// Some auto-generated BS
compile 'com.android.support:design:23.2.1'
compile 'com.android.support:support-v4:23.2.1'
// Robotium --> Emulate User Interaction on tests
compile 'com.jayway.android.robotium:robotium-solo:5.5.4'
// Android Testing
androidTestCompile 'com.android.support:support-annotations:23.2.1'
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support.test:rules:0.5'
// OkHTTP (HTTP Client Library)
compile 'com.squareup.okhttp3:okhttp:3.2.0'
}
apt {
arguments {
library 'true'
}
}
谢谢!
最佳答案
经过讨论,发现代码中存在编译错误(与注释处理器无关)。这是AndroidAnnotations处理器甚至没有被调用,类也没有生成。
解决方案是修复“正常”编译错误,然后运行注释处理器。这很难,因为错误会隐藏在大量生成的类未找到的错误中,所以需要进行彻底的读取。