buck是facebook开源一款构建工具,优点就是快,支持linux和mac环境下的各种构建。
- 安装buck
brew update
brew tap facebook/fb
brew install buck
- 创建一个示例应用:
cocos new -llua -p com.example.demo BuckDemo
- 使用aidl命令修改IGameTuningService.aidl为java
aidl位于AndroidSDK的build-tools/下
cd frameworks/cocos2d-x/cocos/platform/android/java/
aidl -Isrc/com/enhance/gameservice/ src/com/enhance/gameservice/IGameTuningService.aidl
rm -rf src/com/enhance/gameservice/IGameTuningService.aidl
- 创建Android的keystore及keystore.properties
cd frameworks/runtime-src/proj.android
keytool -genkey -keystore game.keystore -alias game -keyalg RSA -keysize 2048 -validity 10000
touch game.keystore.properties
keystore.properties内容:
key.alias=game
key.store.password=android
key.alias.password=android
- 创建.buckconfig文件
.buckconfig内容如下
[android]
target = Google Inc.:Google APIs:19
[project]
ignore = .svn,tmp,ide,doc,.git
7.创建cocos2d-x库工程的BUCK文件
cd frameworks/cocos2d-x/cocos/platform/android/java/
touch BUCK
BUCK文件内容
prebuilt_jar(
name = 'android-async-http-1.4.8',
binary_jar = 'libs/android-async-http-1.4.8.jar',
visibility = [ 'PUBLIC' ],
)
android_library(
name = 'libcocos2d',
srcs = glob(['src/**/*.java']),
manifest = 'AndroidManifest.xml',
exported_deps = [ ':android-async-http-1.4.8', ],
visibility = [ 'PUBLIC' ],
)
- 创建项目的buck构建文件
frameworks/runtime-src/proj.android/BUCK
内容如下:
android_resource(
name = 'res',
manifest = 'AndroidManifest.xml',
res = 'res',
assets = 'assets',
visibility = [ 'PUBLIC' ],
)
prebuilt_native_library(
name = 'native_libs',
native_libs = 'libs',
)
android_library(
name = 'game',
srcs = glob(['src/**/*.java']),
exported_deps = ['//frameworks/cocos2d-x/cocos/platform/android/java:libcocos2d'],
deps = [':res',':native_libs', ],
visibility = [ 'PUBLIC' ],
)
keystore(
name = 'game_keystore',
store = 'game.keystore',
properties = 'game.keystore.properties',
)
android_binary(
name = 'app',
manifest = 'AndroidManifest.xml',
keystore = ':game_keystore',
package_type = 'debug',
deps = [
':game',
],
)
project_config(
src_target = ':app',
)
7.构建并安装
首先编译c++部分,不生成apk。
cocos compile -p android --no-apk
利用buck构建apk工程(速度很快)
buck build frameworks/runtime-src/proj.android:app
adb install -r buck-out/gen/frameworks/runtime-src/proj.android/app.apk
网友评论