问题
I have an Android project currently developed in Eclipse. I would like to transition to Android Studio, without losing the ability to fall back on Eclipse.
When I import a "non android studio project", a copy of my repository is made, and my directory structure is reorganized to conform to the gradle style.
My question is, how can I import my repository in-place, without reorganizing the directory structure?
回答1:
You will need to set up your build.gradle
file manually. Then, when you import into Android Studio, it will see the build.gradle
file and use it, rather than go through the reorganization process.
Here is a starter build.gradle
file you can drop into your Eclipse project directory:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
}
}
apply plugin: 'com.android.application'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
android {
compileSdkVersion 19
buildToolsVersion "21.1.2"
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')
}
}
The big things that you will want to adjust are:
the
compileSdkVersion
, which should match the build target that you are using for Eclipse (see yourproject.properties
file)the
buildToolsVersion
, which should reference a "Build-tools" that you have installed in the SDK Manager (where"21.1.2"
is the currently-latest version)
The comments shown above are there because the file started with one exported from Eclipse, as if you are on the current ADT plugin, you can export a build.gradle
file. However, that plugin has not been updated in quite some time, and I expect that the build.gradle
file it would generate would be largely broken.
You may also wish to set up a basic Gradle wrapper, to smooth the import process. To do that, create a gradle/wrapper/gradle-wrapper.properties
file off your Eclipse project root, with the following contents:
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
The big thing here is the distributionUrl
, which points to an official Gradle distribution, specifically the 2.2.1 that Android Studio 1.0 and Gradle for Android 1.0 like.
So, add those two files to your Eclipse project, and then Android Studio should import-in-place without any file reorganization.
You can see a few hundred projects set up this way.
来源:https://stackoverflow.com/questions/27495316/how-do-i-import-an-eclipse-project-into-android-studio-without-creating-a-reorga