I'm writing my first android app, and I'm just getting started with product flavors. I have an ad-supported app in beta, and I'm writing a paid version with no ads. I can compile both flavors, I think. When I open the gradle window, I see targets like "compile AdsDebugSources" and "compile PremiumDebugSources."
Now, if I double-click on either of those, the build runs to completion without error, but I can't figure out how to run the results. If I click on the green "Run" arrow at the top of the screen, I can never run the premium app.
There's only one entry, "app" that results in a an apk being installed and run on the attached device, and it's the AdsDebug version. I guess I need to add a new configuration, but I can't find any documentation that even mentions the word "flavor."
I've tried adding a configuration, but I don't understand what the questions mean. I looked at the settings for the default app, but they don't seem to mean much. How do I tell it that I want the premium version of my app?
Or does my problem have nothing to do with configurations? I've noticed that when I look at the Build/Edit Flavors
the two flavors are listed, but none of the data fields are filled in. I would have thought that these would be copied from the manifest. Have I neglected something?
All I did to set up the flavors was to add this code to the app level build.gradle file:
flavorDimensions "dummy" productFlavors { ads { dimension "dummy" applicationId 'com.example.myApp.ads' } premium { dimension "dummy" applicationId 'com.example.myApp.premium' }
}
What else do I need to do?
Setting Up Product Flavors Open up your build. gradle file in the app module and add your flavors inside the android section. The below example has 3 product flavors added with each having its own applicationIdSuffix .
Product flavours lets you create multiple variants of an android app while using a single codebase. To create product flavours you need to define rules in the build.
The flavor dimensions define the cartesian product that will be used to produce variants. Example: flavorDimensions("dimA", "dimB") productFlavors { row1 { ... dimension = "dimA" } row2 { ... dimension = "dimA" } row3 { ... dimension = "dimA" } col1 { ...
BuildConfig.FLAVOR gives you combined product flavor. So if you have only one flavor dimension: productFlavors { normal { } admin { } } Then you can just check it: if (BuildConfig. FLAVOR.
Open the Build Variants tool in Android Studio. By default, this is docked on the left.
It will show a list of modules in your project, with a drop-down for each indicating the build variant that will be used by the Run button.
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