トップ 最新 追記

Cocoa練習帳

iOS/iPhone/iPad/watchOS/tvOS/MacOSX/Android プログラミング, Objective-C, Cocoa, Swiftなど

2012|01|02|03|04|05|06|07|08|09|10|11|12|
2013|01|02|03|04|05|06|07|08|09|10|11|12|
2014|01|02|03|04|05|06|07|08|09|10|11|12|
2015|01|02|03|04|05|06|07|08|09|10|11|12|
2016|01|02|03|04|05|06|07|08|09|10|11|12|
2017|01|02|03|04|05|06|07|08|09|10|11|12|

2015-02-15 [Android]cocos2d-xをAndroid StudioでビルドするためのGradleの雛形

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')
    }
}

_ 【Cocoa練習帳】

http://www.bitz.co.jp/weblog/
http://ameblo.jp/bitz/(ミラー・サイト)

トップ 最新 追記