Add different proguard file for debug - android

I have a project with two modules. It exists a default configuration of build.gradle:
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
And I want to add a different configuration (proguard and minifying) for debug compilation as follow:
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
minifyEnabled false
proguardFiles 'proguard-rules-debug.pro'
}
}
When I put this code in my project, it doesn't compile. The log show a message error for each reference to another module:
Error:(37, 42) error: package com.example does not exist
Full Gradle configuration of the two modules.
The app module:
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
...
}
}
apply plugin: 'com.android.application'
...
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
...
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.3"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
minifyEnabled false
}
}
}
repositories {
maven {
...
}
}
repositories{
maven {
url 'http://dl.bintray.com/amulyakhare/maven'
}
}
...
dependencies {
...
}
The library module:
apply plugin: 'com.android.library'
android {
compileSdkVersion 24
buildToolsVersion "24.0.1"
defaultConfig {
...
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
minifyEnabled false
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
...
}

I would try the following:
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-project.txt'), 'proguard-rules.pro'
}
debug {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-project.txt'), 'proguard-rules-debug.pro'
}
}
Alternatively did you try putting the rules files into the build-types folders? You could put the proguard-rules.pro file into the build-types/release folder and the proguard-rules-debug.pro file into the build-types/debug folder.

Related

Changing build type to Release causes "Cannot resolve symbol" for some classes

When I change my build type to release, some of my class are being shown as "Cannot find symbol" in the android studio. Even though the error is being shown, the application is successfully built and run. When I change back to debug these files are recognized properly.
This is my build.gradle
apply plugin: 'com.android.application'
apply plugin: 'realm-android'
apply plugin: 'io.fabric'
apply plugin: 'com.google.gms.google-services'
android {
signingConfigs {
debug {
keyAlias 'debugkey-name'
keyPassword 'dpassword'
storeFile file('debugkey.jks')
storePassword 'dspassword'
}
release {
keyAlias 'releasekey-name'
keyPassword 'rpassword'
storeFile file('releasekey.jks')
storePassword 'rspassword'
}
}
compileSdkVersion rootProject.ext.compileSdkVersion
defaultConfig {
applicationId "com.app.appname"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
multiDexEnabled true
versionCode 0
versionName "0.9.2"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
applicationVariants.all { variant ->
variant.outputs.all {
outputFileName = "Appname-${variant.name}-${defaultConfig.versionName}.apk"
}
}
buildTypes {
debug {
minifyEnabled false
shrinkResources false
resValue "string", "map_box_key", "mapboxfakeKeyalksdk;lk;laksd;lkas;ldkndasdjasndkaklsjdlaksdjlaksjdkajsdlkj"
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.debug
debuggable true
jniDebuggable true
}
release {
minifyEnabled true
shrinkResources true
resValue "string", "map_box_key", "mapboxkeyfakekajsdhkajdsklajlskdjlaksjdajlskjdlkjaslkdjlkasjdlkajdlkjaslkd"
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
debuggable false
jniDebuggable false
renderscriptDebuggable false
}
}
flavorDimensions "Environment"
productFlavors {
appDemo {
resValue "string", "app_name", "AppName"
resValue "string", "url_base_address", "https://baseurl.com"
dimension "Environment"
}
appDev {
applicationIdSuffix ".dev"
resValue "string", "app_name", "Dev-AppName"
resValue "string", "url_base_address", "https://baseurl.com"
dimension "Environment"
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
lintOptions {
disable 'LogNotTimber'
}
}
android.sourceSets {
test {
java.srcDirs = ["src/main/java", "src/mock/java", "src/test/java"]
}
androidTest {
java.srcDirs = ["src/main/java", "src/mock/java", "src/androidTest/java"]
}
appDemo {
java.srcDirs = ["src/main/java", "src/real/java"]
}
appDev {
java.srcDirs = ["src/main/java", "src/real/java"]
}
}
dependencies {
//so many dependencies
}
repositories {
mavenCentral()
}
This is my proguard rules:
-keepclassmembers class
android.support.design.internal.BottomNavigationMenuView {
boolean mShiftingMode;
}
-keepattributes *Annotation*
-keepattributes SourceFile,LineNumberTable
-keep class com.crashlytics.** { *; }
-dontwarn com.crashlytics.**
-keep class android.support.** { *; }
-keep interface android.support.** { *; }
When I try to manually import some file I am not able to see some packages and classes but I am able to go to them with search option in android studio(double shift)
Things I have tried:
Clean and rebuild the project
Invalidate cache and restart
Deleted .idea and .gradle folders and rebuild
Synced the project
update build tools
When I go back to debug, the issue is not there, so it seems like the issue is with my Gradle config.
Please help me find the issue.
For testing purpose modify you app build.gradle to not to optimize apk for release build.
release {
minifyEnabled false
shrinkResources false
....
..}

Proguard not working after update to Google Play Services 11.8.0

After updating Google Play Services to 11.8.0 (from 11.6.2) my builds stop working.
This is what I got:
Unexpected error while computing stack sizes:
Class = [com/google/android/gms/internal/zzao]
Method = [zzf(Ljava/lang/String;)J]
Exception = [java.lang.IllegalArgumentException] (Stack size becomes negative after instruction [23] invokestatic #146 in [com/google/android/gms/internal/zzao.zzf(Ljava/lang/String;)J])
FAILURE: Build failed with an exception.
I'm using Android Studio 3.0.1 with Gradle 4.4.1
My app build.gradle file
buildscript {
repositories {
maven { url "https://maven.fabric.io/public" }
}
dependencies {
classpath "io.fabric.tools:gradle:1.25.1"
}
}
repositories {
maven { url "https://maven.fabric.io/public" }
}
apply plugin: "com.android.application"
apply plugin: "io.fabric"
apply plugin: "let"
apply plugin: "realm-android"
android {
compileSdkVersion project.androidSDKVersion
buildToolsVersion("$androidBuildToolsVersion")
defaultConfig {
versionCode project.versionCode
versionName project.versionName
minSdkVersion project.androidMinSdkVersion
targetSdkVersion project.androidTargetSdkVersion
vectorDrawables.useSupportLibrary = true
resConfigs "pl"
}
buildTypes {
release {
minifyEnabled true
shrinkResources false
crunchPngs false
proguardFiles getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro", "proguard-fresco.pro"
signingConfig signingConfigs.release
}
debug {
ext.enableCrashlytics = false
ext.alwaysUpdateBuildId = false
}
}
flavorDimensions "tier", "minApi"
productFlavors {
minApi21 {
minSdkVersion project.androidMinDevSdkVersion
dimension "minApi"
}
minApi16 {
minSdkVersion project.androidMinSdkVersion
dimension "minApi"
}
dev {
multiDexEnabled true
dimension "tier"
}
prod {
multiDexEnabled false
dimension "tier"
}
}
variantFilter { variant ->
def names = variant.flavors*.name
if (names.contains("prod") && names.contains("minApi21")) {
setIgnore(true)
}
}
applicationVariants.all { variant ->
appendVersionNameVersionCode(variant, defaultConfig)
}
lintOptions {
checkReleaseBuilds false
textReport true
textOutput "stdout"
fatal "UnusedResources"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
debugImplementation("com.android.support:multidex:$multidexVersion")
implementation("com.android.support:support-fragment:$androidSupportVersion")
implementation("com.android.support:support-annotations:$androidSupportVersion")
implementation("com.android.support:appcompat-v7:$androidSupportVersion")
implementation("com.android.support:design:$androidSupportVersion")
implementation("com.android.support:recyclerview-v7:$androidSupportVersion")
implementation("com.android.support:cardview-v7:$androidSupportVersion")
implementation("com.android.support:customtabs:$androidSupportVersion")
implementation("com.android.support.constraint:constraint-layout:$constraintLayoutVersion")
implementation("com.android.installreferrer:installreferrer:$installReferrerVersion")
implementation("com.google.android.gms:play-services-analytics:$playServicesVersion")
implementation("com.google.android.gms:play-services-location:$playServicesVersion")
implementation("com.google.android.gms:play-services-ads:$playServicesVersion")
implementation("com.google.android.gms:play-services-auth:$playServicesVersion")
implementation("com.google.firebase:firebase-core:$playServicesVersion")
implementation("com.google.firebase:firebase-messaging:$playServicesVersion")
implementation("com.google.firebase:firebase-config:$playServicesVersion")
implementation("com.google.firebase:firebase-auth:$playServicesVersion")
implementation("com.google.firebase:firebase-invites:$playServicesVersion")
(...) // I had removed other dependencies from the list
}
def appendVersionNameVersionCode(variant, defaultConfig) {
variant.outputs.all { output ->
def versionCode = android.defaultConfig.versionCode
output.versionCodeOverride = versionCode
outputFileName = "${rootProject.name}-${variant.name}-${variant.versionName}-${versionCode}.apk"
}
}
apply plugin: "com.google.gms.google-services"
You don't need to disable optimization entirely, just optimization on the problem class. I had the same issue and got around it by adding the following to the proguard-rules.pro file:
-keep class com.google.android.gms.internal.** { *; }
I have a similar issue. As suggested in this SO thread you just need to add these lines in your build.gradle file :
...
release {
debuggable false
useProguard true
...
}
...
I also had to remove the pro guard optimization by replacing :
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
by
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

Error:(12, 23) java: package org.apache.http does not exist

my android project doesn't contain build.gradle to put useLibrary 'org.apache.http.legacy'
Sample Build.gradle
apply plugin: 'com.android.application'
android {
useLibrary 'org.apache.http.legacy'
compileSdkVersion 25
buildToolsVersion "25.0.0"
defaultConfig {
applicationId "com.Sample.App"
minSdkVersion 14
targetSdkVersion 25
versionCode 1
versionName "1.1"
}
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
debuggable false
jniDebuggable false
renderscriptDebuggable false
}
debug {
minifyEnabled false
shrinkResources false
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
debuggable true
jniDebuggable true
renderscriptDebuggable true
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.android.support:design:25.1.0'
}

Gradle Warning: missing groovy return statement

I'm having the following warning in my gradle build file
Not all execution paths return a value
This inspection reports on missing groovy return statement at the end of methods returning
and this is the code in that file
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "ac.company.srikar.quickhelpindia"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
android {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
}
}
Can anyone tell what is the issue here and how to get rid of this warning.
With Android Studio 2.2 I had to add a return void before the final bracket in the android section.
android {
compileSdkVersion 24
buildToolsVersion "24.0.2"
defaultConfig {
applicationId "com.example.app"
minSdkVersion 19
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
buildTypes {
debug {
minifyEnabled false
shrinkResources false
}
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
standard {
applicationId "com.example.app.standard"
}
free {
applicationId "com.example.app.free"
}
}
// `return void` removes the lint error: `Not all execution paths return a value`.
return void
}
I have been getting this same warning and I think it is incorrect. I have read through the gradle documentation and it does not appear that a return type is needed. However, the warnings bug me and the only way I could get rid of it was to add return true.
buildTypes {
android {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
return true
}
}
}
I doubt this is the "correct" solution; however, it does remove the warnings and it doesn't cause any issues.
I fixed this by adding the recommended suppression string from inspection:
//noinspection GroovyMissingReturnStatement
android {
compileSdkVersion 25
buildToolsVersion "23.0.3"
...
I got rid of this warning when I specified both, minifyEnabled and shrinkResources.
buildTypes {
debug {
minifyEnabled false
shrinkResources false
}
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
It seems that this is an issue fixed in Android Studio 2.3:
https://code.google.com/p/android/issues/detail?id=223575

debuggable false in android studio 0.4.5

<application
android:debuggable="false"
get a error saying "Avoid hardcoding the debug mode; leaving it out allows debug and release builds to automatically assign one"
I deleted what is up in AndroidManifest and I add this in the build.gradle
android {
compileSdkVersion 18
buildToolsVersion '19.0.0'
defaultConfig {
minSdkVersion 7
targetSdkVersion 19
versionCode 3
versionName "1.2"
}
buildTypes {
debug {
debuggable true
jniDebugBuild true
}
release {
debuggable false
jniDebugBuild true
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:+'
compile files('build/libs/GoogleAdMobAdsSdk-6.4.1.jar')
}
but still does not work when i upload to play store
thanks
This is what I used and it worked perfectly
buildTypes {
debug {
debuggable false
}
release {
runProguard false
debuggable false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}

Categories

Resources