Reputation: 58934
I want to get all app flavor list in activity, how can i get this? This is how i implemented flavor in my app via Gradle.
I can get only current flavor by BuildConfig.java
class.
public static final String FLAVOR = "myExamIdea";
But i want to get all flavor list. Below is my gradle file snippet.
flavorDimensions "igen"
productFlavors {
myExamIdea {}
examLeaders{}
}
This is my BuildConfig.java
class
public final class BuildConfig {
public static final boolean DEBUG = Boolean.parseBoolean("true");
public static final String APPLICATION_ID = "in.kpis.igen.myExamIdeaStaging";
public static final String BUILD_TYPE = "debug";
public static final String FLAVOR = "myExamIdeaStaging";
public static final int VERSION_CODE = 1;
public static final String VERSION_NAME = "1.0";
}
Upvotes: 4
Views: 5173
Reputation: 76669
Obviously, every package will come in a different product flavor
...but one can obtain them in Gradle plugin code, while building:
String[] getProductFlavors(@NotNull Project project) {
ArrayList<String> items = new ArrayList<>();
ApplicationExtension android = (ApplicationExtension) project.getExtensions().getByName("android");
Iterator<? extends ProductFlavor> it = android.getProductFlavors().iterator();
return items.toArray(new String[0]);
}
It is possible to add whatever you like into class BuildConfig
and then retrieve it from there again.
Upvotes: 0
Reputation: 8841
BuildConfig.FLAVOR
gives you combined product flavor. If you have only one dimension then you will get the current flavour. If you have multiple dimensions , then you will have multiple fields , for example
BuildConfig.FLAVOUR_[dimensionname]
You can get the list of product flavours however.
Edit :
myExamIdea { flavorDimension "[dimension_name]"}
examLeaders{ flavorDimension "[dimension_name]"}
Upvotes: 1
Reputation: 235
Unfortunately, it is impossible. List of flavors just not storing in apk.
You can fully disassembly your APK with apktool
and search flavors in its unpacked/decoded output; you even can analyse raw output in HEX-editor if believe the smali disassembler (or Manifest decoder, or some another) is omitting some info.
You will not find it.
Upvotes: 0