Reputation: 5261
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?
Upvotes: 49
Views: 25826
Reputation: 393
SOLUTION
so you want to follow this code is working properly.
android {
compileSdkVersion 30
buildToolsVersion "30.0.2"
defaultConfig {
applicationId "com.premsinghdaksha"
minSdkVersion 17
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
flavorDimensions "client"
productFlavors {
// use for production debug and release build
production {
dimension "client"
buildConfigField("String", "BASE_URL", "YourURL")
//if you want to use string anywhere of app show you define
// buildConfigField and get value where you want to use.
buildConfigField("String", "Shop_", "\"Shop1\"")
// production app name
//if you want change application name and app icon so you define
// resValue, manifestPlaceholders and get these value in Manifests file.
resValue "string", "app_name", "Your production name"
//production app icon
manifestPlaceholders = [
appIcon : "@mipmap/app_icon",
appIconRound: "@mipmap/app_icon_round"
]
signingConfig signingConfigs.release
}
// use for quality debug and release build
quality {
dimension "client"
buildConfigField("String", "BASE_URL", "YourQualityurl")
buildConfigField("String", "Shop_", "\"Shop2\"")
//use for quality app name
resValue "string", "app_name", "quality App name"
// use for quality app icon
manifestPlaceholders = [
appIcon : "@mipmap/quality_app_icon",
appIconRound: "@mipmap/quality_app_icon_round",
]
}
// use for development debug and release build
development {
dimension "client"
buildConfigField("String", "BASE_URL", "development url")
buildConfigField("String", "Shop_", "\"Shop3\"")
//use for dev app name
resValue "string", "app_name", "developer app name"
//use for dev app icon
manifestPlaceholders = [
appIcon : "@mipmap/developer_icon",
appIconRound: "@mipmap/developer_icon_round"
]
}
}
}
signingConfigs {
// use for signed apk
release {
storeFile file("../premsingh.jks")
storePassword "app@app"
keyAlias "key0"
keyPassword "app@app"
v1SigningEnabled true
v2SigningEnabled true
}
}
Upvotes: 4
Reputation: 1006554
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.
Upvotes: 99