quarzoq

Well today I learn what is obfuscate or put another way... "how to make it difficult for people to read your source code". using proguard. and I want share with you how to do it.

Attention, this is a basic configuration to put the algorithm into operation, however, as you can read in the rules file, there are disabled sentences and omitted classes that can be activated later, but investigating and playing with it is up to you.



1) on Android studio put the project view, now go to the android folder and open "build.graddlefile".
now searh this line: "buildTypes {"
and set the code like:
buildTypes {
release {
shrinkResources true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}

}
shrinkResources activate the compress launcher and minifyEnabled the proguard Logic.

2) go to the desktop folder and open too the graddle.build and put this new task:
task obfuscate(type: proguard.gradle.ProGuardTask) {
dependsOn 'dist'
configuration files("proguard-project.txt")
libraryjars files("C:/Program Files/Java/jre1.8.0_231/lib/rt.jar", "C:/Program Files/Java/jre1.8.0_231/lib/jce.jar")
injars files("build/libs/desktop-1.0.jar")
outjars files("build/libs/obfuscated.jar")
}
here the important is the libraryjars , replace the "C:/Program Files/Java/jre1.8.0_231/lib" path with your jre version.

3) now in the desktopfolder, create a new file named: "proguard-project.txt"
this file are the compilation rules.

so put this code
-verbose
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-keepattributes Signature,InnerClasses,SourceFile,LineNumberTable

-dontwarn com.badlogic.**
-dontwarn org.lwjgl.**
-dontwarn org.objectweb.**
-dontwarn com.esotericsoftware.**

-keep class com.badlogic.**
-keep class org.lwjgl.**
-keep class org.objectweb.**
-keep class com.esotericsoftware.**

-keepclassmembers class com.badlogic.** { *; }
-keepclassmembers class org.lwjgl.** { *; }
-keepclassmembers class org.objectweb.** { *; }
-keepclassmembers class com.esotericsoftware.** { *; }

-keepclasseswithmembernames class * {
native <methods>;
}

-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keep public class com.mygdx.testspine.desktop.DesktopLauncher {
public static void main(java.lang.String[]);
}

-keep class com.mygdx.testspine.[i][i].[/i]$[/i]Style { *; }
-keep class com.mygdx.testspine.*[i].Kryo[/i]Serializer { *; }
the important here is remplace the lastets lines... com.mygdx.testspine with your own proyect path

if you see red warnings on code like the lines -keep class org.objectweb.** just ignore it, it is ok.

4) now on your android studio, open the android terminal. and write this commands:
gradlew desktop:dist

gradlew desktop:obfuscate
with the firts you compile your game in the normal way, it is necessary for create the obfuscate one. now bot jars are avalaible on your desktopfolder\build\libs.

I hope you have no problems in the process, greetings!
quarzoq
  • Сообщения: 19

Nate

Proguard is fine and doing it is better than not doing it, but note that everyone uses Proguard and it doesn't make it very much harder to read/modify your app.
Аватара пользователя
Nate

Nate
  • Сообщения: 10740

quarzoq

hehe I know, but atleast is a good resourse for try it :P
quarzoq
  • Сообщения: 19


Вернуться в Tutorials