在Android手机上部署应用程序时找不到java.time.LocalDateTime的类

问题描述

如此处所述,该java.time程序包在API 26(Android O)及更高版本中可用。

解决方法

我在Android手机上部署Android应用程序时遇到ClassNotFoundException。

我尝试在具有Android 6.0.1和Android 7.1.1的android手机上

而当我在(Nexus 5X API 26)并运行Android 8.0的模拟器上部署相同的应用程序时,我不会遇到任何问题。该应用程序加载平稳。

Build.gradle(应用程序)文件具有

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "de.pfiva.mobile.voiceassistant"
        minSdkVersion 23
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro'
        }
    }
}

我包括了本地专家的依赖。这种依赖关系基本上具有普通的Java类(POJO)。在某些类中,存在类型为java.time.LocalDateTime的字段

我该如何解决这个问题。寻找建议。

谢谢。

例外情况:

E/AndroidRuntime: FATAL EXCEPTION: main
                  Process: de.pfiva.mobile.voiceassistant,PID: 25245
                  java.lang.NoClassDefFoundError: Failed resolution of: Ljava/time/LocalDateTime;
                      at java.lang.Class.getDeclaredFields(Native Method)
                      at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:150)
                      at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:100)
                      at com.google.gson.Gson.getAdapter(Gson.java:423)
                      at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:115)
                      at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:164)
                      at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:100)
                      at com.google.gson.Gson.getAdapter(Gson.java:423)
                      at com.google.gson.internal.bind.CollectionTypeAdapterFactory.create(CollectionTypeAdapterFactory.java:53)
                      at com.google.gson.Gson.getAdapter(Gson.java:423)
                      at retrofit2.converter.gson.GsonConverterFactory.responseBodyConverter(GsonConverterFactory.java:64)
                      at retrofit2.Retrofit.nextResponseBodyConverter(Retrofit.java:330)
                      at retrofit2.Retrofit.responseBodyConverter(Retrofit.java:313)
                      at retrofit2.ServiceMethod$Builder.createResponseConverter(ServiceMethod.java:739)
                      at retrofit2.ServiceMethod$Builder.build(ServiceMethod.java:172)
                      at retrofit2.Retrofit.loadServiceMethod(Retrofit.java:170)
                      at retrofit2.Retrofit$1.invoke(Retrofit.java:147)
                      at java.lang.reflect.Proxy.invoke(Proxy.java:813)
                      at $Proxy0.getNLUData(Unknown Source)
                      at de.pfiva.mobile.voiceassistant.activities.MainActivity.onCreate(MainActivity.java:41)
                      at android.app.Activity.performCreate(Activity.java:6826)
                      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1121)
                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2656)
                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2764)
                      at android.app.ActivityThread.-wrap12(ActivityThread.java)
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1502)
                      at android.os.Handler.dispatchMessage(Handler.java:102)
                      at android.os.Looper.loop(Looper.java:154)
                      at android.app.ActivityThread.main(ActivityThread.java:6173)
                      at java.lang.reflect.Method.invoke(Native Method)
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:933)
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
                   Caused by: java.lang.ClassNotFoundException: Didn't find class "java.time.LocalDateTime" on path: DexPathList[[zip file "/data/app/de.pfiva.mobile.voiceassistant-1/base.apk",zip file "/data/app/de.pfiva.mobile.voiceassistant-1/split_lib_dependencies_apk.apk",zip file "/data/app/de.pfiva.mobile.voiceassistant-1/split_lib_slice_0_apk.apk",zip file "/data/app/de.pfiva.mobile.voiceassistant-1/split_lib_slice_1_apk.apk",zip file "/data/app/de.pfiva.mobile.voiceassistant-1/split_lib_slice_2_apk.apk",zip file "/data/app/de.pfiva.mobile.voiceassistant-1/split_lib_slice_3_apk.apk",zip file "/data/app/de.pfiva.mobile.voiceassistant-1/split_lib_slice_4_apk.apk",zip file "/data/app/de.pfiva.mobile.voiceassistant-1/split_lib_slice_5_apk.apk",zip file "/data/app/de.pfiva.mobile.voiceassistant-1/split_lib_slice_6_apk.apk",zip file "/data/app/de.pfiva.mobile.voiceassistant-1/split_lib_slice_7_apk.apk",zip file "/data/app/de.pfiva.mobile.voiceassistant-1/split_lib_slice_8_apk.apk",zip file "/data/app/de.pfiva.mobile.voiceassistant-1/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/de.pfiva.mobile.voiceassistant-1/lib/arm64,/system/lib64,/vendor/lib64]]
                      at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
                      at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
                      at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
                      at java.lang.Class.getDeclaredFields(Native Method) 
                      at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:150) 
                      at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:100) 
                      at com.google.gson.Gson.getAdapter(Gson.java:423) 
                      at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.createBoundField(ReflectiveTypeAdapterFactory.java:115) 
                      at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:164) 
                      at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:100) 
                      at com.google.gson.Gson.getAdapter(Gson.java:423) 
                      at com.google.gson.internal.bind.CollectionTypeAdapterFactory.create(CollectionTypeAdapterFactory.java:53) 
                      at com.google.gson.Gson.getAdapter(Gson.java:423) 
                      at retrofit2.converter.gson.GsonConverterFactory.responseBodyConverter(GsonConverterFactory.java:64) 
                      at retrofit2.Retrofit.nextResponseBodyConverter(Retrofit.java:330) 
                      at retrofit2.Retrofit.responseBodyConverter(Retrofit.java:313) 
                      at retrofit2.ServiceMethod$Builder.createResponseConverter(ServiceMethod.java:739) 
                      at retrofit2.ServiceMethod$Builder.build(ServiceMethod.java:172) 
                      at retrofit2.Retrofit.loadServiceMethod(Retrofit.java:170) 
                      at retrofit2.Retrofit$1.invoke(Retrofit.java:147) 
                      at java.lang.reflect.Proxy.invoke(Proxy.java:813) 
                      at $Proxy0.getNLUData(Unknown Source) 
                      at de.pfiva.mobile.voiceassistant.activities.MainActivity.onCreate(MainActivity.java:41) 
                      at android.app.Activity.performCreate(Activity.java:6826) 
                      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1121) 
                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2656) 
                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2764) 
                      at android.app.ActivityThread.-wrap12(ActivityThread.java) 
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1502) 
                      at android.os.Handler.dispatchMessage(Handler.java:102) 
                      at android.os.Looper.loop(Looper.java:154) 
                      at android.app.ActivityThread.main(ActivityThread.java:6173) 
                      at java.lang.reflect.Method.invoke(Native Method) 
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:933) 
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)

猜你在找的技术问答相关文章

如何检查配对的蓝牙设备是打印机还是扫描仪(Android)
是否允许实体正文进行HTTP DELETE请求?
如何将ZipInputStream转换为InputStream?
java.util.logging Java 8中的变量
PowerMockito.doReturn返回null
Java中的RESTful调用
Swing / Java:如何正确使用getText和setText字符串
特殊字符和重音字符
Android Studio中的ndk.dir错误
错误“找不到主类”