Proguard: keeping dynamically declared methods
android, proguard
Solution
The problem resided in a library project that I was using, and the `proguard.cfg` from that project wasn't being inspected by Proguard.
By adding the following lines to my own projects `proguard.cfg`, I was able to make the notice disappear:
-keep class android.content.Context {
public java.io.File getExternalCacheDir();
}
Problem
I'm using reflection to call a method that is outside of the target API level of my Android application: ``` try { Method m = Class.forName("android.content.Context") .getDeclaredMethod("getExternalCacheDir"); Object result = m.invoke(this); if (result instanceof File) { Log.v("MyApp", "external cache: " + ((File) result).getAbsolutePath()); cacheDirectory = (File) result; } else { Log.v("MyApp", "non-file cache: " + result); } } catch (Exception e) { // ... } ``` I can optimize this without any problems through Proguard, but it warns me: ``` Note: com.example.MyApp accesses a declared method 'getExternalCacheDir()' dynamically Maybe this is library method 'android.content.Context { java.io.File getExternalCacheDir(); }' Maybe this is library method 'android.content.ContextWrapper { java.io.File getExternalCacheDir(); }' Maybe this is library method 'android.test.mock.MockContext { java.io.File getExternalCacheDir(); }' Note: there were 1 accesses to class members by means of introspection. You should consider explicitly keeping the mentioned class members (using '-keep' or '-keepclassmembers'). ``` Is this an actual problem, or is Proguard just informing me of a potential problem?