I am trying to merge my free app and paid app. The productFlavors of Android's new build system seem to be a perfect fit for my problem.
I have the freeApp flavor working great, however when I build the paidApp flavor the R file that is being generated is in a package structure that is defined in the freeApp.
Here is a snippet from by gradle.build file:
productFlavors {
freeApp {
versionCode 201308020
versionName "2.0.13_free"
packageName "com.flyingspheres.android"
}
paidApp {
versionCode 201305110
versionName "2.0.10_paid"
packageName "com.flyingspheres.android.inventory"
}
I always believed the R file's location is defined by the package name in the manifest. I verified that the manifest file is generating correctly.
The problem is that the R file for both flavors is located in the same location. Gradle demands that a manifest lives within the main source tree so whatever version of the manifest I put in the main source tree that is where the R.java file will be generated at.
Assuming that I get the R files to generate in the correct location for each flavor; how are the import statements for the R file supposed to be managed so that each flavor references the correct R file?
Here is a screen shot of my project structure:
Each AndroidManifest.xml file is a full and complete manifest - according to the documentation the manifest in the main tree should completely overwrite the product flavor version. Although, that is clearly not happening, because the activity that should be launched and the content providers aren't being overwritten.
Any insights to what I'm doing wrong would be most appreciated. This has to be a very common situation that anyone overriding the packageName would run into. I've been trying to figure it out for about a week now and can't seem to get there on my own.
Thanks,
-Aaron
void missingDimensionStrategy ( String dimension, String requestedValue) Specifies a flavor that the plugin should try to use from a given dimension in a dependency. Android plugin 3.0. 0 and higher try to match each variant of your module with the same one from its dependencies.
Build types define certain properties that Gradle uses when building and packaging your app, and are typically configured for different stages of your development lifecycle.
Flavor Dimensions is a way to group flavors by a name. For now, we're using just a single group. Add the following line in your defaultConfig block: flavorDimensions "default" Now syncing the gradle would give you the following product flavors: Android Build Variants combine build types and product flavors.
Under android's gradle plugin 0.7.3, the generated R.java
file is only made for the src/main
's package name. It contains all the resources for the different flavors, it just puts them into one generated R.java
file. I heard this from an IO talk.
What's your package name in the src/main/AndroidManifest.xml
? My guess is that it's com.flyingspheres.android
Try importing R
in your classes which need to access resources programatically using your src/main
's package name.
E.g.
import com.flyingspheres.android.R;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With