我正在尝试将mapbox导航集成在我的Android应用中,当我尝试在手机上运行代码时,我会收到此错误。
奇怪的是,如果我在模拟器上运行它,它可以毫无问题...
我已经尝试过Google这个错误,但是我找不到任何可以帮助我的答案。
我得到的错误是以下
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
和graddle文件如下:
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/
我相信您遇到了一个已知问题,该问题在Android Navigation SDK的开源回购上被标记为:https://github.com/mapbox/mapbox/mapbox/mapbox-navigation-and-yavigation-and-android-and android/eskay/1982#issuecomment-505955023
从开发团队的响应中复制/粘贴:
此问题是特别引起的,因为Mapbox Maps SDK中包含的事件版本不包括导航事件。MAPS V8.1.0 MAPBOX/MAPBOX-GL-NATICATE#14874(任何先前的版本工作👌(。我们正在跟踪#1890
中导航SDK一侧所需的工作可以在此期间进行的解决方法,该解决方案不包括MAPS SDK的事件依赖关系,以便使用导航SDK的事件v4.4.1👀
implementation('com.mapbox.mapboxsdk:mapbox-android-sdk:8.1.0') { exclude group: 'com.mapbox.mapboxsdk', module: 'mapbox-android-telemetry' }
我遇到了完全相同的问题,可以通过以下内容解决它:
我从build.gradle文件中删除了任何androidTestimplectation和sistimpletation,我也必须更改任何android.support ... boldernaintlayout ... conderaintlayout to androidx.constraintlayout.widget.widget.constraint.constraint.constraint.constraintlayout
>希望这也会对您有所帮助。
编辑:
我启动了另一个项目,然后再次遇到了同样的问题。我不得不添加
compileOptions {
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
}
到我的模块build.gradle文件。
实际上,如果您使用的是navigationui sdk,则不需要使用mapbox sdk,因为它已经包含在navigationui sdk中。遥测/导航级课程。
但是,github resolvi的瓜迪奥拉31337答案的答案帮助我了解了我的问题,好吧,我只是通过删除Mapbox SDK实施仅保留导航的部分而给了它,这对我来说有用,也许Mapbox SDK的存在是由于出现错误而造成某种冲突。