11

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.

hoss
  • 2,430
  • 1
  • 27
  • 42
mjanes
  • 315
  • 2
  • 9
  • I am not being able to run proguard either. Are you generating the apk through Build -> Generate Signed APK ? If so, what proguard file do you choose in the following dialog? There is very little information about this on the documentation... – Ricardo Belchior Jul 22 '13 at 16:29
  • I am experiencing exactly the same, pro guard doesn't do anything, although the configuration file is provided during the "Generate Signed APK" process. Unfortunately there is barely information about Android Studio working with Pro Guard. Also stated the question here: http://stackoverflow.com/questions/18087664/generating-a-pro-guard-configuration-file-with-android-studio#comment26529592_18093805 – Peter Osburg Aug 17 '13 at 17:41

3 Answers3

3

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

Community
  • 1
  • 1
IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
2

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.

mjanes
  • 315
  • 2
  • 9
0
**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

Android Genius
  • 224
  • 1
  • 6