在Lollipop设备下运行应用程序时出现异常

时间:2016-06-29 10:09:20

标签: android

我的应用在Lollipop设备上正常运行。但是当我尝试在Lollipop设备下面运行应用程序时,它每次都会出错。

错误如下:

  

错误:.dex文件中的方法引用数不能超过64K。   :app:transformClassesWithDexForDebug FAILED   错误:任务':app:transformClassesWithDexForDebug'执行失败。

我的gradle文件如下:

defaultConfig {
    applicationId "com.ielts.touchstone.touchstone"
    minSdkVersion 15
    targetSdkVersion 23
    versionCode 1
    versionName "1.0.4"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

3 个答案:

答案 0 :(得分:2)

尝试将 multiDexEnabled 添加到您的app build.gradle文件中。

 defaultConfig {
    multiDexEnabled true
}

另外,首先清理您的项目。

答案 1 :(得分:1)

你的应用程序有超过64K的方法,默认情况下不支持android 5.0,因此例外。要支持5.0以下的64K以上方法,请为您的应用添加multidex支持。 在app模块的gradle文件中添加以下代码

android {
    .
    .
    .

    defaultConfig {
        ... 
        ...

        // Enabling multidex support.
        multiDexEnabled true
    }
    ...
}

dependencies {
  compile 'com.android.support:multidex:1.0.0'
}

并在您的清单中将multidex支持库中的MultiDexApplication类添加到应用程序元素。

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.android.multidex.myapplication">
    <application
        ...
        android:name="android.support.multidex.MultiDexApplication">
        ...
    </application>
</manifest>

可以找到更多详细信息here

答案 2 :(得分:0)

您的申请正在超过64K方法限制。 Upto API 19,android系统使用dalvik处理器,限制为64k方法。但是从API 21开始,android系统使用Android Runtimes,因此如果您正在为上面的API 21 n构建应用程序,则必须添加multiDexEnabled true。它将使用超过64K的方法配置应用程序。

检查一下 https://developer.android.com/studio/build/multidex.html

希望它会有所帮助:)

相关问题