How do I disable proguard for building my Android app? - android

It used to be that proguard was controlled by project.properties, but that's no longer the case, and the Android documentation has not been updated. The project.properties file now clearly states that the it is generated by Android Tools and changes will be erased. I've tried commenting out the proguard.config line, but when I compile, it rewrites the project.properties, and continues to use proguard. What is the current method of disabling proguard? Thanks!
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system edit
# "ant.properties", and override values to adapt the script to your
# project structure.
#
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt:proguard-google-api-client.txt
# Project target.
target=android-17
android.library.reference.1=../../../../android-sdk-linux/extras/google/google_play_services/libproject/google-play-services_lib

set this
minifyEnabled false
in your app build.gradle
Like this:
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

set
useProguard false
in your app build.gradle
like
buildTypes {
release {
minifyEnabled false
useProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

Have you tried to add the next line to your proguard configuration file (to the beginning of the file) :
-dontobfuscate
?

Try to delete the proguard directory in your project. So proguard will forget its mapping.

According to the React-Native Docs, To disable Proguard, set def enableProguardInReleaseBuilds to false in your android/app/build.gradle:
/**
* Run Proguard to shrink the Java bytecode in release builds.
*/
def enableProguardInReleaseBuilds = false // Instead of true

In my case
1 ->
add this line in the android tag:
android {
def enableProguardInReleaseBuilds = false // Instead of true
2 -> then add this line
buildTypes {
release {
minifyEnabled false
shrinkResources = false
signingConfig signingConfigs.release
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
I hope it will work for you

Related

Android project not obfuscating

I want to obfuscate my android code, I have set minifienable true and setup proguard file, but after generating apk and decompile, the code is not obfuscated. This is my proguard :
my proguard file:
-dontwarn com.huawei.**
-dontwarn org.conscrypt.*
-dontwarn org.openjsse.javax.net.ssl.*
-dontwarn org.openjsse.net.ssl.OpenJSSE
my build.gradle file
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
debug{
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
To enable ProGuard in Android Studio. Below is the sample how to enable default ProGuard in Android Studio.
Go to the build.gradle file of app
enable the proguard minifyEnabled true and useProguard true
enable shrinkResources true to reduce the APK size by shrinking resources.
proguardFiles getDefaultProguardFile('proguard-android.txt') to enable the default one. If you want to use your own proguard file then use the below rules.
release
{
debuggable false
useProguard true
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
delete build file
invalidate cache and restart android studio

Removing unused resources requires unused code shrinking to be turned on

I am preparing to release an App to production. So, I generated signed apk. After generating signed apk, I was getting a problem. My apk file size is a little large and I tried ways to shrink the apk size. I already tried
app --> Refactor --> Remove Unused Resources
and it is not too reduce. So, I added shrinkResources true in my build.gradle(app)
buildTypes {
release {
minifyEnabled false
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
After adding shrinkResources true and I got below error when I rebuild. My question is how should I turn on unused Code shrinking first? Thanks and appreciating.
Resource shrinking works only in conjunction with code shrinking. After the code shrinker removes all unused code, the resource shrinker can identify which resources the app still uses. This is especially true when you add code libraries that include resources—you must remove unused library code so the library resources become unreferenced and, thus, removable by the resource shrinker
To enable resource shrinking, set the shrinkResources property to true in your build.gradle file (alongside minifyEnabled for code shrinking). For example:
android {
...
buildTypes {
release {
shrinkResources true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
}
reference
Maybe you set by mistake minifyEnabled = false and shrinkResources = true in your buildTypes.debug, so, maybe, it is a root of a problem, not your buildTypes.release
android {
buildTypes {
release {
minifyEnabled true
shrinkResources true
}
}
}
You might want to refer to the Android Documentation to shrink your code and resources:
Shrink your code and resources
Like a comment already pointed out, resource shrinking only works when you have used the code shrinker. To enable shrinkResources in your build.gradle file you must have first set minifyEnabled to true
Simple just open the build.gradle file on App level i.e. android/app/build.gradle and implement this:
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
useProguard true
minifyEnabled false
shrinkResources false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
In order to use resource shrinking, you also need to enable code shrinking as they both works in conjunction.
So to do so, set shrinkResources true along with minifyEnabled true.
You can follow the official site for the same.
make sure to add it into proper part of gradle
signingConfigs {
buildTypes {
debug {
buildConfigField "java.util.Date", "buildTime", "new java.util.Date(" + System.currentTimeMillis() + "L)"
}
release {
buildConfigField "java.util.Date", "buildTime", "new java.util.Date(" + System.currentTimeMillis() + "L)"
}
}
}
buildTypes {
release {
minifyEnabled false
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
If you have added shrinkResources true make sure it comes after minifyEnabled true the order matters so https://stackoverflow.com/a/56426634/10355668 is correct thanks

Code shrinking on debug

Before I release the app, I am trying to test whether there will be any changes(methods, variables removed) if I code shrink with Instant run the app. I am following this Enable code shrinking with Instant Run but it does not show any signs in my code that was removed or changed.
android {
buildTypes {
debug {
minifyEnabled true
useProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
}
Is there any way to check if there are changes made?
You should use Shrinking options -printUsage and it will tell you dead code, which eventually will be removed during shrinking.
-printusage [filename]
Specifies to list dead code of the input class files. The list is printed to the standard output or to the given file. For example, you can list the unused code of an application. Only applicable when shrinking.
android {
...
buildTypes {
release {
shrinkResources true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
}

Android proguarded apk still readable

I tried to proguard my app. It successfully obfuscated the apk. However, when i try to view the java code of my apk using Apk_oneclick, I am able to. I have created a release version of my apk. Still the problem persist. Any help would be much appreciated.
Thanks in advance.
build.gradle:
Proguard Rules:
Java code from the release-apk:
For enabling ProGuard configurations for your application you need to enable it in your module level gradle file. you need to set the value of minifyEnabled true.
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
You can also enable shrinkResources true which will remove resources that ProGuard flaggs as unused.
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
You need to set following property
and add some rules in proguard-android
buildTypes {
release {
debuggable false
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
Got it working. Cleaned the project and ran the same with some changes in the Proguard rules.

i can't build app when use ProGuard in Android Studio

I am using lasted version of Android Studio, and i have obfuscated my project by ProGuard in Android Studio.
edit content of Build.gradlesuch as this :
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
but when start the build project, an error like that
warning Image :
How can I fix this?
Simply add -dontwarn com.github.siyamed.shapeimageview to your proguard-rules.pro.
I had same issue,try to change minifyEnabled true to minifyEnabled false.
And just refer this enter link description here

Categories

Resources