之前曾有人问过这个问题,但是,我已经认真遵循了指示,并且仍在收到此问题。我需要一些帮助来弄清我所遇到的特殊情况。这是我所做的。
1)添加android-support-multidex.jar:将android-support-multidex.jar添加到计划的libs文件夹
2)编辑项目build.gradle:我修改了位于项目文件夹中的build.gradle文件。
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)修改Project Application类:我有一个扩展Application的类。我添加了以下内容。
@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
这最初是一个Eclipse项目。我导出了Eclipse项目,然后在Android Studio中导入了build.gradle文件。从那以后,我一直无法成功运行该项目。我错过的任何步骤的帮助将不胜感激。提前致谢!
编辑:这是我的顶级构建文件的内容
// 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.+'
}
}
最佳答案
更换:
classpath 'com.android.tools.build:gradle:0.12.+'
与:
classpath 'com.android.tools.build:gradle:1.0.0'
因为在7个月的Beta版本Android Gradle中未提供multidex支持。
关于android - 找不到Gradle DSL方法: 'multiDexEnabled';使用不包含方法的gradle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27932066/