简体   繁体   中英

Android studio dalvik vm unable to find class

I am trying to figure out how to fix an error with a legacy android project that I have ported over to android studio. I'm hoping this is more an issue with my build.gradle scripts. The class library works properly when coding, complete with completion and such.

I've tried closing android studio, running gradlew clean, then reopening it in android studio and that didn't work.

Here is my settings.gradle script.

include ':app', ':imageloader-core-1.6.1'

Here is my project build.gradle script.

buildscript {
    repositories {
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.0.0'
        classpath 'jp.leafytree.gradle:gradle-android-scala-plugin:1.3.1'
    }
}

allprojects {
    repositories {
        jcenter()
        mavenCentral()
    }
}

Here is my app build.gradle script.

apply plugin: 'com.android.application'
apply plugin: 'jp.leafytree.android-scala'

android {
    compileSdkVersion 19
    buildToolsVersion "21.1.1"

    defaultConfig {
        applicationId "com.andre.andredublin"
        minSdkVersion 14
        targetSdkVersion 19
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }

    sourceSets {
        main {
            scala {
                srcDir 'src'
            }
        }
    }

    dexOptions {
        preDexLibraries false
        javaMaxHeapSize "2g"
    }
}

dependencies {
    compile 'com.facebook.android:facebook-android-sdk:3.21.1'
    compile 'com.android.support:multidex:1.0.0'
    compile 'org.scala-lang:scala-library:2.11.4'
    compile 'io.spray:spray-json_2.11:1.3.1'
    compile 'org.scaloid:scaloid_2.11:3.6.1-10'
    compile 'com.loopj.android:android-async-http:1.4.4'
    compile 'com.google.code.gson:gson:2.2.2'
    compile 'net.hockeyapp.android:HockeySDK:3.5.0'
    compile project(':imageloader-core-1.6.1')
}

afterEvaluate {
    tasks.matching {
        it.name.startsWith("dex")
    }.each { dx ->
        if (dx.additionalParameters == null) {
            dx.additionalParameters = []
        }
        dx.additionalParameters += "--multi-dex"
        dx.additionalParameters += "--main-dex-list=$rootDir/main-dex-list.txt".toString()
    }
}

Here is the error I receive from the logs when running in genymotion.

01-17 03:18:07.291    1118-1118/? E/dalvikvm﹕ Could not find class 'com.novoda.imageloader.core.LoaderSettings$SettingsBuilder', referenced from method com.andre.andredublin.MyApplication.onCreate
01-17 03:18:07.291    1118-1118/? W/dalvikvm﹕ VFY: unable to resolve new-instance 751 (Lcom/novoda/imageloader/core/LoaderSettings$SettingsBuilder;) in Lcom/andre/andredublin/MyApplication;
01-17 03:18:07.291    1118-1118/? D/dalvikvm﹕ VFY: replacing opcode 0x22 at 0x0005
01-17 03:18:07.291    1118-1118/? D/dalvikvm﹕ DexOpt: unable to opt direct call 0x1244 at 0x0a in Lcom/andre/andredublin/MyApplication;.onCreate
01-17 03:18:07.291    1118-1118/? D/dalvikvm﹕ DexOpt: unable to opt direct call 0x1242 at 0x1f in Lcom/andre/andredublin/MyApplication;.onCreate
01-17 03:18:07.291    1118-1118/? D/AndroidRuntime﹕ Shutting down VM
01-17 03:18:07.291    1118-1118/? W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xa4bd6648)
01-17 03:18:07.295      377-393/system_process D/﹕ HostConnection::get() New Host Connection established 0xb939d6a0, tid 393
01-17 03:18:07.295    1118-1118/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
    java.lang.NoClassDefFoundError: com.novoda.imageloader.core.LoaderSettings$SettingsBuilder
            at com.andre.andredublin.MyApplication.onCreate(MyApplication.java:40)
            at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1007)
            at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4444)
            at android.app.ActivityThread.access$1300(ActivityThread.java:141)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:5103)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:525)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
            at dalvik.system.NativeStart.main(Native Method)

I've just had similar problem with library project in Android Studio. My app was working on devices with Lollipop, but not on KitKat. The reason for it was that I had multiple dex set up, because I used google play services imported, so the number of method references was more than 64K. Luckily, I have managed to eliminate the need for multiple dex by reducing it to google maps import only. If this cannot be done for you, this and this articles might be useful.

Converted to reply from the comment.

Did you maybe forget to reference any JAR file? Does library project imageloader-core-1.6.1 reports any errors (anything underlined with red color)? Same error after Build->Clean project ? Same error after File->Invalidate Cache ?

Sometimes also helps Gradle line compile files(PATH_TO_JAR_FILE) , but as I know this was fixed in all newer Android Studios. Which AS version are you using?

Here is my solution.

1. set defaultConfig

"multiDexEnabled true" 

2. add dependence

compile 'com.android.support:multidex:1.0.1'

3. add:

protected void attachBaseContext(Context base) {
    super.attachBaseContext(base);
    MultiDex.install(this);
}

in your application.java

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM