iOS/iPhone/iPad/watchOS/tvOS/MacOSX/Android プログラミング, Objective-C, Cocoa, Swiftなど
EclipseでGradle関連ファイルをエクスポートすればいいのだが、今後、Eclipseをインストールしていない環境での作業を考えて、Android Studioでビルドするために必要なGradle関連のファイルを備忘録として記録する。
ディレクトリ構成は以下のとおり。
-+
| settings.gradle
| build.gradle
+-cocos2d
| |
| +-cocos
| |
| +-platform
| |
| +-android
| |
| +-java
| build.gradle
|
+-proj.android
build.gradle
上記のsettings.gradleと複数のbuild.gradleを作成すれば、Android StudioのImport Non-Android Studio projectで開けるようになる。
ルートディレクトリのsettings.gradleとbuild.gradleの内容は以下のとおり。
include ':cocos2d:cocos:platform:android:java'
include ':proj.android'
// 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:1.0.0'
}
}
cocos2d-xのbuild.gradleの内容は以下のとおり。
apply plugin: 'android-library'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
android {
compileSdkVersion 10
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/
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src//... 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')
}
}
当該アプリのbuild.gradleの内容は以下のとおり。
apply plugin: 'android'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile project(':cocos2d:cocos:platform:android:java')
}
android {
compileSdkVersion 10
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']
jniLibs.srcDirs = ['libs']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
// Move the build types to build-types/
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src//... 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')
}
}