本文譯自Android官方技術文檔《Migrating from IntelliJ Projects》,原文地址:http://tools.android.com/tech-docs/new-build-system/migrating-from-intellij-projects。
上1篇介紹了如何上1篇介紹了如何把1個Eclipse上的Android項目遷移到 Android Studio,這1篇繼續介紹對 IntelliJ項目的遷移。
翻譯不容易,轉載請注明CSDN博客上的出處:
http://blog.csdn.net/maosidiaoxian/article/details/42736561
翻譯工作耗時費神,如果你覺得本文翻譯得還OK,請點擊文末的“頂”;如有錯訛,敬請指正。謝謝。
res/
, src/
)
而不是用 Gradle 項目的默許新目錄結構 (src/main/java/
, src/main/res/
等)。下面給出1個示例 gradle 文件。gradle assembleDebug
可以測試您的構建。如果你之前不是用 Gradle 來構建的,需要從 http://www.gradle.org/downloads 中安裝它。請注意,當您通過
Studio 創建新項目時,我們會在項目的根目錄創建1個 gradle wrapper 腳本 (“gradlew”和“gradlew.bat”),所以該項目的任何用戶只需在你的項目中運行“gradlew assembleDebug”等命令,gradle 就會自動下載和安裝。但是,您現有的 IntelliJ 項目大概還沒有這個 gradle 腳本。buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
android {
compileSdkVersion 18
buildToolsVersion "18.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')
}
}