java.lang.NoClassDefFoundError:无法解决以下问题:Lcom/mapbox/android/telemetry/MapboxTelemetry; [英] java.lang.NoClassDefFoundError: Failed resolution of: Lcom/mapbox/android/telemetry/MapboxTelemetry;
问题描述
我正在学习mapbox,并且已经按照kotlin跟随遵循mapbox来实现mapbox教程
I am learning mapbox and I have implemented mapbox with kotlin followed following mapbox tutorial
但是当我运行代码时,我在运行真实设备时遇到了异常
but when I run the code I am getting following exception when I run real device
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/mapbox/android/telemetry/MapboxTelemetry;
at com.mapbox.mapboxsdk.module.telemetry.TelemetryImpl.<init>(TelemetryImpl.java:30)
at com.mapbox.mapboxsdk.ModuleProviderImpl.obtainTelemetry(ModuleProviderImpl.java:22)
at com.mapbox.mapboxsdk.Mapbox.initializeTelemetry(Mapbox.java:167)
at com.mapbox.mapboxsdk.Mapbox.getInstance(Mapbox.java:64)
at com.example.myapplication.MainActivity.onCreate(MainActivity.kt:18)
at android.app.Activity.performCreate(Activity.java:7224)
at android.app.Activity.performCreate(Activity.java:7213)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1272)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2956)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3113)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:113)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:71)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1858)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:201)
at android.app.ActivityThread.main(ActivityThread.java:6820)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:922)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.mapbox.android.telemetry.MapboxTelemetry" on path: DexPathList[[zip file "/data/app/com.example.myapplication-85zEOZQGHEn-PrcXcL50yg==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.myapplication-85zEOZQGHEn-PrcXcL50yg==/lib/arm, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:171)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
我想知道导致异常的原因
I want to know what is causing the exception
我尝试过的操作我添加了以下mapbox proguard-rules
what I have tried I have added following mapbox proguard-rules
在我的proguard-rules.pro以下
below my proguard-rules.pro
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
-dontwarn com.mapbox.services.android.location.LostLocationEngine
-dontwarn com.mapbox.services.android.location.MockLocationEngine
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
低于build.gradle(:app)
below build.gradle(:app)
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 30
buildToolsVersion "30.0.2"
defaultConfig {
applicationId "com.example.myapplication"
minSdkVersion 14
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.1.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation project(':mapbox-android-sdk-9.5.0')
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
我想知道我到底在哪里犯了错误,任何暗示,建议和帮助对我们都有很大帮助!
I want to know where exactly I have made the mistake, any hints, suggestion, help greatly appriciated!
推荐答案
我认为,当您将mapbox添加为本地依赖项时,某些依赖项不包括在项目中,因此请添加以下代码行;解决了我的问题,当然会产生新的错误,但要消除遥测错误:
I think when you add mapbox as local dependency, some dependencies not include in project, so add this line of code; that solved my problem, of course produces new error, but remove telemetry error:
implementation 'com.mapbox.mapboxsdk:mapbox-android-telemetry:6.2.0'
这篇关于java.lang.NoClassDefFoundError:无法解决以下问题:Lcom/mapbox/android/telemetry/MapboxTelemetry;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!