Android java.lang.NoSuchMethodError: No virtual method ;or its super classes (declaration of

Android java.lang.NoSuchMethodError: No virtual method ;or its super classes (declaration of,第1张

修改 AOSP 源码后调用错误 java.lang.NoSuchMethodError: No virtual method *** in class *** ;or its super classes (declaration of ‘***’ appears in /system/framework/framework.jar!classes3.dex)

在 Android 10 AOSP 中自定了新的系统服务,在 app 中调用发现 java.lang.NoSuchMethodError: No virtual method 错误,详情如下:

2022-03-30 15:53:40.678 2046-2046/com.test.tempserviceclient E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.test.tempserviceclient, PID: 2046
    java.lang.NoSuchMethodError: No virtual method getValue()I in class Lcom/test/customservice/TestServiceManager; or its super classes (declaration of 'com.test.customservice.TestServiceManager' appears in /system/framework/framework.jar!classes3.dex)
        at com.test.tempserviceclient.MainActivity.onCreate(MainActivity.java:17)
        at android.app.Activity.performCreate(Activity.java:7853)
        at android.app.Activity.performCreate(Activity.java:7842)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1306)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7356)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)

经过各种搜索 ,查到两种解决方案

临时设置为可以调用 adb shell settings put global hidden_api_policy 1编辑 greylist,将需要设置的包名加入 greylist 中。在 frameworks/base/config/hiddenapi-greylist-packages.txt 中最后一行增加
***
org.apache.xpath
org.apache.xpath.axes
org.apache.xpath.compiler
org.apache.xpath.domapi
org.apache.xpath.functions
org.apache.xpath.jaxp
org.apache.xpath.objects
org.apache.xpath.operations
org.apache.xpath.patterns
org.apache.xpath.res
org.ccil.cowan.tagsoup
org.ccil.cowan.tagsoup.jaxp
+ com.test.customservice

原因是由于在 Android 10 中,针对非 SDK 接口进行了限制,默认是 blacklist 的,通过下面一个命令可以生成包含所有非 SDK 接口及其对应的名单

m out/soong/hiddenapi/hiddenapi-flags.csv

然后通过 vim out/soong/hiddenapi/hiddenapi-flags.csv打开改文件,发现 TestServiceManager 为 blacklist , 修复该问题,就用上述方案 (2)

Lcom/test/customservice/ITestService$Default;->()V,public-api,system-api,test-api,whitelist
Lcom/test/customservice/ITestService$Default;->asBinder()Landroid/os/IBinder;,public-api,system-api,test-api,whitelist
Lcom/test/customservice/ITestService$Default;->getBundle()Landroid/os/Bundle;,public-api,system-api,test-api,whitelist
Lcom/test/customservice/ITestService$Default;->getValue()I,public-api,system-api,test-api,whitelist
Lcom/test/customservice/ITestService$Default;->setBundle(Landroid/os/Bundle;)V,public-api,system-api,test-api,whitelist
Lcom/test/customservice/ITestService$Default;->setValue(I)V,public-api,system-api,test-api,whitelist
Lcom/test/customservice/ITestService$Stub$Proxy;->(Landroid/os/IBinder;)V,blacklist
Lcom/test/customservice/ITestService$Stub$Proxy;->asBinder()Landroid/os/IBinder;,public-api,system-api,test-api,whitelist
Lcom/test/customservice/ITestService$Stub$Proxy;->getBundle()Landroid/os/Bundle;,public-api,system-api,test-api,whitelist
Lcom/test/customservice/ITestService$Stub$Proxy;->getInterfaceDescriptor()Ljava/lang/String;,blacklist
Lcom/test/customservice/ITestService$Stub$Proxy;->getValue()I,public-api,system-api,test-api,whitelist
Lcom/test/customservice/ITestService$Stub$Proxy;->mRemote:Landroid/os/IBinder;,blacklist
Lcom/test/customservice/ITestService$Stub$Proxy;->sDefaultImpl:Lcom/test/customservice/ITestService;,blacklist
Lcom/test/customservice/ITestService$Stub$Proxy;->setBundle(Landroid/os/Bundle;)V,public-api,system-api,test-api,whitelist
Lcom/test/customservice/ITestService$Stub$Proxy;->setValue(I)V,public-api,system-api,test-api,whitelist
Lcom/test/customservice/ITestService$Stub;->()V,public-api,system-api,test-api,whitelist
Lcom/test/customservice/ITestService$Stub;->DESCRIPTOR:Ljava/lang/String;,blacklist
Lcom/test/customservice/ITestService$Stub;->TRANSACTION_getBundle:I,blacklist
Lcom/test/customservice/ITestService$Stub;->TRANSACTION_getValue:I,blacklist
Lcom/test/customservice/ITestService$Stub;->TRANSACTION_setBundle:I,blacklist
Lcom/test/customservice/ITestService$Stub;->TRANSACTION_setValue:I,blacklist
Lcom/test/customservice/ITestService$Stub;->asBinder()Landroid/os/IBinder;,public-api,system-api,test-api,whitelist
Lcom/test/customservice/ITestService$Stub;->asInterface(Landroid/os/IBinder;)Lcom/test/customservice/ITestService;,public-api,system-api,test-api,whitelist
Lcom/test/customservice/ITestService$Stub;->getDefaultImpl()Lcom/test/customservice/ITestService;,public-api,system-api,test-api,whitelist
Lcom/test/customservice/ITestService$Stub;->getDefaultTransactionName(I)Ljava/lang/String;,blacklist
Lcom/test/customservice/ITestService$Stub;->getTransactionName(I)Ljava/lang/String;,blacklist
Lcom/test/customservice/ITestService$Stub;->onTransact(ILandroid/os/Parcel;Landroid/os/Parcel;I)Z,public-api,system-api,test-api,whitelist
Lcom/test/customservice/ITestService$Stub;->setDefaultImpl(Lcom/test/customservice/ITestService;)Z,public-api,system-api,test-api,whitelist
Lcom/test/customservice/ITestService;->getBundle()Landroid/os/Bundle;,public-api,system-api,test-api,whitelist
Lcom/test/customservice/ITestService;->getValue()I,public-api,system-api,test-api,whitelist
Lcom/test/customservice/ITestService;->setBundle(Landroid/os/Bundle;)V,public-api,system-api,test-api,whitelist
Lcom/test/customservice/ITestService;->setValue(I)V,public-api,system-api,test-api,whitelist
Lcom/test/customservice/TestServiceManager;->(Landroid/content/Context;Lcom/test/customservice/ITestService;)V,blacklist
Lcom/test/customservice/TestServiceManager;->TAG:Ljava/lang/String;,blacklist
Lcom/test/customservice/TestServiceManager;->getBundle()Landroid/os/Bundle;,blacklist
Lcom/test/customservice/TestServiceManager;->getValue()I,blacklist
Lcom/test/customservice/TestServiceManager;->iTestService:Lcom/test/customservice/ITestService;,blacklist
Lcom/test/customservice/TestServiceManager;->setBundle(Landroid/os/Bundle;)V,blacklist
Lcom/test/customservice/TestServiceManager;->setValue(I)V,blacklist

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/992095.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-21
下一篇 2022-05-21

发表评论

登录后才能评论

评论列表(0条)

保存