flavour : override package name - android

I had a project with this package name : applicationId 'com.safa.auditzanjan'
Now I have created a flavour into other same project and I have added those project into this project. this new package name's project is:applicationId "com.safa.auditkhoramabad".
how could I set older package Name to this flavour?Thats mean I want to do override com.safa.auditkhoramabad for my new flavour to com.safa.auditzanjan?
***EDIT***********
this is my Independent gradle config project:
defaultConfig {
applicationId 'com.safa.auditzanjan'
minSdkVersion 15
targetSdkVersion 25
multiDexEnabled true
versionCode 56
versionName '1.8.56'
}
dexOptions {
jumboMode = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
applicationIdSuffix '.debug'
versionNameSuffix '-debug'
}
}
productFlavors {
main {
signingConfig signingConfigs.SigningConfig1
}
ts {
signingConfig signingConfigs.SigningConfig1
applicationIdSuffix ".ts"
versionNameSuffix "-ts"
}
}
this is flavour gradle config:
zanjan {
applicationId 'com.safa.auditzanjan'
signingConfig signingConfigs.SigningConfig1
applicationIdSuffix ".zanjan"
versionNameSuffix "-zanjan"
versionCode 56
versionName '1.8.56'
resValue( "string", "app_name", "ممیزی زنجان")
}

You should be able to do something like following
productFlavors {
flavor1 {
applicationId "com.safa.auditzanjan"
}
flavor2 {
applicationId "com.safa.auditkhoramabad"
}

Related

Cannot get property '?' on null object error when flutter build apk

In my case I run flutter build apk -t lib/main_dev.dart --release --flavor=dev command to build a release APK, I have setup build flavors in my project. But after I run that command it gives "A problem occurred evaluating project ':app'.> Cannot get property '?' on null object" error. Here is my app level build.gradle file,
android {
compileSdkVersion 31
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
lintOptions {
checkReleaseBuilds false │
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.getin.app***"
minSdkVersion 21
targetSdkVersion 31
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
multiDexEnabled true
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
flavorDimensions "app"
productFlavors {
dev {
dimension "app"
versionNameSuffix "-dev"
resValue "string", "app_name", "GetIn Dev"
resValue "string", "facebook_app_id", "5982**********"
resValue "string", "facebook_client_token", "d8f78c******************"
resValue "string", "fb_login_protocol_scheme", "fb*****************"
}
prod {
dimension "app"
applicationId "com.getin.app"
resValue "string", "app_name", "GetIn"
resValue "string", "facebook_app_id", "5982**********"
resValue "string", "facebook_client_token", "d8f78c******************"
resValue "string", "fb_login_protocol_scheme", "fb*****************"
}
}
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.google.firebase:firebase-crashlytics'
}
Here is the given error,
As the image, it shows error is on line number 42, in line number 42 it has this,

What's the right way to add product flavors in react native?

After i added product flavors in my react native project, the app always crashes when i made a release, right after i started it.
I tried to open android studio to see Logcat, but since the app crashes in the moment it's started i couldn't see anything.
Here is part of my app/build.gladle:
project.ext.envConfigFiles = [
dev: ".env.local",
production: ".env.production",
staging: ".env.staging"
]
apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle"
android {
flavorDimensions "default"
defaultConfig {
applicationId "com.company"
applicationIdSuffix ""
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
ndk {
abiFilters "armeabi-v7a", "x86"
}
resValue "string", "build_config_package", "com.company"
}
buildTypes {
release {
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"),
"proguard-rules.pro"
}
}
productFlavors {
dev {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
applicationIdSuffix ".dev"
versionNameSuffix "-dev"
}
staging {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
applicationIdSuffix ".staging"
versionNameSuffix "-staging"
}
production {
}
}
}
I'm also using fastLane for deploy my app, like this:
lane :staging do |options|
gradle(task: 'clean')
gradle(
task: "assemble",
flavor: "Staging",
build_type: "Release",
print_command: false,
properties: {
"android.injected.signing.store.file" => "file.keystore",
"android.injected.signing.store.password" => options[:storepass],
"android.injected.signing.key.alias" => options[:keyalias],
"android.injected.signing.key.password" => options[:keypass],
}
)
upload_to_play_store(track: 'alpha')
end
Try to rename your productFlavors, for example:
Change dev to devTest.

How can I create a unique variable for each build in Android Studio?

I have six builds like
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.config
manifestPlaceholders = [appVersion: ""];
}
staging {
applicationIdSuffix '.staging'
versionNameSuffix '-staging'
manifestPlaceholders = [appVersion: "-stg"];
}
debug {
applicationIdSuffix '.debug'
versionNameSuffix '-debug'
manifestPlaceholders = [appVersion: "-debug"];
}
}
productFlavors {
panel {
versionCode 2
versionName '1.1'
applicationIdSuffix '.panel'
manifestPlaceholders = [appName: "exampleapp-panel"];
}
admin {
manifestPlaceholders = [appName: "exampleapp-admin"];
}
}
I want to change each function or variable for each build.
I can use it this way in XCode, but I have not found a way in Android studio.
Can I make a setting file using in AndroidStudio like this?
You can use something like following for each build/product flavor.
buildConfigField "boolean", "VALUE_KEY", "true"
resValue "string", "my_string", "Some string"
The first can be accessed in your code as BuildConfig.VALUE_KEY, the 2nd is written to strings.xml
try this :
productFlavors {
pro {
minSdkVersion 15
applicationId 'com.myapps'
signingConfig signingConfigs.release
targetSdkVersion 23
resValue "string", "app_name", "myapps"
buildConfigField "boolean", "IS_DEV", "false"
}
dev {
minSdkVersion 15
applicationId 'com.myapps.dev'
targetSdkVersion 23
resValue "string", "app_name", "myapps 1.2"
buildConfigField "boolean", "IS_DEV", "true"
}
}

How do I include `applicationIdSuffix` in some generated resource value?

Imagine this setup:
android {
buildTypes {
debug {
applicationIdSuffix ".debug"
}
}
productFlavors {
foo {
applicationId defaultConfig.applicationId + '.foo'
}
}
}
How can I set up a dynamic string value such as
resValue "string", "package_name", applicationId
so that it includes the applicationIdSuffix for debug builds?
If I add this to defaultConfig, its my defaultConfig's applicationId that is set. If I add this to the flavor configuration, it is missing the applicationIdSuffix (this is null at this level).
Any hints?
The cool part about applicationIdSuffix is that you can use it in flavors as well as in build types. Check this out:
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "dev.bmax.suffixtext"
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
applicationIdSuffix '.debug'
}
}
productFlavors {
prod {
applicationIdSuffix '.prod'
}
mock {
applicationIdSuffix '.mock'
}
}
}
Now, when I build my 'prodDebug' variant the final application ID is 'dev.bmax.suffixtext.prod.debug', which is what you want if I understand your question correctly.
EDIT
You can access the variant's name in a Gradle task like this:
applicationVariants.all { variant ->
// Use 'variant.name'
}
Gradle Android Plugin version 0.14.3 added support of the variant specific BuildConfigField/resValue:
applicationVariants.all { variant ->
variant.resValue "string", "name", "value"
}

Gradle BuildConfigFields Syntax

What could be wrong with this syntax? I am getting Gradle DSL method not found:'buildConfigFields()' error.
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.okason.drawingapp"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
def filesAuthorityValue = applicationId + ".files"
//Now you can use ${filesAuthority} in your manifest
manifestPlaceholders = [filesAuthority: filesAuthorityValue]
//Now you can use BuildConfig.FILES_AUTHORITY in our code
buildConfigFields "String", "FILES_AUTHORITY", "\"${filesAuthorityValue}\""
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
you should be using buildConfigField and not buildConfigFields
Change
//Now you can use BuildConfig.FILES_AUTHORITY in our code
buildConfigFields "String", "FILES_AUTHORITY", "\"${filesAuthorityValue}\""
to
//Now you can use BuildConfig.FILES_AUTHORITY in our code
buildConfigField "String", "FILES_AUTHORITY", "\"${filesAuthorityValue}\""
are you sure that buildConfigFields even exits ?

Categories

Resources