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

问题描述 投票:0回答:1

我有一个使用 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文件中添加的服务。 这个问题在用户端似乎是间歇性的。

在什么场景下,会出现这个异常?我无法重现问题。

android android-manifest classnotfoundexception android-service-binding
1个回答
0
投票

这到底是什么

com.java.android.GAService
?作为 .so 文件提供的一些自定义本机库?

根据我的经验,不同版本的 Android 会有不同的行为。在某些版本上,本机库会自动加载,而在某些版本上,您需要显式加载它们。

在使用此 GAService 之前尝试添加与您的代码类似的内容 - 假设文件为 libgaservice.so:

System.loadLibrary("gaservice");
© www.soinside.com 2019 - 2024. All rights reserved.