Obfuscating code in android studio - android

Under minifyEnabled I changed from false to true.
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
Then I generated a signed APK and used javadecompilers.com to see if files had been altered and the classes,variables, etc were still the same.
I also attempted to use dex2jar, but the terminal stated that no files were found. I also attempted to export my android studio project as a jar file.
Any other suggestions ?

Did you build a release version of your application? As default for minifyEnabled is false, so if you build a debug version, that would explain it.
Other than that, could you post your proguard-rules.pro file? It might contain exceptions that are too broad.
I've used dex2jar many many times, and it's worked for me.
I'm on a mac, so i simply run "./d2j-dex2jar.sh app.apk" command, and then open the resulting jar file in a program called JDGui, there you can see all the files in the jar file.

Related

How can I build an .aar library with shrunk classes in Android Studio?

I want to build an .aar library and proguard classes, but my library proguard file doesn't work, and I can see clear classes.
Here is my proguard file:
android {
buildTypes {
release {
minifyEnabled true
useProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules-my-lib.pro'
}
}
}
and app/build.gradle:
android {
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
While you can probably shrink and obfuscate the library itself, the usual practice is to leave minifyEnabled as false and provide the proguard configuration to the application, using consumerProguardFiles instead of proguardFiles.
This means that the minification is applied only once, on the whole application, using the merged configuration from the app's proguardFiles and the libraries consumerProguardFiles. This is usually more efficient because parts of the libraries not actually used by the application can be removed.
Create a Android Studio Project and convert it to library Follow this link. Build and Execute the command Generate APK, .aar file will be created in release/debug folder.
Write the proguard rules as similar to APK, it will apply to .aar file also.
I hope this helps

How can I tell if I'm using Proguard to obfuscate my code?

I have an app that I migrated from Eclipse to Android-Studio. I want to make sure I'm using Proguard for my release version. I see in my build.gradle file this:
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
However, I don't have a proguard-android.txt or proguard-rules.txt in my project's folder. Is my code being obfuscated?
No, your code is not being obfuscated. You are not running proguard. minifyEnabled controls whether to run proguard, and you have it set to false, need to change that to true to turn on proguard. getDefaultProguardFile('proguard-android.txt') gets the default proguard rules from the SDK. See proguardFiles docs.
To check that your code is being obfuscated, you can look in your build/outputs/mapping/release directory. Those files should have modification times from during your build. Looking at the mapping.txt will give the obfuscation details (which names were mapped to what).
proguard-android.txt is system file .u need not to care.
'proguard-rules.txt is here . if u havent ,u can add a empty file. u can use ur custom name . But when minifyEnabled is true ,u need to add some line in it.

Where can I find project.properties in my project?

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.

Can't generate signed APK in Android Studio, because proguard-rules.txt is missing

I have a problem with generating signed APK in Android Studio. After fixing all the warnings I am stuck on this one:
Error:Execution failed for task ':app:proguardRelease'.
java.io.FileNotFoundException: /Users/franek/Documents/Android_Studio_Melange/app/proguard-rules.txt (No such file or directory)
I don't want to change minifyEnabled to false, because I want to keep Proguard working. How can I fix this error?
A fragment of build.gradle:
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt')
}
}
should work ok, as long as you don't need any special ProGuard configuration. If you do, use your original proguardFiles entry and create the file
/Users/franek/Documents/Android_Studio_Melange/app/proguard-rules.txt
Then put your custom rules in this file.
Delete folder build inside app folder, then regenerate.
You can try delete folder build inside app folder.
Then regenerate.
you need to disable the proguard
you can follow these steps: (to disable the proguard)
https://stackoverflow.com/a/72272882/10340870
it works for me. After disable the pro guards I'm able to generate the signed aab file
I realise this question has been long answered, but I had the same problem and have been trying for hours to fix it. None of the solutions on here worked for me, so I'm adding this to save others the trouble.
I solved the issue just by completely getting rid of the proguardFiles line, so my code looks like:
buildTypes {
release {
minifyEnabled true
}
}
Of course this doesn't help if you need a specific proguard file, but I thought I had to specify one and it turned out I didn't. I hope this helps!

Android Studio ProGuard does not appear to run

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.
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
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.
**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

Categories

Resources