简体   繁体   English

Android工作室dalvik vm无法找到课程

[英]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. 我试图弄清楚如何修复我已经移植到android studio的遗留android项目的错误。 I'm hoping this is more an issue with my build.gradle scripts. 我希望这对我的build.gradle脚本来说更是个问题。 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. 我试过关闭android工作室,运行gradlew clean,然后在android studio中重新打开它,但是没有用。

Here is my settings.gradle script. 这是我的settings.gradle脚本。

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

Here is my project build.gradle script. 这是我的项目build.gradle脚本。

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. 这是我的app build.gradle脚本。

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. 以下是我在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. 我刚刚在Android Studio中遇到了与库项目类似的问题。 My app was working on devices with Lollipop, but not on KitKat. 我的应用程序正在使用Lollipop设备,但不在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. 原因是我有多个dex设置,因为我使用了google play services导入,所以方法引用的数量超过了64K。 Luckily, I have managed to eliminate the need for multiple dex by reducing it to google maps import only. 幸运的是,我已经设法通过将它减少到谷歌地图导入来消除多个dex的需要。 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? 您是否忘记引用任何JAR文件? Does library project imageloader-core-1.6.1 reports any errors (anything underlined with red color)? 库项目imageloader-core-1.6.1报告任何错误(带红色下划线的任何内容)? Same error after Build->Clean project ? Build->Clean project后出现相同的错误? Same error after File->Invalidate Cache ? 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. 有时也帮助Gradle行compile files(PATH_TO_JAR_FILE) ,但据我所知,这在所有较新的Android工作室中都得到了修复。 Which AS version are you using? 您使用的是哪个AS版本?

Here is my solution. 这是我的解决方案。

1. set defaultConfig 1.设置defaultConfig

"multiDexEnabled true" 

2. add dependence 2.增加依赖性

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

3. add: 3.添加:

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

in your application.java 在你的application.java中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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