Recently, using a new mobile phone to test, there are frequent ANRs, and each loading is very slow. Every time the loading is slow, the following code will appear:
After understanding, Android 9 introduces restrictions on the use of non-SDK interfaces, whether they are used directly or indirectly through reflection or JNI. This means that when manipulating a class through semantics such as reflection, you should not access functions or fields that are not listed in the SDK (there are usually @hide
flags).
The meanings of blacklist, greylist, greylist-max-o, and greylist-max-p are as follows:
- blacklist Blacklist: Prohibited non-SDK interfaces, crash directly at runtime (so must be resolved)
- greylist greylist: the non-SDK interface that can still be used in the current version, but may become a restricted non-SDK interface in the next version
- greylist-max-o: A non-SDK interface that can be used in targetSDK<=O, but is prohibited in targetSDK>=P
- greylist-max-p: non-SDK interfaces that can be used in targetSDK<=P, but are prohibited in targetSDK>=Q
1. Non-SDK interface
Official document: Restrictions for non-SDK interfaces
Officially, starting from Android 9 (API level 28), restrictions have been imposed on the non-SDK interfaces used by apps.
These restrictions come into play if your app passes references 非 SDK 接口
or tries 使用反射或 JNI 来获取句柄
. The official explanation is for 提升用户体验、降低应用崩溃
risk.
1.1. Non-SDK interface detection tool
The official has given a detection tool, download address
Google official veridex download:
https://android.googlesource.com/platform/prebuilts/runtime/+/master/appcompat
Android veridex non-SDK interface detection tool
How to use veridex:
./appcompat.sh --dex-file=文件名.apk --imprecise
The file name is veridex.gz, just decompress it directly. After decompression
Because my development environment is mac. So zip the veridex-mac.zip file, and copy the apk into it.
Open the terminal, cd to the current directory, and execute it.
appcompat.sh --dex-file=apk.apk
./appcompat.sh --dex-file=文件名.apk --imprecise
Supplement, both commands work. It's just --imprecise
parameters, you can see more detailed information.
Copy the command line information, and check the code that needs to be modified according to the registration.
Finished - call it a day - sprinkle flowers...