How to have different gradle.properties files for release/debug builds? - android

We need to have gradle.properties files with different configs for release and debug builds, because some of the features we use are experimental and they break some things. Is that possible?
Example of our gradle.properties file
org.gradle.daemon=true
org.gradle.jvmargs=-Xmx1500m -XX:MaxPermSize=512m
org.gradle.parallel=true
kotlin.incremental=true
android.enableD8=true

As per official document:
You can create and configure build types in the module-level build.gradle file inside the android block. When you create a new module, Android Studio automatically creates the debug and release build types for you. Although the debug build type doesn't appear in the build configuration file, Android Studio configures it with debuggable true. This allows you to debug the app on secure Android devices and configures APK signing with a generic debug keystore.
You can add the debug build type to your configuration if you want to add or change certain settings. The following sample specifies an applicationIdSuffix for the debug build type, and configures a "staging" build type that is initialized using settings from the debug build type.
You can use same build.gradle for release and debug modes like:
buildTypes {
release {
// Do whatever you want to do in release mode
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
// Do whatever you want to do in debug mode
applicationIdSuffix ".debug"
debuggable true
}
/**
* The `initWith` property allows you to copy configurations from other build types,
* then configure just the settings you want to change. This one copies the debug build
* type, and then changes the manifest placeholder and application ID.
*/
staging {
initWith debug
manifestPlaceholders = [hostName:"internal.example.com"]
applicationIdSuffix ".debugStaging"
}
}
Ref: Source

buildTypes {
release {
shrinkResources true
minifyEnabled true
debuggable false
signingConfig signingConfigs.releaseConfig
}
debug1 {
debuggable true
signingConfig signingConfigs.debug
}
debug2 {
debuggable true
signingConfig signingConfigs.debug
}
}
You came different build variants like above and on Android studios select the build variants option(usually in the bottom left corner). select which variant you want to build the apk and run the app.

Related

React native android build gradle debuggable false does not turn off __DEV__

Hi I cannot found any answer solution for this
I have follwoing custom variant in \android\app\build.gradle
I have tried put debuggable false
But this does not changed __DEV__ to false.
Everyone is telling debug variant and release variant but nobody is telling how exactly a specific toggle to change __DEV__ to false.
Please help thanks.
buildTypes {
alpha {
signingConfig signingConfigs.dev
debuggable false
...
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
matchingFallbacks = ['release', 'debug']
}
}
also I have tried removed 'debug' from matchingFallbacks not working as well.
matchingFallbacks = ['release']
If im not mistaking you are looking at it wrong. As the link below mentions.
You can use the DEV global variable in JavaScript to determine if you're using React Native packager or not. If you are running your app in the iOS Simulator or Android emulator DEV will be set to true.
React Native DEV and PROD variables
As long as your running the app on emulators the __DEV__ variable will be true.
You can try to run in a simulator with --configuration Release
I'm experiencing this problem too, in my case the buildType name should contain "release" keyword. (don't ask me why)
Change alpha to alphaRelease and everything should works fine.
Example:
(I'm using RN 0.68.2)
buildTypes {
debug {
signingConfig signingConfigs.debug
debuggable true
applicationIdSuffix ".dev"
}
alphaRelease {
initWith release
matchingFallbacks = ['release']
signingConfig signingConfigs.hmg
debuggable false
applicationIdSuffix ".hmg"
}
release {
/* Add the firebaseCrashlytics extension (by default, it's disabled to improve build speeds) and set
* nativeSymbolUploadEnabled to true along with a pointer to native libs. */
firebaseCrashlytics {
nativeSymbolUploadEnabled true
unstrippedNativeLibsDir 'build/intermediates/merged_native_libs/release/out/lib'
}
// Caution! In production, you need to generate your own keystore file.
// see https://reactnative.dev/docs/signed-apk-android.
signingConfig signingConfigs.release
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
debuggable false
applicationIdSuffix ""
}
}

Is Proguard necessary for gradle 3.2.1?

I am doing this first time. Using Facebook SDK for android app.
I am following this tutorial.
https://developers.facebook.com/docs/sharing/android/
My app is gradle 3.2.1
Do I need to use ProGuard here?
What code should I write between the given two codes on this link :
https://developer.android.com/studio/build/shrink-code.html?fbclid=IwAR3hmG6hOtzfyiHa3Sehxa4o2j9vq9sPrk8ZVbr-WWyUDakiskFMZQgloJM
android {
buildTypes {
release {
// Enables code shrinking, obfuscation, and optimization for only
// your project's release build type.
minifyEnabled true
// Enables resource shrinking, which is performed by the
// Android Gradle plugin.
shrinkResources true
// Includes the default ProGuard rules files that are packaged with
// the Android Gradle plugin. To learn more, go to the section about
// R8 configuration files.
proguardFiles getDefaultProguardFile(
'proguard-android-optimize.txt'),
'proguard-rules.pro'
}
}
...
}
And another code:
android {
...
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile(
'proguard-android-optimize.txt'),
// List additional ProGuard rules for the given build type here. By default,
// Android Studio creates and includes an empty rules file for you (located
// at the root directory of each module).
'proguard-rules.pro'
}
}
flavorDimensions "version"
productFlavors {
flavor1 {
...
}
flavor2 {
proguardFile 'flavor2-rules.pro'
}
}
}
There are some more small codes below it, which one should I add?
Please explain.
As you add ProGuard files you have to add this
useProguard true
in your gradle File(module)

Build type is always "Release"

I am obtaining that BuildConfig.BUILD_TYPE returns always "release", even if I am compiling it in debug mode.
I include here a part of my build.gradle:
buildTypes {
debug {
debuggable true
minifyEnabled false
}
release {
debuggable false
minifyEnabled false
//md5 sign certificate split in two
proguardFile './dexguard-config/dexguard-release-conservative.pro'
//proguardFile getDefaultDexGuardFile('dexguard-release-aggressive.pro')
proguardFile 'dexguard-project.txt'
}
Thank you!
Make sure you are importing BuildConfig of your own module, with the package name from its AndroidManifest.xml.
Other modules' BuildConfigs might be hardwired to release.
Check your option in Build Variants in Android Studio.
PS: You can also run your release APK in debug mode.

connectedAndroidTest and release build type

I'm using gradle:1.2.3
I would like to run my androidConntectTests (instrumentation tests) on release (signed, minified) configuration, but I cannot.
My build types:
buildTypes {
debug {
minifyEnabled false
debuggable true
}
robotium {
debuggable true
minifyEnabled true
signingConfig signingConfigs.release
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
release {
minifyEnabled true
debuggable false
signingConfig signingConfigs.release
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
I have read, that those tests can only be run on debbugable configurations, so I made "robotium" build type (see above), but it still does not work.
When I try calling "gradle tasks" it shows only connectedAndroidTest-Flavour-Debug, and calling "connectedAndroidTest-Flavour-Release/Robobium" simply fails with "task XXX not found in root project".
Is there any way to make instrumentation tests run on diffrent build type?
The android gradle plugin will create test variants for all your flavors. To switch the build type used you can do this, as stated in the documentation
Currently only one Build Type is tested. By default it is the debug Build Type, but this can be reconfigured with:
android {
...
testBuildType "staging"
}

This application does not have the debuggable attribute enabled in its manifest

Cannot debug application com.domain.test on device samsung-gt_i9300-323020cfc86b804f.
This application does not have the debuggable attribute enabled in its manifest.
If you have manually set it in the manifest, then remove it and let the IDE automatically assign it.
If you are using Gradle, make sure that your current variant is debuggable.
Your comment has already hinted the answer to this post but since you have not selected an answer I'll write it down.
Change build variant from release to debug from android studio left corner.
A right solution is written in https://stackoverflow.com/a/25628789/2914140:
open build.gradle of your module, type: 'debuggable true' (an example is below):
buildTypes {
release {
signingConfig signingConfigs.release
debuggable true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
debug {
applicationIdSuffix ".debug"
debuggable true
}
}
When you generate a signed APK from menu, you should edit 'release' branch changing 'debuggable true' to false in order to avoid a debuggable information.
In build.gradle
debug {
debuggable true
signingConfig signingConfigs.debug
}
for whose came here searching TS's quote, check if you set Android Application in Run/Debug configuration popup. Not Native, like in my mistake.

Categories

Resources