Home » Android » Android Studio ProGuard does not appear to run

Android Studio ProGuard does not appear to run

Posted by: admin May 14, 2020 Leave a comment

Questions:

I switched over from Eclipse to Android Studio in the last few days and have gotten most everything working. However, when I generate a signed APK it appears as though ProGuard is never running.

I am using the Generate Signed APK Wizard, selecting ‘Run ProGuard’ and specifying my proguard.cfg as the config file. The build process runs without errors and generates a functional apk, but that apk is 65% larger than the one generated by Eclipse. When I generate the apk through Android Studio’s APK Wizard and do not select ‘Run Proguard’ the resulting apk is the same size as the one that should have had ProGuard run on it. No mapping.txt, seeds.txt, or usage.txt is generated anywhere in my project directory. I have tried adding

buildTypes {
    release {
        runProguard true
        proguardFile file('proguard.cfg')
        proguardFile getDefaultProguardFile('project-android.txt')
    }
}

and variations to my build.gradle file but that has had no effect either.

This is occurring on Android Studio 0.2.0, though I was seeing the same behavior on 0.1.9. I am working on Windows 7.

Can anyone tell me what might be going on? I would be happy if I could find the logs ProGuard is supposed to generate.

How to&Answers:

Just update your build.gradle

buildTypes {           
   release {
     minifyEnabled true
     proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
   }
}

Details Reference.
I hope it will helps you

Answer:

Happily, I have found a solution. The issue was that before creating the signed apk, I had modified the package name in the AndroidManifest in order to overwrite a particular build in the Google Play Store. However, this change of package name had not refactored all of the corresponding “import ‘package name’.R;” lines throughout the code. Today, after re-importing the project, it would no longer build because of errors attempting to import R. Once I modified all the import lines, not only did my project build properly, but exporting the signed apk properly ran ProGuard.

I’m guessing that Android Studio was somehow caching the “import R” lines and that when ProGuard was attempting to run it did not have those cached values and then crashed. Why there was no error output for me to see, I do not know.

Answer:

**in new Gradle system** 

BuildType.runProguard                 ->  minifyEnabled
BuildType.zipAlign                    -> zipAlignEnabled
BuildType.jniDebugBuild               -> jniDebuggable
BuildType.renderscriptDebug           -> renderscriptDebuggable
ProductFlavor.renderscriptSupportMode -> renderscriptSupportModeEnabled
ProductFlavor.renderscriptNdkMode     -> renderscriptNdkModeEnabled

or visit at
http://tools.android.com/tech-docs/new-build-system