我正在尝试运行 GnssAntennaInfo。在模拟器上一切正常。在真实设备(sdk 27)上测试时,应用程序崩溃并出现以下错误:
2020-11-23 10:57:59.470 1203-1203/com.example.axpapp E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.axpapp, PID: 1203
java.lang.NoClassDefFoundError: Failed resolution of: Landroid/location/GnssAntennaInfo;
at com.example.axpapp.GNSSTests.getAntennaInfo(GNSSTests.kt:8)
at com.example.axpapp.GNSSTests$Companion.printAntennaInfo(GNSSTests.kt:15)
at com.example.axpapp.MainActivity.onCreate(MainActivity.kt:11)
at android.app.Activity.performCreate(Activity.java:7258)
at android.app.Activity.performCreate(Activity.java:7249)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1222)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2927)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3059)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1724)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:7000)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:441)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408)
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.location.GnssAntennaInfo" on path: DexPathList[[zip file "/data/app/com.example.axpapp-q_DcCIhOmXK9bQRnVIC0NA==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.axpapp-q_DcCIhOmXK9bQRnVIC0NA==/lib/arm, /system/lib, /system/vendor/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at com.example.axpapp.GNSSTests.getAntennaInfo(GNSSTests.kt:8)
at com.example.axpapp.GNSSTests$Companion.printAntennaInfo(GNSSTests.kt:15)
at com.example.axpapp.MainActivity.onCreate(MainActivity.kt:11)
at android.app.Activity.performCreate(Activity.java:7258)
at android.app.Activity.performCreate(Activity.java:7249)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1222)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2927)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3059)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1724)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:7000)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:441)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1408)
GNSSTest.kt 如下:
package com.example.axpapp
import android.location.GnssAntennaInfo
class GNSSTests {
fun getAntennaInfo(): String {
val antenna = GnssAntennaInfo.CREATOR
return antenna.toString()
}
companion object {
fun printAntennaInfo(){
println(GNSSTests().getAntennaInfo())
}
}
}
这次崩溃的原因是什么?如何修复?