I have to value in the app module BuildConfig, but I want to use this value from the other module. how can I do it?
1-This is app Gradle:
applicationVariants.all { variant ->
def privacyUrl = "https://www.google.com/privacy-policy"
def termsUrl = "https://www.gogle.com/terms-of-service/"
variant.buildConfigField "String", "URL_PRIVACY_POLICY", "\"${privacyUrl}\""
variant.buildConfigField "String", "URL_TERMS_OF_USE", "\"${termsUrl}\""
if (variant.name.startsWith("development")) {
def domain = "https://api.dev.google.com/"
def countryCode = "+63"
variant.buildConfigField "String", "BASE_URL", "\"${domain}\""
variant.buildConfigField "String", "COUNTRY_CODE", "\"${countryCode}\""
} else if (variant.name.startsWith("staging")) {
def domain = "https://api.stage.google.com/"
def countryCode = "+0000"
variant.buildConfigField "String", "COUNTRY_CODE", "\"${countryCode}\""
variant.buildConfigField "String", "BASE_URL", "\"${domain}\""
}
//production
else {
def domain = "https://api.google.com/"
def countryCode = "+000"
variant.buildConfigField "String", "BASE_URL", "\"${domain}\""
variant.buildConfigField "String", "COUNTRY_CODE", "\"${countryCode}\""
}
}
2-This is profile module gradle:
android {
compileSdk Versions.compile_sdk_version
defaultConfig {
minSdk Versions.min_sdk_version
targetSdk Versions.target_sdk_version
versionCode Versions.version_code
versionName Versions.version_name
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
enableCompose(this)
}
I want to use privacyUrl and termsUrl in the profile module but I don't have access to the app module BuldConfig
Related
build.gradle module
`
android {
namespace 'com.bangkit.booking_futsal'
compileSdk 32
defaultConfig {
applicationId "com.bangkit.booking_futsal"
minSdk 21
targetSdk 32
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
}
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
viewBinding true
}
buildscript {
repositories {
maven { url "http://dl.bintray.com/pt-midtrans/maven" }
maven { url "https://jitpack.io" }
}
}
productFlavors {
sandbox {
buildConfigField "String", "BASE_URL", "\"BASE_URL\""
buildConfigField "String", "CLIENT_KEY", "\"CLIENT_KEY\""
}
}
}`
i added buildscript and productFlavors in gradle module, but it generates error as shown below.
[error(https://i.stack.imgur.com/dNlHG.png)
Cannot find a variant matching build type 'debug' and product flavors
'[]' in :app
here I use kotlin and android studio dolphin
I expect no errors when syncing the project
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,
there's an option to attach a debugger to an installed app from android studio
I used to use it but, recently I joined a new company and it's not working showing me that error after selecting the process
this is my Gradle code I've:
plugins {
id("com.android.application")
id("kotlin-android")
id("kotlin-android-extensions")
id("kotlin-kapt")
id("androidx.navigation.safeargs")
id("com.google.firebase.firebase-perf")
id("com.google.firebase.crashlytics")
id("com.google.firebase.appdistribution")
id("com.github.triplet.play") version "2.8.0"
}
android {
compileSdkVersion 30
buildToolsVersion '30.0.3'
ndkVersion '21.3.6528147'
defaultConfig {
ndk.abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
applicationId "xxx.xxx.xxx"
minSdkVersion 21
targetSdkVersion 30
versionCode gitVersionCode
versionName gitVersionName
multiDexEnabled true
vectorDrawables.useSupportLibrary = true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
javaCompileOptions {
annotationProcessorOptions {
arguments += ["room.schemaLocation": "$projectDir/schemas".toString()]
}
}
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8
}
testOptions {
animationsDisabled = true
}
sourceSets {
androidTest.assets.srcDirs += files("$projectDir/schemas".toString())
}
signingConfigs {
appGallery{
keyAlias "XXXXX"
keyPassword "XXXXX"
storeFile file("XXXXX")
storePassword "XXXXX"
}
playStore {
keyAlias "XXXXX"
keyPassword "XXXXX"
storeFile file("XXXXX")
storePassword "XXXXX"
}
config {
storeFile file("XXXXX")
storePassword "XXXXX"
keyPassword "XXXXX"
keyAlias "XXXXX"
}
}
lintOptions {
checkReleaseBuilds false
abortOnError false
}
bundle {
language {
enableSplit = false
}
}
buildTypes {
debug {
signingConfig signingConfigs.config
getIsDefault().set(true)
minifyEnabled false
debuggable true
jniDebuggable false
shrinkResources false
zipAlignEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro', '$playcoreDir/proguard/common.pgcfg', '$playcoreDir/proguard/per-feature-proguard-files'
manifestPlaceholders = [isEnableCrashReporting: "false"]
}
release {
signingConfig signingConfigs.config
minifyEnabled true
shrinkResources true
zipAlignEnabled true
debuggable false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro', '$playcoreDir/proguard/common.pgcfg', '$playcoreDir/proguard/per-feature-proguard-files'
manifestPlaceholders = [isEnableCrashReporting: "true"]
}
unitTestVariants.all {
it.mergedFlavor.manifestPlaceholders += [isEnableCrashReporting: "false"]
}
externalNativeBuild {
ndkBuild {
path 'src/main/jni/Android.mk'
}
}
}
flavorDimensions "audience"
productFlavors {
appGallery {
dimension "audience"
setProperty("archivesBaseName", "XXX")
signingConfig signingConfigs.appGallery
buildConfigField "String", "BASE_URL", "\"XXXXX\""
firebaseAppDistribution {
releaseNotes = "Version XXXXX"
serviceCredentialsFile = file(firebaseServiceAcc)
appId = firebaseAppId
groups = "XXXX"
apkPath = "app/build/outputs/apk/appGallery/release/XXX-appGallery-release.apk"
}
}
playStore {
dimension "audience"
setProperty("archivesBaseName", "XXX")
buildConfigField "String", "BASE_URL", "\"XXXXX\""
signingConfig signingConfigs.playStore
}
staging {
dimension "audience"
getIsDefault().set(true)
signingConfig signingConfigs.playStore
setProperty("archivesBaseName", "XXX")
versionNameSuffix "-Staging"
buildConfigField "String", "BASE_URL", "\"XXXX\""
firebaseAppDistribution {
releaseNotes = "Development Version\nUrl : XXXXX"
serviceCredentialsFile = file(firebaseServiceAcc)
appId = firebaseAppId
groups = "XXXXX"
apkPath = "app/build/outputs/apk/staging/release/XXX-staging-release.apk"
}
}
}
buildFeatures {
dataBinding true
}
testOptions {
unitTests.includeAndroidResources = true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/notice.txt'
exclude 'META-INF/ASL2.0'
exclude("META-INF/*.kotlin_module")
}
}
play {
serviceAccountCredentials = file(googlePlayServiceAcc)
track = "beta"
defaultToAppBundles = true
resolutionStrategy = "auto"
releaseStatus = "completed"
updatePriority = 5
userFraction = 1.0
}
dependencies {
// my libs
}
apply plugin: 'com.google.gms.google-services'
so, it'd be nice if anyone helped me to solve this issue
HINT: normal debug run working but, it's taking time to build & run in debug mode
I have a Android Library and I am using it in app module. In library I use a BuildConfig.SPECIAL_VALUE.
I would like to override this BuildConfig in my app module build gradle.
I found similary question but It doesn't help me (Access buildConfigField from gradle in Android app)
I try this but is not working:
My app module build.gradle:
android {
publishNonDefault true
compileSdkVersion 28
flavorDimensions "default"
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "app....id"
flavorDimensions "default"
minSdkVersion 23
targetSdkVersion 28
versionCode 1
versionName "1.0.0"
multiDexEnabled true
renderscriptTargetApi 18
renderscriptSupportModeEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
buildConfigField 'boolean', 'DEBUG_LOG_ENABLED', 'false'
signingConfig signingConfigs.productivity_mentor_release_config
debuggable = false
manifestPlaceholders = [crashlyticsEnabled: true]
}
debug {
testCoverageEnabled = false
buildConfigField 'boolean', 'DEBUG_LOG_ENABLED', 'true'
debuggable = true
manifestPlaceholders = [crashlyticsEnabled: false]
}
unitTest {
testCoverageEnabled = false
buildConfigField 'boolean', 'DEBUG_LOG_ENABLED', 'false'
manifestPlaceholders = [crashlyticsEnabled: false]
}
}
productFlavors {
develop {
buildConfigField 'boolean', 'LOG_EVENTS_TO_REMOTE_ENABLED', 'false'
buildConfigField 'boolean', 'FIREBASE_CRASH_ENABLED', 'false'
buildConfigField 'String', 'SPECIAL_VALUE', '"11"'
}
production {
buildConfigField 'boolean', 'LOG_EVENTS_TO_REMOTE_ENABLED', 'true'
buildConfigField 'boolean', 'FIREBASE_CRASH_ENABLED', 'true'
buildConfigField 'String', 'SPECIAL_VALUE', '"22"'
}
beta {
buildConfigField 'boolean', 'LOG_EVENTS_TO_REMOTE_ENABLED', 'true'
buildConfigField 'boolean', 'FIREBASE_CRASH_ENABLED', 'true'
buildConfigField 'String', 'SPECIAL_VALUE', '"33"'
}
roboTest {
minSdkVersion 18
buildConfigField 'boolean', 'LOG_EVENTS_TO_REMOTE_ENABLED', 'false'
buildConfigField 'boolean', 'FIREBASE_CRASH_ENABLED', 'true'
buildConfigField 'String', 'SPECIAL_VALUE', '"44"'
}
}
testOptions {
unitTests.returnDefaultValues = true
}
lintOptions {
abortOnError false
}
compileOptions {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
And my library build.gradle:
android {
compileSdkVersion 28
flavorDimensions "default"
buildToolsVersion '28.0.3'
publishNonDefault true
defaultConfig {
minSdkVersion 22
targetSdkVersion 28
multiDexEnabled true
renderscriptTargetApi 18
renderscriptSupportModeEnabled true
javaCompileOptions {
annotationProcessorOptions {
arguments = ["room.schemaLocation":
"$projectDir/schemas".toString()]
}
}
}
buildTypes {
release {}
debug {}
unitTest { }
}
productFlavors {
develop {
buildConfigField 'boolean', 'LOG_EVENTS_TO_REMOTE_ENABLED', 'false'
buildConfigField 'boolean', 'FIREBASE_CRASH_ENABLED', 'false'
buildConfigField 'String', 'SPECIAL_VALUE', '"1"'
}
production {
buildConfigField 'boolean', 'LOG_EVENTS_TO_REMOTE_ENABLED', 'true'
buildConfigField 'boolean', 'FIREBASE_CRASH_ENABLED', 'true'
buildConfigField 'String', 'SPECIAL_VALUE', '"2"'
}
beta {
buildConfigField 'boolean', 'LOG_EVENTS_TO_REMOTE_ENABLED', 'true'
buildConfigField 'boolean', 'FIREBASE_CRASH_ENABLED', 'true'
buildConfigField 'String', 'SPECIAL_VALUE', '"3"'
}
roboTest {
minSdkVersion 18
buildConfigField 'boolean', 'LOG_EVENTS_TO_REMOTE_ENABLED', 'false'
buildConfigField 'boolean', 'FIREBASE_CRASH_ENABLED', 'true'
buildConfigField 'String', 'SPECIAL_VALUE', '"4"'
}
}
testOptions {
unitTests.returnDefaultValues = true
}
lintOptions {
abortOnError false
}
compileOptions {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
}
ext {
google_services_version = '16.0.7'
}
Below is an extract from my gradle source code. What I want to achieve is to add suffix to app name when buildType.debug is executed. I tried the following code, but variables are in gradle assigned in sequence as they are written in file and not as task order. So in the example below buildVariant variable will always be equal to Release.
{
def buildVariant = ""
buildTypes {
debug {
manifestPlaceholders = [showDebug: 'true']
buildVariant = " (DEBUG)"
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
manifestPlaceholders = [showDebug: 'false']
signingConfig signingConfigs.myConf
buildVariant = " Release"
}
}
productFlavors {
flavour1{
resValue 'string', 'app_name', 'Flavour1'+buildVariant
}
flavour2{
resValue 'string', 'app_name', 'Flavour2'+buildVariant
}
flavour3{
resValue 'string', 'app_name', 'Flavour3'+buildVariant
}
}
It was a really interesting puzzle to solve, so thanks for the question!
Here what you can do:
android {
compileSdkVersion 23
buildToolsVersion "23.0.0"
defaultConfig {
....
}
buildTypes {
debug {
}
release {
}
}
productFlavors {
FlavorA {
}
FlavorB {
}
}
applicationVariants.all { variant ->
variant.resValue "string", "app_name", '"' + variant.productFlavors.get(0).name + '_' + variant.buildType.name + '"'
}
}
dependencies {
}
As a result, it'd print the app name "FlavorA_debug", "FlavorB_release", etc.
(NB! I ran it with gradle classpath 'com.android.tools.build:gradle:1.3.0' - works great, though I didn't try with older versions)