Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android ProGuard obfuscation of library: keep class not working

Intro: I have in AS 1 project with 2 models:

  1. Android library project with some "Public API class"
  2. Android APP dependent on above library (the library module is on the dependency list)

Task: I want to obfuscate my library project because I want to expose it as public SDK but keep my code protected...

What I did: So I made custom ProGuard rules:

-dontshrink
-dontoptimize
-dontpreverify
-keep class com.org.my_public_api_class_name

I skip all other stages in order to eliminate where the bug is to only obfuscation stage.

Result: Build of the APP module fails with errors like

Error: cannot find symbol class my_public_api_class_name

It seems for me that the problem is that the obfuscation NOT skipped the class I wanted to, so now he has some meaningless name and therefore in the APP, where I'm using him, The original name not exist.

Thanks,

like image 276
michael Avatar asked Nov 11 '15 10:11

michael


1 Answers

To exclude your class from obfuscation, try this:

 -keep class com.org.my_public_api_class_name**
 -keepclassmembers class com.org.my_public_api_class_name** {*;}
like image 190
random Avatar answered Nov 15 '22 04:11

random