无法创建服务:Android中的Java.lang.ClassNotFoundException

jk9hmnmh  于 2023-05-21  发布在  Android
关注(0)|答案(1)|浏览(143)

我有一个使用SDK库发送数据的Android应用程序。我将SDK库打包为.aar文件,并在App中添加了依赖项。
我正在尝试在本地复制用户遇到的以下异常。

enter code here](Process: com.GA.injector, PID: 13175
04-23 22:49:14.900 2010093 13175 13175 E AndroidRuntime: java.lang.RuntimeException: Unable to create service com.java.android.GAService: java.lang.ClassNotFoundException: Didn't find class "com.java.android.GAService" on path: DexPathList[[zip file "/system/priv-app/Injector/Injector.apk"],nativeLibraryDirectories=[/system/priv-app/Injector/lib/x86_64, /system/lib64, /system/product/lib64, /system/lib64, /system/product/lib64]]
04-23 22:49:14.900 2010093 13175 13175 E AndroidRuntime: at android.app.ActivityThread.handleCreateService(ActivityThread.java:4198)
04-23 22:49:14.900 2010093 13175 13175 E AndroidRuntime: at android.app.ActivityThread.access$1500(ActivityThread.java:237)
04-23 22:49:14.900 2010093 13175 13175 E AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1932)
04-23 22:49:14.900 2010093 13175 13175 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:106)
04-23 22:49:14.900 2010093 13175 13175 E AndroidRuntime: at android.os.Looper.loop(Looper.java:223)
04-23 22:49:14.900 2010093 13175 13175 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:7664)
04-23 22:49:14.900 2010093 13175 13175 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
04-23 22:49:14.900 2010093 13175 13175 E AndroidRuntime: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
04-23 22:49:14.900 2010093 13175 13175 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
04-23 22:49:14.900 2010093 13175 13175 E AndroidRuntime: Caused by: java.lang.ClassNotFoundException: Didn't find class "com.java.android.GAService" on path: DexPathList[[zip file "/system/priv-app/Injector/Injector.apk"],nativeLibraryDirectories=[/system/priv-app/Injector/lib/x86_64, /system/lib64, /system/product/lib64, /system/lib64, /system/product/lib64]]
04-23 22:49:14.900 2010093 13175 13175 E AndroidRuntime: at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:207)
04-23 22:49:14.900 2010093 13175 13175 E AndroidRuntime: at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
04-23 22:49:14.900 2010093 13175 13175 E AndroidRuntime: at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
04-23 22:49:14.900 2010093 13175 13175 E AndroidRuntime: at android.app.AppComponentFactory.instantiateService(AppComponentFactory.java:129)
04-23 22:49:14.900 2010093 13175 13175 E AndroidRuntime: at androidx.core.app.CoreComponentFactory.instantiateService(CoreComponentFactory.java:75)
04-23 22:49:14.900 2010093 13175 13175 E AndroidRuntime: at android.app.ActivityThread.handleCreateService(ActivityThread.java:4177))

GAService是SDK库的manifest文件中添加的服务。此问题在用户端似乎是间歇性的。
在什么情况下会发生此异常?我在重现这个问题时遇到了麻烦。

eqoofvh9

eqoofvh91#

com.java.android.GAService到底是什么?一些自定义本机库提供的.so文件?
根据我的经验,不同版本的Android有不同的行为。在某些版本上,本机库是自动加载的,在某些版本上,您需要显式加载它们。
在使用此GAService之前,请尝试添加与您的代码类似的内容-假设文件为libgaservice.so:

System.loadLibrary("gaservice");

相关问题