如何解决:“ java.lang.RuntimeException:无法获取提供者com.mapbox.android.telemetry.provider.MapboxTelemetryInitProvider

时间:2019-05-08 15:36:18

标签: java android gradle mapbox

我试图在我的android应用程序中集成mapbox导航,当我试图在手机上运行代码进行测试时,出现此错误。

奇怪的是,如果我在模拟器上运行它,就可以毫无问题...

我已经尝试过搜索此错误,但是我找不到任何可以帮助我的答案。

我得到的错误如下

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: upt.cti.com.testapp, PID: 20632
    java.lang.RuntimeException: Unable to get provider com.mapbox.android.telemetry.provider.MapboxTelemetryInitProvider: java.lang.ClassNotFoundException: Didn't find class "com.mapbox.android.telemetry.provider.MapboxTelemetryInitProvider" on path: DexPathList[[zip file "/data/app/upt.cti.com.testapp-W7F_WF7ciClLNb_MtYNj9g==/base.apk"],nativeLibraryDirectories=[/data/app/upt.cti.com.testapp-W7F_WF7ciClLNb_MtYNj9g==/lib/arm64, /data/app/upt.cti.com.testapp-W7F_WF7ciClLNb_MtYNj9g==/base.apk!/lib/arm64-v8a, /system/lib64, /vendor/lib64, /product/lib64]]
        at android.app.ActivityThread.installProvider(ActivityThread.java:7215)
        at android.app.ActivityThread.installContentProviders(ActivityThread.java:6699)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6600)
        at android.app.ActivityThread.-wrap2(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
        at android.os.Handler.dispatchMessage(Handler.java:108)
        at android.os.Looper.loop(Looper.java:166)
        at android.app.ActivityThread.main(ActivityThread.java:7529)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "com.mapbox.android.telemetry.provider.MapboxTelemetryInitProvider" on path: DexPathList[[zip file "/data/app/upt.cti.com.testapp-W7F_WF7ciClLNb_MtYNj9g==/base.apk"],nativeLibraryDirectories=[/data/app/upt.cti.com.testapp-W7F_WF7ciClLNb_MtYNj9g==/lib/arm64, /data/app/upt.cti.com.testapp-W7F_WF7ciClLNb_MtYNj9g==/base.apk!/lib/arm64-v8a, /system/lib64, /vendor/lib64, /product/lib64]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:93)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        at android.app.ActivityThread.installProvider(ActivityThread.java:7200)
        at android.app.ActivityThread.installContentProviders(ActivityThread.java:6699) 
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6600) 
        at android.app.ActivityThread.-wrap2(Unknown Source:0) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066) 
        at android.os.Handler.dispatchMessage(Handler.java:108) 
        at android.os.Looper.loop(Looper.java:166) 
        at android.app.ActivityThread.main(ActivityThread.java:7529) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921) 
        Suppressed: java.io.IOException: Failed to open dex files from /data/app/upt.cti.com.testapp-W7F_WF7ciClLNb_MtYNj9g==/base.apk because: Failure to verify dex file '/data/app/upt.cti.com.testapp-W7F_WF7ciClLNb_MtYNj9g==/base.apk': Bad method handle type 7
        at dalvik.system.DexFile.openDexFileNative(Native Method)
        at dalvik.system.DexFile.openDexFile(DexFile.java:353)
        at dalvik.system.DexFile.<init>(DexFile.java:100)
        at dalvik.system.DexFile.<init>(DexFile.java:74)
        at dalvik.system.DexPathList.loadDexFile(DexPathList.java:374)
        at dalvik.system.DexPathList.makeDexElements(DexPathList.java:337)
        at dalvik.system.DexPathList.<init>(DexPathList.java:157)
        at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:65)
        at dalvik.system.PathClassLoader.<init>(PathClassLoader.java:64)
        at com.android.internal.os.PathClassLoaderFactory.createClassLoader(PathClassLoaderFactory.java:43)
        at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:75)
        at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:38)
        at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:719)
        at android.app.LoadedApk.getClassLoader(LoadedApk.java:752)
        at android.app.LoadedApk.getResources(LoadedApk.java:1005)
        at android.app.ContextImpl.createAppContext(ContextImpl.java:2489)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6497)
                ... 8 more

和gradle文件如下:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "upt.cti.com.testapp"
        minSdkVersion 26
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

repositories {
    mavenCentral()
    maven { url 'https://mapbox.bintray.com/mapbox' }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:support-v4:28.0.0'
    implementation 'com.android.support:support-media-compat:28.0.0'
    implementation 'com.android.support:exifinterface:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:7.3.2'
    implementation 'com.mapbox.mapboxsdk:mapbox-android-navigation-ui:0.37.0'
}

我正在尝试按照本教程创建自己的导航应用程序,但是我一直在寻求指导。

https://docs.mapbox.com/help/tutorials/android-navigation-sdk/

3 个答案:

答案 0 :(得分:1)

我认为您遇到了一个已知问题,该问题已在Android导航SDK的开放源代码仓库中标记为:https://github.com/mapbox/mapbox-navigation-android/issues/1982#issuecomment-505955023

从开发团队的答复中复制/粘贴:

  

此问题具体是由于Mapbox Maps SDK中包含的事件版本不包含导航事件?mapbox/mapbox-events-android#383-事件v4.5.0和事件v4.5.1包含在Maps v8.1.0中而导致的mapbox/mapbox-gl-native#14874(任何以前的版本都适用?)。我们正在#1890

中跟踪Navigation SDK方面所需的工作。      

在此期间,可以采取一种解决方法,即排除Maps SDK中的事件依赖关系,以便使用Navigation SDK中的Events v4.4.1?

implementation('com.mapbox.mapboxsdk:mapbox-android-sdk:8.1.0') {
  exclude group: 'com.mapbox.mapboxsdk', module: 'mapbox-android-telemetry'
}

答案 1 :(得分:0)

实际上,如果您使用的是NavigationUi SDK,则不需要使用Mapbox SDK,因为它已经包含在NavigationUi SDK中。实际上,我遇到了同样的问题,即缺少Telemetry / NavigationMetaData类。

但是answer from Guardiola31337 in Github resolvi的答案帮助我理解了我的问题,好吧,我只是删除了mapbox sdk的实现,只保留了NavigationUi部分,这对我有用,也许是因为创建了mapbox sdk由于这种错误而引起的某种冲突。

答案 2 :(得分:-1)

我遇到了完全相同的问题,可以通过以下操作解决此问题:

我从build.gradle文件中删除了任何androidTestImplementation和testImplementation,而且我还不得不将所有android.support ... ConstraintLayout更改为androidx.constraintlayout.widget.ConstraintLayout

希望这对您有所帮助。

编辑:

我启动了另一个项目,并再次遇到相同的问题。我必须添加

    compileOptions {
    sourceCompatibility = '1.8'
    targetCompatibility = '1.8'
}

到我的模块build.gradle文件。