问题
i'm trying to add two flavors in my project, I already have android annotations and it's working fine without the favors, but when I'm adding the two favors the MainActivity_ class is generated only for one of the flavors when changeing the build variant. Any ideas on how could you add flavors and still use the annotations?
Android annotations version is '3.2'
My android section in gradle looks like this
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
packagingOptions {
exclude 'META-INF/license.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
exclude 'META-INF/notice.txt'
}
defaultConfig {
applicationId "$PackageName"
minSdkVersion 14
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
flavor1 {
}
flavor2 {
}
}
}
apt {
arguments {
androidManifestFile variant.outputs[0].processResources.manifestFile
resourcePackageName "$PackageName"
}
}
回答1:
I'm myself using AndroidAnnotations for a while now and I have a few projects that require product flavors as well. So far I managed to make it work.
My guess would be that you misconfigured your resourcePackageName in your apt.
Here is what I do in my (truncated) build.gradle file:
ext {
APP_NAME = "your app name here"
}
defaultConfig {
applicationId APP_GROUP
versionName APP_VERSION
versionCode 1
minSdkVersion 12
targetSdkVersion 21
}
apt {
arguments {
androidManifestFile variant.outputs[0].processResources.manifestFile
resourcePackageName android.defaultConfig.applicationId
}
}
You might also want to have a custom applicationId for each flavor your using. You can do it that way:
productFlavors {
flavor1 {
applicationId android.defaultConfig.applicationId + ".flavor1"
}
flavor2 {
applicationId android.defaultConfig.applicationId + ".flavor2"
}
}
Hope this solves your issue ;)
来源:https://stackoverflow.com/questions/28362494/android-annotations-and-flavors-in-android-studio-1-0-1