Reputation: 609
I have and Android app where various people test both development builds and release builds. The development builds are not obfuscated and I would like to be able to programatically determine at runtime if the application has been obfuscated or not.
Is there a way to do this?
Upvotes: 2
Views: 511
Reputation: 1521
Select a class which is always renamed by Proguard after obfuscation. Its name is ExampleClass.java
in the code below. Check its name in runtime with the following line:
ExampleClass.java
...
public static final boolean OBFUSCATED = !ExampleClass.class.toString().contains("ExampleClass");
That's all. No helper class or method is required and works without causing exceptions.
Upvotes: 0
Reputation: 80340
As @Sean proposed use a class which has no (external) dependencies.
But beware, ProGuard can detect the use of reflection, so you must somehow load class from string name, by not using a string literal (text resource maybe?): http://proguard.sourceforge.net/index.html#/FAQ.html%23forname
Upvotes: 1
Reputation: 66886
Here's one idea: add a class to your code base that is not used at all. Proguard will obfuscate and/or remove it. So, loading it via reflection in the app ought to cause ClassNotFoundException
if it's been run through ProGuard.
Upvotes: 2