Android Studio无法解决:multidex打开文件

时间:2018-10-29 03:59:36

标签: android android-studio gradle resolve

无法解决:multidex 打开文件

我同步项目时发现此错误。

apply plugin: 'com.android.library'

android {
    compileSdkVersion rootProject.compileSdkVersion
    buildToolsVersion rootProject.buildToolsVersion

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion rootProject.targetSdkVersion
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

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

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    def system_dependencies = rootProject.ext.system_dependencies
    compile system_dependencies.appcompat_v7
    testCompile 'junit:junit:4.12'
}

我添加了它,但是没用;

maven {
    url 'https://maven.google.com'
}

我尝试了很多方法。如何解决?

3 个答案:

答案 0 :(得分:1)

尝试此代码

 defaultConfig {
        applicationId "com.test"
        minSdkVersion 17
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        // Enabling multidex support.
        multiDexEnabled true
    }

 dependencies {
     //Multidex support for devices prior to lollipop
     implementation 'com.android.support:multidex:1.0.1'
 }

应用程序类

package appUtils;

import android.app.Application;
import android.content.Context;
import android.os.Build;
import android.support.multidex.MultiDex;



public class App extends Application {
    @Override
    public void onCreate() {
        super.onCreate();

    }

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) MultiDex.install(this);
    }
}

答案 1 :(得分:0)

在Android 5.0之前添加对Multidex支持的依赖关系。由于您的minSdkVersion 16 ,因此您必须添加依赖项才能启用Multidex。

dependencies {
  implementation 'com.android.support:multidex:1.0.3'
}

答案 2 :(得分:0)

在项目build.gradle

    allprojects {
    repositories {
        /**
         * This must be at the top.
         */
        maven {
            url 'https://maven.google.com'
        }
        // Others 
        maven { url "..." }
        jcenter()
        mavenCentral()
        google()
    }
   }