Android Studio - nested flavors (Gradle) - android

I am trying to generate different APKs for free and paid version (removed ads in layout files), additionally I want to track with Google Analytics downloads from different stores (Google Play, Amazon, etc.)
In the directory tree it would look like this:
\
\[free]
\[amazon]
\[googleplay]
\common part for free app
\[pro]
\[amazon]
\[googleplay]
\common part for paid app
Is it possible to have such build variants with Gradle build? If not, what would you be your suggested solution. I know I can prepare flavors in flat structure (amazonfree, amazonpro, googleplayfree, googleplaypro), but some of the code would have to be duplicated.

flavorDimensions is what you search for. One dimension would be price for you ( free/paid ) and the other dimension is the store (play/amazon/..)

Related

How to communicate between custom flavour files in android?

I have two custom flavors - free and paid. Free flavour comes with basic features whereas the paid one comes with advanced features.
I invoke paid version files from free. This works fine in paid build variant since this will include both(free and paid) src folders. If I change to the free variant, the call to paid variant files is not recognized. What is the right way to do this?

Multiple Release and Debug Options For Different Clients

I have an android app in use by several clients, when I build the app currently I have 2 options 1. release and 2. debug
Now my problem is some om my clients require certain features others do not, meaning that for the same app some features might be disabled for some clients while other clients would have extra features.
I would like to know how I can have more than one release option when building my app. eg.
ClientARelease
ClientBRelease
ClientCRelease
ClientADebug
ClientBDebug
ClientCDebug
So if Client A wants all features of the app but client B does not when I select ClientBRelease the features not required by ClientB are not bundled with the apk.
How do I achieve this with android?
You should use Android Build Types and Build Flavors. Check out Android Developer Guide
Each build variant represents a different version of your app that you can build. For example, you might want to build one version of your app that's free, with a limited set of content, and another paid version that includes more. You can also build different versions of your app that target different devices, based on API level or other device variations.
Creating product flavors is similar to creating build types: add them
to the productFlavors block in your build configuration and include
the settings you want.
In some cases, you may want to combine configurations from multiple
product flavors. For example, you may want to create different
configurations for the "full" and "demo" product flavors that are
based on API level. To do this, the Android plugin for Gradle allows
you to create multiple groups of product flavors as flavor dimensions.
When building your app, Gradle combines a product flavor configuration
from each flavor dimension you define, along with a build type
configuration, to create the final build variant.
Also for some cases you can use APK splitting/AppBundle.

Firebase analytics for different build types

I want to integrate firebase analytics to both of my android and iOS app.
For android, I have a single flavour with 3 different build types. Dev staging and release. All these build types have the same application ID.
For historical reasons, I cannot change the build type to include a different suffix to differentiate.
On firebase analytics, I would like to have two dashboard! The first to include data from dev and staging. The second to include data from release.
The question is - how should I create the projects and link the google-service.json? Is that possible to do?
Thanks.
Inside src directory create different directories for each build type. Then place google-services.json for specific types inside the respective directories.
For example I have two build types debug and release, so this is how it works
So you will have three directories - dev, staging and release and they will have their own google-services.json file.

Android Studio: debug classes depending on a flavour

I have an application with three different flavours and two build types. The main module defines some common interfaces and each flavour implements them. The flavours correspond to stores : google, amazon and samsung. The app proposes some in-app purchases, which is specific to each flavour.
I implemented a few debug classes to ease the integration tests of the google the flavour. The debug classes implement the IInAppBillingService and an alternative to the purchase dialog. Now the problem is that some debug classes have dependencies on a flavour. I can't switch to another flavour without having compilation errors.
I would like to keep these test classes, as they are used in integration tests. Also, they should be kept away from the release build type, to avoid any debug/testing code appearing in the released version.
My question is : how to define classes with dependencies on a flavour, but that are not used during the building of the release version ?
As you probably know, you can put code and assets specific to a flavor in its own folder under src. For example you can have folders such as google, amazon, and samsung for each flavor. You can also create debug and release folders for classes and assets specific to each build type. This is useful if you have code only used for development but that should not go into the final release version.
You can take this a step further and create folders for any combination of build type and flavor, for example, googleDebug or amazonRelease.
For automated testing, create a test folder for unit tests which run locally on you development machine or an androidTest folder for instrumented tests run on a device or emulator. These can also be combined with build types and flavors, for example androidTestDebug, androidTestSamsung, or androidTestSamsungDebug.
All classes for testing should go under
Instead of having the classes that handles the billing logic in the flavour folder directly, I used another module specific to a flavour.
In the google billing module, I keep all the classes involved in the in-app purchases. Each module specific to a flavour is imported for the corresponding flavour. This way, I avoid mixing code specific to different flavours.
For example, in the build.gradle file I have :
googleCompile project(path: ':inappbilling_google')
In the inappbilling_google module, I have all the classes involved in in-app purchase through Google in-app billing. There is a debug folder to keep all the classes that should not appear during the release build process.
I was quite happy with this solution, as I keep clearly separate the code of the different flavours and build types... until I discovered that Gradle had some limitations. Indeed, the code present in the debug folder of modules is not included during the compilation. This is a known issue (limitation) of Gradle and the Android Gradle plugin.
However, the Google team and Gradle team have worked on this and have announced a solution to this, with the version 2.5 of the Android Gradle plugin.
In a near future, it will be possible to separate our code using the Android Gradle plugin only. Good news !

Build two different apk using one single code in android eclipse

I am still working with Eclipse to develop android applications. Now there is a situation where I am supposed to build 2 different applications (You can consider as free and non-free version apk) using same app-code. I have got thousands of links regarding build.gradle and application package-name and others on google, but I don't how to build/use it in Eclipse.
Another question I have is how to point to 2 different images
based on different application.?
If you want to release two different build (paid and free). You need to change the package name. Just goto the manifest file.
For example: for free version
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.free">
and similarly for paid version
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.paid">
Alternatively, I will recommend you to use In app purchase feature and release only build
Try this.. Is there any way to integrate Eclipse with Gradle in Android project?.. There is no simple answer for this question.. Either you use eclipse with gradle and set two flavours with different in your build.gradle
productFlavors {
free {
applicationId 'your.package.name.free'
}
paid {
applicationId 'your.package.name.paid'
}
}
or else just copy your project twice and change package name. If you want to upload both your apps in play store then you need two different package names.

Categories

Resources