之前已经提出过这个问题,但是,我已仔细按照说明进行操作,但仍然收到此问题。我需要一些帮助来弄清楚我在特定情况下缺少的东西。这就是我所做的。
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.+'
}
}
答案 0 :(得分:1)
替换:
classpath 'com.android.tools.build:gradle:0.12.+'
使用:
classpath 'com.android.tools.build:gradle:1.0.0'
因为在Gradle for Android插件的7个月大的测试版中没有提供multidex支持。