I am currently working on an Android library which is developed with AndroidAnnotations, and uses some Fragments. When it is compiled as an Android application, the code is fine and everything works. When it is compiled as an Android library, it breaks because it can't find any of the AndroidAnnotations generated classes.
I annotated each activity with @EActivity(resName="activity_name")
instead of @EActivity(R.layout.activity_name)
, and this corrects a few errors.
The problem that I encounter is that in some of those activities, I create dynamically some Fragments like this (for example) :
PhotoFragment fragment = PhotoFragment_.builder().someParams("a string param").build();
When I try to compile as an Android library, this call fails because it can't find the dynamically generated PhotoFragment_
class. Is there a solution to make it work? Either by changing the way I create the Fragment, or by configuring AndroidAnnotations?
EDIT 20/04/2016
My build.gradle
(module level) :
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'
}
}
Thanks a lot!
After discussion, it turned out there was a compilation error in the code (not related to the annotation processor). This is the AndroidAnnotations processor was not even called, and the classes were not generated.
The solution is fixing the "normal" compilation error, then annotation processors will run. It is hard, because the error will be buried in lots of generated class not found errors, so a thorough read is needed.