Is it really possible to use ProGuard in Hybrid Application I am using Cordova version to build an android app where I have to obfuscate the plugin's java code.
Till now I have done this
Added
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
Inside build.gradle of project's root folder.
And uncomment the proguard line from project.properties
proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
But nothing is obfuscating from the code when I decompile the APK.
I had ProGuard running for release builds when Cordova built with Ant, but now that Gradle is used my project's release builds aren't being obfuscated (my "cordova build --release android" output shows a step for :CordovaLib:mergeReleaseProguardFiles, but no other proguard/minification/obfuscation entries).
With Ant, my project.properties file referred to my proguard-project.txt file using the proguard.config parameter.
How do I configure this to work now that Cordova uses Gradle?
Have a look at the updated Proguard Documentation, you now have to change the build.gradle file.
Change the buildType release section to something like this
android {
...
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
}
I'm trying to use proguard but it keeps telling me to look for a project.properties folder and post this code
proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt
the thing is I can't locate it. Where can I find it?
If you are using Android Studio then you will not have a project.properties file as it uses the gradle build system.
You can add ProGuard into your gradle build as follows:
buildTypes {
release {
minifyEnabled true
proguardFile getDefaultProguardFile('proguard-android.txt')
}
}
These lines should be automatically generated when you create a new Android Studio project, although minifyEnabled is set to false.
I switched my IDE from eclipse to android studio and generated apk after some very minor changes (No class or files were added).
The APK generated from eclipse was around of size 3 MB but when I generated APK from android studio, the apk size was around 5.5 MB.
I even tried to clean and generate APK in Release mode but still APK size was same i.e. 5.5 MB.
Is there any specific reason behind this in android studio or am I missing something ?
your problem certainly have nothing to do with Android Studio or Eclipse. It's todo with Gradle and Ant. Those are the built systems used by each respectively.
On a general approach it seems to be that the Ant build was using ProGuard to remove unused resources and classes whilst your build.gradle file is not instructing Gradle to do the same.
Trying adding the minifyEnabled to your release build, like in the example below.
PS: change the name of the proguard file to the one on your project
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
I am new to Android and Android Studio.
During my learning I came across the Google Play Services for Ads and all.
I tried to enable proguard in my project but reading the below link proguard.
The problem is that I am not able to find proguard-project.txt or proguard.cfg in my project structure...
Instead there is a proguard-rules.txt in my project structure...
How can I find these missing files and configure proguard in my project...
Please help...
Use the proguard-rules.txt file instead. Proguard doesn't attach any special significance to the name of its rule input files; it uses whatever's set up in your build files, which for new projects created in recent versions of Android Studio, is:
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
The proguard-android.txt file lives inside your SDK, and contains reasonable Android-wide defaults that all projects should use.
I had the same problem when I started using Android Studio
You can't see the ProGuard files because you are previewing you project in a non Project file mode. Which most probably will be Android view mode.
You have to change the mode by clicking on the drop down list of the Android selection and select Project Files to see all the files in the project as the following:
Then you will be able to see the hidden files in the Android project structure view mode.
And here is a good example for the ProGuard
You can find proguard-project.txt in
C:\Users\"USER"\AppData\Local\Android\android-studio\sdk\tools\proguard
"USER" is the name in you will see when you click on c-drive \users \yourname
the code posted previously must be corrected to the following according to your use:
buildTypes {
release {
minifyEnabled true //according to your use
// or
minifyEnabled false //according to your use
// runProguard false ** NOT USED ANYMORE, replaced by minifyEnabled
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
I couldn't find this proguard-rules.txt anywhere on my Windows machine with Android Studio. I did however find a LayoutExample\app\proguard-rules.pro file. This is probably because I had imported my project from Eclipse, so Android Studio didn't create one automatically. So what I did was:
1 - Copy the proguard-rules.pro from the example project to the same folder as build.gradle for my project (you can either search for this file on your machine or create an empty project)
2 - Edit the code in build.gradle to use this file instead of proguard-rules.txt, e.g.
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
}
Sync gradle, then Build > Build APK. Worked fine for me.
proguard-rules.txt can be found with terminal command on OS X (should be similar on windows as well)
$ locate proguard-rules.txt
On my machine the output is:
/Applications/Android Studio.app/Contents/plugins/android/lib/templates/gradle-projects/AndroidWearModule/root/proguard-rules.txt.ftl
/Applications/Android Studio.app/Contents/plugins/android/lib/templates/gradle-projects/NewAndroidModule/root/proguard-rules.txt.ftl
/Applications/Android Studio.app/Contents/plugins/android/lib/templates/gradle-projects/NewAndroidTVModule/root/proguard-rules.txt.ftl
/Applications/Android Studio.app/Contents/plugins/android/lib/templates/gradle-projects/NewGlassModule/root/proguard-rules.txt.ftl
You can place this file by removing the extra extension beyond txt. Here is what it looks like so you can create your own and place in your android project.
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in ${sdkDir}/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
I had the same problem after updating android studio , I couldn't import my project to new version.
change in the gradle build file.
buildTypes {
release {
minifyEnabled false *//change to this not runProguard false*
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}