如果在Android9.0亦即API-28或以上的系统中运行debug app时,出现如下警告弹窗:
Detected problems with API compatibility(visit g.co/dev/appcompat for more info)
说明在代码中有通过反射调用含有@hide注解的方法或属性的逻辑,亦即调用系统隐藏API的逻辑。而从Android9.0开始,系统将限制这种调用方式,而弹出警告弹窗。
而要隐藏这个警告弹窗,有3种方案:
1.修改build.gradle文件,将targetSdkVersion修改为28或以上。
2.采用反射的方法关闭弹窗,在Application中执行一下如下方法即可。
* Android 9开始限制开发者调用非官方API方法和接口(即用反射直接调用源码)
* 弹框提示 Detected problems with API compatibility(visit g.co/dev/appcompat for more info)
* 隐藏警告弹框
private void closeDetectedProblemApiDialog() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) {
return;
try {
@SuppressLint("PrivateApi") Class clsPkgParser = Class.forName("android.content.pm.PackageParser$Package");
Constructor constructor = clsPkgParser.getDeclaredConstructor(String.class);
constructor.setAccessible(true);
@SuppressLint("PrivateApi") Class clsActivityThread = Class.forName("android.app.ActivityThread");
Method method = clsActivityThread.getDeclaredMethod("currentActivityThread");
method.setAccessible(true);
Object activityThread = method.invoke(null);
Field hiddenApiWarning = clsActivityThread.getDeclaredField("mHiddenApiWarningShown");
hiddenApiWarning.setAccessible(true);
hiddenApiWarning.setBoolean(activityThread, true);
} catch (Exception e) {
e.printStackTrace();
3.查看代码中调用了哪些系统隐藏API,看可否将这些逻辑改成其他方式实现。
调用了系统隐藏API的时候,都会有类似Accessing hidden field或Accessing hidden method的打印。比如如下几个:
W/com.test.hm: Accessing hidden field Landroid/os/Message;->next:Landroid/os/Message; (light greylist, reflection)
W/com.test.hm: Accessing hidden method Ldalvik/system/CloseGuard;->get()Ldalvik/system/CloseGuard; (light greylist, reflection)
W/com.test.hm: Accessing hidden method Ldalvik/system/CloseGuard;->open(Ljava/lang/String;)V (light greylist, reflection)
W/com.test.hm: Accessing hidden method Ldalvik/system/CloseGuard;->warnIfOpen()V (light greylist, reflection)
W/com.test.hm: Accessing hidden method Lcom/android/org/conscrypt/OpenSSLSocketImpl;->setAlpnProtocols([B)V (light greylist, reflection)
W/com.test.hm: Accessing hidden field Landroid/content/ContentResolver;->mTargetSdkVersion:I (dark greylist, reflection)
当然以上方法调用,可能不太容易找到其他实现的方式,如果真的找不到,那也没办法。
如果在Android9.0亦即API-28或以上的系统中运行debug app时,出现如下警告弹窗:Detected problems with API compatibility(visit g.co/dev/appcompat for more info)说明在代码中有通过反射调用含有@hide注解的方法或属性的逻辑,亦即调用系统隐藏API的逻辑。而从Android9.0开始,系统将限制这种调用方式,而弹出警告弹窗。而要隐藏这个警告弹窗,有3种方案:1.修改build.gradle文件,将ta
A direct prejudgement strategy that takes the diffraction ring as the analysis target is put forward to pr
ed
ict hot images induc
ed
by defects of tens of microns in the main amplifier section of high power laser systems. Analysis of hot-image formation process shows that the hot image can be precisely calculat
ed
with the extract
ed
intensity oscillation of the diffraction ring on the front surface of the nonlinear plate. The gradient direction matching (GDM) method is adopt
ed
to
detect
diffraction
在我的手机升级为android9的时候,通过屎丢丢安装程序就会出现提示:
Detect
ed
problem
s with
API
compatibility
究其原因:说的是开发者可能通过 Java 反射、JNI 等来调用 Android 系统内部使用、并未提供在 SDK 中的接口,为了安全考虑,每次打开应用我都要告诉你,这么做是不行的。
然后大神们写了各种
隐藏
的方法,我是写不出来了。
解决方法:修改...
Android P 后谷歌限制了开发者调用非官方公开
API
方法或接口,也就是说,你用反射直接调用源码就会有这样的提示
弹窗
出现,非 SDK 接口指的是 Android 系统内部使用、并未提供在 SDK 中的接口,开发者可能通过 Java 反射、JNI 等技术来调用这些接口。但是,这么做是很危险的:非 SDK 接口没有任何公开文档,必须查看源代码才能理解其行为逻辑。
但是源码是JAVA写的,万物皆可...