我正在使用反射来调用我的 Android 应用程序的目标 API 级别之外的方法:
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) {
// ...
}
我可以通过 Proguard 毫无问题地优化它,但它警告我:
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').
这是一个实际问题,还是 Proguard 只是通知我一个潜在问题?