Gradle DSL Method not found: 'multiDexEnabled&

2019-09-01 07:18发布

问题:

This question has been asked before, however, I have followed the directions carefully and am still receiving this issue. I need some help with figuring out what I am missing with my particular situation. Here is what I have done.

1) Add android-support-multidex.jar: Added android-support-multidex.jar to projected libs folder 2) Edit project build.gradle: I modified my build.gradle file located in my project's folder.

apply plugin: 'android'

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    .....
    compile 'com.android.support:multidex:1.0.0'
}

android {
    compileSdkVersion 19
    buildToolsVersion "21.1.2"

    defaultConfig {
    applicationId "com.example.mypackagename"
        minSdkVersion 14
        targetSdkVersion 21

        // Enabling multidex support.
        multiDexEnabled true
    }

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

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }

        // Move the tests to tests/java, tests/res, etc...
        instrumentTest.setRoot('tests')

        // Move the build types to build-types/<type>
        // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
        // This moves them out of them default location under src/<type>/... which would
        // conflict with src/ being used by the main source set.
        // Adding new build types or product flavors should be accompanied
        // by a similar customization.
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }
}

3) Modify Project Application class: I have a class that extends Application. I added the following to it.

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

This was originally an Eclipse project. I exported the Eclipse project, and then imported the build.gradle file in Android Studio. I have not been able to successfully run the project since. Any help with steps I have missed would be appreciated. Thanks in advance!

Edit: Here is the contents of my top-level build file

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.12.+'
    }
}

回答1:

Replace:

classpath 'com.android.tools.build:gradle:0.12.+'

with:

classpath 'com.android.tools.build:gradle:1.0.0'

as multidex support was not offered in that 7-month-old beta release of the Gradle for Android plugin.