【问题标题】:VM has multidex support, MultiDex support library is disabledVM 有 multidex 支持,MultiDex 支持库被禁用
【发布时间】:2015-10-25 05:35:15
【问题描述】:

我收到以下错误。

致命异常:主要

  • 2.1.0 版本的虚拟机支持多索引
  • 安装
  • VM 支持 multidex,MultiDex 支持库被禁用。
  • 安装
  • VM 支持 multidex,MultiDex 支持库被禁用。
  • 关闭虚拟机

这是我的 build.gradle,我已经在 android 部分启用了 multidex,

apply plugin: 'com.android.application'


android {
compileSdkVersion 23
buildToolsVersion '23.0.0'

defaultConfig {
    applicationId "com.mycompany.newlogin"
    minSdkVersion 15
    targetSdkVersion 22
    versionCode 1
    versionName "1.0"
    multiDexEnabled true
}

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

}
useLibrary 'org.apache.http.legacy'
}



dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:multidex:1.0.0'
compile 'com.google.guava:guava-jdk5:17.0'
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:design:23.0.1'
//compile 'org.apache.httpcomponents:httpcore:4.4.1'
compile 'org.apache.httpcomponents:httpclient:4.5'
compile 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'

}

我的清单文件是

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mycompany.newlogin" >
<uses-permission android:name="android.permission.INTERNET"/>


<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme"
    android:name="android.support.multidex.MultiDexApplication">
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".Login"
        android:label="@string/title_activity_login" >
    </activity>
    <activity
        android:name=".Register"
        android:label="@string/title_activity_register" >
    </activity>
</application>
</manifest>

【问题讨论】:

  • 你有从 Application 扩展的类吗?
  • 我有扩展 AppCompactActivity 的 MainActivity 类
  • 来自文档:该库为 API 级别 4 到 20 的平台提供兼容性。该库在为辅助 dex 文件提供内置支持的较新版本的平台上没有任何作用。我在grepcode 上检查了他们的代码

标签: android virtual-machine android-multidex


【解决方案1】:

创建一个类,将其命名为 App 并从 MultiDexApplication 扩展,如下所示:

import android.support.multidex.MultiDexApplication;

public class App extends MultiDexApplication {
    //you can leave this empty or override methods if you like so the thing is that you need to extend from MultiDexApplication
}

在您的清单中添加 App 作为您的应用程序名称,就像这样

<application
        android:name=".App" // <<< this is the important line!
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name">

添加所有内容后,构建一个干净的构建,它现在应该可以工作了:)。

【讨论】:

  • 我已经上传了我的清单文件,请看看并帮助我在我的清单文件中添加你的
  • android:name="android.support.multidex.MultiDexApplication" -> 将其替换为您的自定义类。
  • 嗨,Baniares 和 Kientux,感谢你们的帮助。我收到一些空点异常错误,但不知道为什么?所以请帮我解决这个问题。
  • 老兄,我认为这不是错误,vm已经支持multidex,这就是他们禁用的原因,尝试在5.0以下检查日志。我猜 ART vm 已经有了 multidex 支持
【解决方案2】:

在您的应用程序类中覆盖 attachBaseContext 方法

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

【讨论】:

  • 假设有一个类扩展了 Application
猜你喜欢
  • 2018-04-21
  • 1970-01-01
  • 1970-01-01
  • 2015-02-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-03-28
  • 2023-03-21
相关资源
最近更新 更多