0

我正在尝试运行 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())
        }
    }
}

这次崩溃的原因是什么?如何修复?

4

2 回答 2

0

按此顺序编辑构建路径:

确保/gen是之前/src

在此处输入图像描述

于 2020-11-23T18:38:24.323 回答
0

此外,您可以尝试执行以下步骤:

  1. 清洁项目
  2. 无效并重新启动

它也对我有用。

于 2020-11-23T21:09:23.640 回答