Android-maps-utils: Adding the dependency causes ClassNotFoundException

Created on 2 Jun 2020  Â·  6Comments  Â·  Source: googlemaps/android-maps-utils

Hi all,

I was hoping to install the Maps Utils library to add dynamically labeled markers to my application. However, once I add the dependency to the gradle, my app no longer launches with the following issue:

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.android.wealthplus, PID: 1122
    java.lang.RuntimeException: Unable to instantiate application com.example.android.wealthplus.StarterApplication: java.lang.ClassNotFoundException: Didn't find class "com.example.android.wealthplus.StarterApplication" on path: DexPathList[[zip file "/data/app/com.example.android.wealthplus-zNbUEd4nyAlGM6K9qnuwxQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.android.wealthplus-zNbUEd4nyAlGM6K9qnuwxQ==/lib/arm64, /system/lib64, /product/lib64]]
        at android.app.LoadedApk.makeApplication(LoadedApk.java:1296)
        at android.app.ActivityThread.handleMakeApplication(ActivityThread.java:7007)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6989)
        at android.app.ActivityThread.access$1600(ActivityThread.java:272)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2055)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:237)
        at android.app.ActivityThread.main(ActivityThread.java:8016)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1076)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.android.wealthplus.StarterApplication" on path: DexPathList[[zip file "/data/app/com.example.android.wealthplus-zNbUEd4nyAlGM6K9qnuwxQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.android.wealthplus-zNbUEd4nyAlGM6K9qnuwxQ==/lib/arm64, /system/lib64, /product/lib64]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        at android.app.AppComponentFactory.instantiateApplication(AppComponentFactory.java:76)
        at android.app.Instrumentation.newApplication(Instrumentation.java:1156)
        at android.app.LoadedApk.makeApplication(LoadedApk.java:1288)
        at android.app.ActivityThread.handleMakeApplication(ActivityThread.java:7007) 
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6989) 
        at android.app.ActivityThread.access$1600(ActivityThread.java:272) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2055) 
        at android.os.Handler.dispatchMessage(Handler.java:107) 
        at android.os.Looper.loop(Looper.java:237) 
        at android.app.ActivityThread.main(ActivityThread.java:8016) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1076) 
        Suppressed: java.io.IOException: Failed to open dex files from /data/app/com.example.android.wealthplus-zNbUEd4nyAlGM6K9qnuwxQ==/base.apk because: Bad encoded_array value: Failure to verify dex file '/data/app/com.example.android.wealthplus-zNbUEd4nyAlGM6K9qnuwxQ==/base.apk': Bad encoded_value method type size 7
        at dalvik.system.DexFile.openDexFileNative(Native Method)
        at dalvik.system.DexFile.openDexFile(DexFile.java:365)
        at dalvik.system.DexFile.<init>(DexFile.java:107)
        at dalvik.system.DexFile.<init>(DexFile.java:80)
        at dalvik.system.DexPathList.loadDexFile(DexPathList.java:465)
        at dalvik.system.DexPathList.makeDexElements(DexPathList.java:424)
        at dalvik.system.DexPathList.<init>(DexPathList.java:164)
        at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:126)
        at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:101)
        at dalvik.system.PathClassLoader.<init>(PathClassLoader.java:74)
        at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:87)
        at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:116)
        at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:114)
        at android.app.ApplicationLoaders.getClassLoaderWithSharedLibraries(ApplicationLoaders.java:60)
        at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:892)
        at android.app.LoadedApk.getClassLoader(LoadedApk.java:991)
        at android.app.LoadedApk.getResources(LoadedApk.java:1248)
        at android.app.ContextImpl.createAppContext(ContextImpl.java:2618)
        at android.app.ContextImpl.createAppContext(ContextImpl.java:2610)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6882)
                ... 8 more

The Starter Application in my Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.example.android.wealthplus">

    <application
        android:name=".StarterApplication"
        android:allowBackup="true"
        android:hardwareAccelerated="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
        android:usesCleartextTraffic="true">
....

Here is my gradle with the Maps Utils implementation:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 29
    buildToolsVersion '28.0.3'

    defaultConfig {
        applicationId "com.example.android.wealthplus"
        minSdkVersion 26
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
        }
    }

}

repositories {
    mavenCentral()
}

ext {
    supportLibVersion = '28.0.0'  // variable that can be referenced to keep support libs consistent
    work_version = '2.3.2'
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'androidx.appcompat:appcompat:1.2.0-alpha02'

    implementation 'androidx.recyclerview:recyclerview:1.2.0-alpha01'
    implementation 'androidx.preference:preference:1.1.0'
    implementation 'androidx.cardview:cardview:1.0.0'

    implementation 'com.firebase:firebase-jobdispatcher:0.8.5'

    implementation 'androidx.appcompat:appcompat:1.2.0-alpha02'
    implementation 'com.google.android.material:material:1.2.0-alpha05'

    // Instrumentation dependencies use androidTestCompile
    // (as opposed to testCompile for local unit tests run in the JVM)
    implementation 'androidx.navigation:navigation-fragment:2.0.0'
    implementation 'androidx.navigation:navigation-ui:2.0.0'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.annotation:annotation:1.1.0'
    androidTestImplementation 'androidx.test:runner:1.3.0-alpha04'
    androidTestImplementation 'androidx.test:rules:1.3.0-alpha04'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta4'

    implementation 'com.github.lecho:hellocharts-library:1.5.8@aar'

    api 'org.jsoup:jsoup:1.10.1'

    implementation "androidx.work:work-runtime:${work_version}"

    implementation 'com.parse.bolts:bolts-tasks:1.4.0'
    implementation 'com.parse.bolts:bolts-applinks:1.4.0'
    implementation 'com.parse:parse-android:1.13.0'
    //implementation 'com.google.android.gms:play-services:9.4.0'
    implementation 'com.android.support:multidex:1.0.0'

    implementation 'com.opencsv:opencsv:5.1'

    implementation 'com.android.support:design:28.0.0'

    implementation 'com.google.android.gms:play-services:12.0.1'
    implementation 'com.androidmapsextensions:android-maps-extensions:2.4.0'

    implementation 'com.google.maps.android:android-maps-utils:1.3.3'
}

As soon as I remove the Maps Utils dependency, it all goes back to normal. Also, I am using Parse Server as a backend database.

Any ideas what the issue might be?

Thanks,

  • Alberto

Most helpful comment

@air89 Could you try adding the below compileOptions block to your build.gradle to support Java 8:

android {
  ...
  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }
  // Only if you're using Kotlin
  kotlinOptions {
    jvmTarget = "1.8"
  }
}

Android Maps Utils uses some Java 8 features now and if your app doesn't include this you can apparently see this issue:
https://stackoverflow.com/a/50983181/937715

All 6 comments

Based on the stack trace you shared this doesn't appear to be an issue with the android maps utils library but rather it could be an issue with multidexing. Are you able to confirm if that is the case?

Thanks for the quick response. I'm relatively new to Android development, so I am not sure how to check. Do you mind sharing how to check if multidexing is the issue?

Quick update: I added dependencies, and manifest and class modifications to ensure multidexing is enabled and am still receiving the same error.

@air89 Could you try adding the below compileOptions block to your build.gradle to support Java 8:

android {
  ...
  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }
  // Only if you're using Kotlin
  kotlinOptions {
    jvmTarget = "1.8"
  }
}

Android Maps Utils uses some Java 8 features now and if your app doesn't include this you can apparently see this issue:
https://stackoverflow.com/a/50983181/937715

@barbeau that did the trick, thanks!

Ok Now i will come in Meet My team Now

ในวันที่ พฤ. 4 มิ.ย. 2020 11:40 น. air89 notifications@github.com
เขียนว่า:

Closed #741 https://github.com/googlemaps/android-maps-utils/issues/741.

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/googlemaps/android-maps-utils/issues/741#event-3405013888,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/APX3IVTZDL4YLOPGGDXZNYLRU4QVRANCNFSM4NQHQH7Q
.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Ricardo1980 picture Ricardo1980  Â·  7Comments

TatyanaRTB picture TatyanaRTB  Â·  3Comments

dadino picture dadino  Â·  7Comments

SeijiIto picture SeijiIto  Â·  7Comments

harold-hernandez30 picture harold-hernandez30  Â·  3Comments