这个问题之前已经问过了,但是,我已经仔细按照指示进行操作,并且仍然收到此问题。我需要一些帮助来弄清楚我的特定情况缺少什么。这是我所做的。
1)添加android-support-multidex.jar:添加了android-support-multidex.jar到投影库文件夹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)修改项目应用程序类:我有一个扩展应用程序的类。我在其中添加了以下内容。
@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'
因为在 Gradle for Android 插件的 7 个月前的测试版中没有提供 multidex 支持。