天天看點

Migrating from IntelliJ Projects

We might provide an automatic migration option in Android Studio in the future.

For now, to migrate your IntelliJ project to an Android Gradle project (which can then be imported into IntelliJ and supported directly in IntelliJ), follow the following steps:

Create a basic "build.gradle" file. Unlike the default Gradle file created by Android Studio when you create a new project, the following gradle file will point the source code directories to the existing folders (e.g. <code>res/</code>, <code>src/</code>) instead of the default new directory structure used for Gradle projects (<code>src/main/java/</code>, <code>src/main/res/</code>, etc). A sample gradle file is given below.

Identify which library projects you are using (such as ActionBarSherlock). In Gradle you no longer need to add in these libraries as source code projects; you can simply refer to them as dependencies, and the build system will handle the rest; downloading, merging in resources and manifest entries, etc. For each library, look up the corresponding AAR library dependency name (provided the library in question has been updated as a android library artifact), and add these to the dependency section.

build.gradle:

<code>buildscript {</code>

<code>    repositories {</code>

<code>        mavenCentral()</code>

<code>    }</code>

<code>    dependencies {</code>

<code>        classpath 'com.android.tools.build:gradle:0.5.+'</code>

<code>}</code>

<code>apply plugin: 'android'</code>

<code>dependencies {</code>

<code>    compile fileTree(dir: 'libs', include: '*.jar')</code>

<code>android {</code>

<code>    compileSdkVersion 18</code>

<code>    buildToolsVersion "18.0.1"</code>

<code>    sourceSets {</code>

<code>        main {</code>

<code>            manifest.srcFile 'AndroidManifest.xml'</code>

<code>            java.srcDirs = ['src']</code>

<code>            resources.srcDirs = ['src']</code>

<code>            aidl.srcDirs = ['src']</code>

<code>            renderscript.srcDirs = ['src']</code>

<code>            res.srcDirs = ['res']</code>

<code>            assets.srcDirs = ['assets']</code>

<code>        }</code>

<code>        // Move the tests to tests/java, tests/res, etc...</code>

<code>        instrumentTest.setRoot('tests')</code>

<code>        // Move the build types to build-types/&lt;type&gt;</code>

<code>        // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...</code>

<code>        // This moves them out of them default location under src/&lt;type&gt;/... which would</code>

<code>        // conflict with src/ being used by the main source set.</code>

<code>        // Adding new build types or product flavors should be accompanied</code>

<code>        // by a similar customization.</code>

<code>        debug.setRoot('build-types/debug')</code>

<code>        release.setRoot('build-types/release')</code>

http://tools.android.com/tech-docs/new-build-system/migrating-from-intellij-projects

繼續閱讀