我目前正在开发一个使用 AndroidAnnotations 开发的 Android 库,并使用一些 Fragment。当它被编译为 Android 应用程序时,代码很好并且一切正常。当它被编译为 Android 库时,它会崩溃,因为它找不到任何 AndroidAnnotations 生成的类。
我用 @EActivity(resName="activity_name")
而不是 @EActivity(R.layout.activity_name)
注释了每个 Activity ,这纠正了一些错误。
我遇到的问题是,在其中一些 Activity 中,我动态创建了一些像这样的 fragment (例如):
PhotoFragment fragment = PhotoFragment_.builder().someParams("a string param").build();
当我尝试编译为 Android 库时,此调用失败,因为它找不到动态生成的 PhotoFragment_
类。有没有办法让它发挥作用?是通过更改创建 Fragment 的方式,还是通过配置 AndroidAnnotations?
编辑2016年4月20日
我的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 处理器甚至没有被调用,并且类也没有生成。
解决方案是修复“正常”编译错误,然后注释处理器将运行。这很难,因为错误会被埋藏在大量生成的类未找到错误中,因此需要彻底阅读。
关于android - 使用 AndroidAnnotations 和 Fragments 编译库项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36723335/