Refer to the second point here(Encrypt Class Files) How to make apk Secure. Protecting from Decompile how can i encrypt and decrypt class file in Android?
-
2You cannot. You can obfuscate it, there are different tools which allows you to do that (ProGuard is one of them) – BackSlash Feb 08 '17 at 10:58
3 Answers
You can obfuscate code with proguard (free) and dexgaurd (enterprise)
in your app gradle:
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFile 'proguard-google-play-services.pro'
proguardFile 'proguard-butter-knife.pro'
proguardFile 'proguard-volley.pro'
}
debug {
minifyEnabled false
}
}
with this code in release mode your code obfuscate.
some files must not obfuscate so you can create some files in root of app folders and on that you can set which file must not obfuscate
volley files for example:
-keep class com.android.volley.** {*;}
-keep class com.android.volley.toolbox.** {*;}
-keep class com.android.volley.Response$* { *; }
-keep class com.android.volley.Request$* { *; }
-keep class com.android.volley.RequestQueue$* { *; }
-keep class com.android.volley.toolbox.HurlStack$* { *; }
-keep class com.android.volley.toolbox.ImageLoader$* { *; }
usually in libraries readme they write what you have to write for prevent obfuscating for some classes. also consider you can only make it harder but not impossible.

- 1,852
- 3
- 22
- 38
Code Signing is one option to make your apk file secure. It ensures the authenticity and integrity of your source code. You may go through the below link for more details
Now coming to your question on protecting the apk file from de-compiling, it is not possible completely but you can still use some preventive measures to make it tough. Please go through below link
-
Signing the APK doesn't prevent decompiling it, which is what the OP is looking for. – BackSlash Feb 08 '17 at 11:03
-
My point was more towards securing the apk file which was the part of original question. And yeah as you said it won't stop from de-compiling the apk file anyway – Sravya Feb 08 '17 at 11:10
-
The OP said "secure", but specified that he wants to encrypt and decrypt class files to prevent decompiling: this answer does not answer the question. – BackSlash Feb 08 '17 at 11:11
You can try this tool if you want a higher level for obfuscation: Bg+ Anti Decompiler/Obfuscator

- 39
- 2