michael
michael

Reputation: 3945

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,

Upvotes: 7

Views: 10715

Answers (1)

random
random

Reputation: 10309

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** {*;}

Upvotes: 24

Related Questions