【发布时间】:2015-03-11 23:52:24
【问题描述】:
之前有人问过这个问题,但是,我已仔细按照说明进行操作,但仍然收到此问题。我需要一些帮助来弄清楚我在特定情况下缺少什么。这是我所做的。
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) 修改项目应用程序类:我有一个扩展应用程序的类。我添加了以下内容。
@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.+'
}
}
【问题讨论】:
-
您应该在项目的根目录中有另一个
build.gradle文件(这个文件可能来自您的app/目录)。如果您可以编辑您的问题并粘贴到顶级build.gradle文件中,这将有助于我们确认您的困难来源。 -
好的,请看我编辑的答案。谢谢!
标签: android gradle android-studio