android - MultiDexApplication 无法识别

标签 android gradle android-multidex

尝试在我的应用程序中使用 MultiDexApplication,但当我尝试使用它扩展我的应用程序 Activity 时,无法识别该类。

这是我的 build.gradle 文件:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion '21.0.1'
    defaultConfig {
        applicationId 'com.myapp'
        minSdkVersion 10
        targetSdkVersion 21
        versionCode 115
        versionName '4.8'
    }

    buildTypes {
        debug {
            debuggable true
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        release {
            debuggable false
            runProguard true
            zipAlign true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    packagingOptions {
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
    }

    lintOptions {
        checkReleaseBuilds false
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])

    compile 'com.google.android.gms:play-services:6.1.11'

    compile 'com.android.support:appcompat-v7:21.0.0'

    compile 'com.nineoldandroids:library:2.4.0'
    compile 'com.viewpagerindicator:library:2.4.1@aar'
    compile project(':facebook')
}

您可以看到我在 21 日编译,使用最新的构建工具,以及最新的 google play 服务和支持库。

有人让这个工作吗?

最佳答案

MultiDexApplication 类不是 appcompat-v7 库的一部分。它被装在一个单独的 jar 中(称为 android-support-multidex)。

/sdk/extras/android/support/multidex/library/libs 下找到 android-support-multidex.jar(支持库的修订版 21 提供)并将其复制到项目的 libs 文件夹中。

更新(2014 年 11 月 5 日):
该 jar 现在在中央存储库中可用:

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

有关详细信息,请参阅 here .

更新(2021 年 9 月 27 日):
Jetpack (AndroidX) 用户应将此添加为依赖项:

dependencies {
  ...
  implementation 'androidx.multidex:multidex:2.0.1'
}

关于android - MultiDexApplication 无法识别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26557737/

相关文章:

Android nfcv.transceive() 抛出异常

android - 多屏支持大小屏

gradle - 将 sourceSets 放在多个项目 gradle 中的位置

java - Android Studio 3.4 多个dex文件定义

Android - 关闭对话框 fragment 后出现小对话框

android - 如何在滚动顶部或向下隐藏 tabhost

java - Android Studio/Intellij,Gradle 错误 :Cause: peer not authenticated

android-studio - 带有 NDK : link error : undefined reference to 'stderr' 的安卓工作室

java - Google map 未找到类 "com.google.android.gms.dynamic.zza"

Android 依赖多次包含,导致应用达到 dex 限制