Android gradle product flavors with wearable apps - android

I'm adding a wearable component to an existing app which uses product flavors in the gradle build to build multiple versions of the app.
I know the package names / application Id's need to match between the mobile and wearable builds, but do I just need to copy the
productFlavors
signingConfigs
buildTypes
from my main mobile app. I'm not quite sure if all of this is needed to get things working or not.

The productFlavors no, unless you are going to do something specific for the wear app with a particular flavor.
The signingConfigs and buildTypes you should copy, the wear app definitely needs to be signed as well. You may adapt the buildType for wear such is enable/disable minify it you want from the main app.
Here's a portion of my own mobile and wear build configs
Mobile
android {
compileSdkVersion 20
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "org.codechimp.qrwear"
minSdkVersion 18
targetSdkVersion 20
versionCode 26
versionName "1.20"
}
productFlavors {
prod {
}
dev {
versionName = android.defaultConfig.versionName + " dev"
}
}
signingConfigs { release }
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
}
}
Wear
android {
compileSdkVersion 20
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "org.codechimp.qrwear"
minSdkVersion 20
targetSdkVersion 20
versionCode 26
versionName "1.20"
}
signingConfigs { release }
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
}
}

Related

Flavors error - No matching client found for package name

i try to implement flavors by this guide:
https://proandroiddev.com/advanced-android-flavors-part-1-building-white-label-apps-on-android-ade16af23bcf
but i get this error:
No matching client found for package name 'com.example.client1'
this is my gradle:
android {
compileSdkVersion 28
defaultConfig {
applicationId 'com.example'
minSdkVersion 23
targetSdkVersion 28
versionCode 19
versionName '9.7'
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
flavorDimensions "default"
productFlavors {
ashkelon {
applicationIdSuffix ".client1"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
and this is the source tree:
src/
main/
client1/
any help will be very appreciated!
It means you have only one google-services.json
you need to add one more google-services.json file for client1

How to configure product flavor in new gradle

I am configuring paid and free version of my app and I got below error. I already configure same before android 3 without problem.
How to fixe it please ?
Gradle script
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "capstone.nanodegree.udacity.com.mypodcast"
minSdkVersion 16
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
targetCompatibility 1.8
sourceCompatibility 1.8
}
//flavorDimensions "default"
flavorDimensions "free", "paid"
productFlavors {
free {
applicationId "capstone.nanodegree.udacity.com.mypodcast.free"
dimension "free"
}
paid {
applicationId "capstone.nanodegree.udacity.com.mypodcast.paid"
dimension "paid"
}
}
}
def AAVersion = '4.4.0'
def GLIDEVersion = '4.3.1'
def supportVersion = '26.1.0'
Check that there's entries for both packages in your google-services.json .....also, and this might be separate issue, I believe you should only have to define one dimension (both your flavors would have same dimension value)
I am using Flavors same as you, I'll remove 2 of my flavors and rename for simplicity comparisons:
compileSdkVersion 26
buildToolsVersion googleBuildTools
dataBinding {
enabled = true
}
defaultConfig {
applicationId "com.myapp"
minSdkVersion 21
targetSdkVersion 26
multiDexEnabled true
vectorDrawables.useSupportLibrary = true
}
signingConfigs {
releaseMyApp {
storeFile file("$projectDir/../myappkeystore.jks")
storePassword System.getenv('MYAPP_STORE_PASSWORD')
keyAlias System.getenv('MYAPP_KEY_ALIAS')
keyPassword System.getenv('MYAPP_KEY_PASSWORD')
}
}
productFlavors {
myapp {
applicationId "com.myApp.one"
buildConfigField "String", "SERVER_URL", '"https://api.myappone.com"'
versionCode 24
versionName "1.18"
minSdkVersion 21
}
myappStaging {
applicationId "com.myapp.one.staging"
buildConfigField "String", "SERVER_URL", '"https://stg.api.myappone.com"'
versionCode 24
versionName "1.18"
minSdkVersion 21
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
productFlavors.myapp.signingConfig signingConfigs.releaseMyapp
productFlavors.myappStaging.signingConfig signingConfigs.releaseMyapp
}
}
without issues, but i'll post in case there is something different that you notice that I didn't, but your error is probably related to your firebase json. You can use the same json file for all your flavors, you just need a client section for each application identifier. which you can create online through firebase portal.
I made the mistake of making individual firebase json files for each flavor and later figured out I didn't need to do that as they were all identical with all clients in them.
Originally I only used flavors for two different application types, but later had to make flavors for staging as well to support PUSH in multiple environments. Goodluck. Hopefully that helps, but I'm guessing you need to fix your firebase json file.

Changing only Application ID, not package name

I only want to change application id in gradle file, but dont want to change package name.
Is it possible?
It is not recommended to change your application id. What you can do is change your application suffix.
As an example, if your application id is com.example.my_app then add different suffixes for different build types, such as com.example.myapp.dev for debug.
Go to app/build.gradle file and on android block add the suffix you want:
buildTypes {
release {
applicationIdSuffix ".production"
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
applicationIdSuffix ".dev"
versionNameSuffix '-DEBUG'
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
Read more about it here
No problem. You can change your application Id as long as your app is not on store. If you change your application id, It would immediately become a different app for google play.
I have many apps with different package name and application ids.
Yes you can change androidId in defaultConfig.
android {
compileSdkVersion 27
buildToolsVersion '27.0.3'
defaultConfig {
applicationId "com.somepkg" // <- we can change applicationId in defaultConfig
minSdkVersion 21
targetSdkVersion 26
vectorDrawables.useSupportLibrary = true
....
}
}
Also we can change applicationId in flavors use suffix or override it:
flavorDimensions "app"
productFlavors {
qa {
dimension "app"
applicationIdSuffix = ".qa" // <- add suffix (it will be )
}
production {
applicationId = "com.someotherpkg" // <- we can change applicationId in flavors
dimension "app"
}
}
However your src files will be still in the same folders.

What about BuildType_Decorated info in Gradle log?

When I start Gradle to build a test or debug application, It logs this at the very beginning.
BuildType_Decorated{name=release, ...
with attributs from the release builtType, While I ran the Debug buildType !
Any idea what this issue could be ?
compileSdkVersion ANDROID_BUILD_SDK_VERSION
buildToolsVersion ANDROID_BUILD_TOOLS_VERSION
productFlavors {
// Define separate dev and prod product flavors.
dev {
// dev utilizes minSDKVersion = 21 to allow the Android gradle plugin
// to pre-dex each module and produce an APK that can be tested on
// Android Lollipop without time consuming dex merging processes.
minSdkVersion 21
multiDexEnabled false
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
prod {
// The actual minSdkVersion for the application.
minSdkVersion ANDROID_BUILD_MIN_SDK_VERSION
multiDexEnabled false
}
}
defaultConfig {
applicationId "fr.millezimsolutions.app.millezimu"
targetSdkVersion ANDROID_BUILD_TARGET_SDK_VERSION
minSdkVersion ANDROID_BUILD_MIN_SDK_VERSION
versionCode ANDROID_BUILD_VERSION_CODE
versionName ANDROID_BUILD_APP_VERSION_NAME
}
buildTypes {
release {
debuggable false
ext.enableCrashlytics = true
renderscriptOptimLevel 3
signingConfig android.signingConfigs.release
zipAlignEnabled true
minifyEnabled true
// shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules-release.pro'
}
debug {
debuggable true
renderscriptOptimLevel 3
applicationIdSuffix ".debug"
versionNameSuffix "debug"
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules-debug.pro'
testProguardFile('proguard-rules-test.pro')
}
}

buildTypes not working build.gradle Android Studio

I am new to Android studio and I need to add:
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
debuggable true
}
}
in my build.gradle Android Studio, but getting error:
Gradle DSL method not found:'buildTypes()'
Try to configure buildTypes from "File-> Project Structure" and select your module, you can easily configure everything on the right side panel.
are you sure that your build file is set up correctly?
The buildTypes have to be in the android closure. It should look something like this
note: this is just a example you can't just copy and paste this
android {
compileSdkVersion "Google Inc.:Glass Development Kit Preview:19"
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.your.package"
minSdkVersion 19
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
Hope this is of use for you

Categories

Resources