目前我们在 Eclipse 项目导入中没有保留现有目录结构的选项。如果您安装了 Eclipse 的副本,您可以在那里打开它,然后将项目导出到 Gradle 构建文件;进行就地导出。您必须修改它导出的构建文件,因为它指定了一个非常旧的插件版本。具体来说,您必须更新 dependencies.buildscript.classpath 语句以指定 0.8.+,并更新 gradle/wrapper/gradle-wrapper.properties 文件中的 distributionUrl 属性以指定 Gradle 1.10 .
如果您没有 Eclipse,您可以使用这个样板 build.gradle 文件来帮助您入门。复制到项目根目录:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.8.+'
}
}
apply plugin: 'android'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.1"
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')
}
}
接下来,把这个 settings.gradle 文件放到你的根目录下。
include ':'
接下来,从您创建的另一个项目的根目录中复制 gradlew 和 gradlew.bat 文件以及 gradle 目录在你的项目中安装包装器。
完成了。您现在应该可以将它导入 Android Studio 并使用它了。