新文档在:
https://github.com/faint2death/cocos2d-js/blob/master/build-ipa.md
1. 环境配置
MacBook Air,操作系统版本是10.9.3,Xcode版本是5.0.2。把cocos2d-js解压到/Users/x/cocos2d/cocos2d-js-v3.0-beta,配置环境变量:
xtekiMacBook-Air:cocos2d-js-v3.0-beta x$ ./setup.py
Setting up cocos2d-x...
->Check environment variable COCOS_CONSOLE_ROOT
->Find environment variable COCOS_CONSOLE_ROOT...
->COCOS_CONSOLE_ROOT is found : /Users/x/cocos2d/cocos2d-js-v3.0-beta/tools/cocos2d-console/bin
->Configuration for Android platform only, you can also skip and manually edit "/Users/x/.bash_profile"
->Check environment variable NDK_ROOT
->Find environment variable NDK_ROOT...
->NDK_ROOT not found
->Please enter the path of NDK_ROOT (or press Enter to skip):
->Check environment variable ANDROID_SDK_ROOT
->Find environment variable ANDROID_SDK_ROOT...
->ANDROID_SDK_ROOT not found
->Please enter the path of ANDROID_SDK_ROOT (or press Enter to skip):
->Check environment variable ANT_ROOT
->Find environment variable ANT_ROOT...
->ANT_ROOT not found
->Find command ant in system...
->Command ant not found
->Please enter the path of ANT_ROOT (or press Enter to skip):
Please execute command: "source /Users/x/.bash_profile" to make added system variables take effect
xtekiMacBook-Air:cocos2d-js-v3.0-beta x$ source /Users/x/.bash_profile
IOS只需安装Xcode,不需要其他其他SDK。
2. 编译测试
生成一个测试项目:
xtekiMacBook-Air:cocos2d-js-v3.0-beta x$ cocos new MyGame -l js -d /Users/x/project/
编译这个测试项目:
xtekiMacBook-Air:cocos2d-js-v3.0-beta x$ cd /Users/x/project/MyGame
xtekiMacBook-Air:MyGame x$ cocos compile -p ios
编译后,在项目目录的runtime/ios/下生成MyGame.app目录包,然后可以用xcrun打包:
xtekiMacBook-Air:MyGame x$ xcrun -sdk iphoneos PackageApplication /Users/x/project/MyGame/runtime/ios/MyGame.app -o /Users/x/project/MyGame/MyGame.ipa
xtekiMacBook-Air:MyGame x$ ls -l
total 18328
-rw-r--r-- 1 x staff 9370194 6 16 16:42 MyGame.ipa
...
这个生成的ipa文件是i386指令集,用于模拟器测试调试。
3. 真机安装包编译
真机安装包需要证书签名,开发阶段一般有两种:开发和发布,本节讨论的是企业内部发布的in-house证书。
首先,在苹果开发者网站 https://developer.apple.com/account/ios/identifiers/bundle/bundleList.action配置App ID,这个App ID后面编译的时候要用到。然后到 https://developer.apple.com/account/ios/profile/profileList.action?type=production下载刚才设置App ID的Profile,下载到本地后双击。
双击项目目录frameworks/runtime-src/proj.ios_mac/下的xcodeproj文件,在打开的xcode里设置General里的Bundle Identifier,注意和App ID匹配,下面的Team选择企业发布证书。如果是横屏的游戏,那么在下面的Device Orientation勾选"Landscape Left"和“Landscape Right”,如果是竖屏游戏,那么勾选“Portrait”和“Upside Down”。然后在Build Settings的Code Signing Identity选择开发还是发布,最后在下面的Provisioning Profile选择刚才在苹果开发网站下载的Profile。
需要编译arm指令集的ipa包,那么还要修改cocos2d-js-v3.0-beta/tools/cocos2d-console/plugins/project_compile/project_compile.py关于ios编译参数的修改:
def build_ios(self):
...
command = ' '.join([
"xcodebuild",
"-project",
"\"%s\"" % projectPath,
"-configuration",
"%s" % 'Debug' if self._mode is 'debug' else 'Release',
"-target",
"\"%s\"" % targetName,
"-sdk",
"iphonesimulator",
"-arch i386",
"CONFIGURATION_BUILD_DIR=%s" % (output_dir)
])
...
这里把iphonesimulator改成iphoneos,i386改成armv7,然后在项目目录执行cocos compile -p ios,编译到最后的时候,会调用codesign来做一个签名,会弹出一个钥匙串访问的对话框,选总是允许就可以了。
编译好后,还是用xcrun打包成ipa文件:
xtekiMacBook-Air:MyGame x$ xcrun -v -sdk iphoneos PackageApplication /Users/x/project/MyGame/runtime/ios/MyGame.app -o /Users/x/project/MyGame/MyGame.ipa --sign "iPhone Distribution: xxx"
这个ipa文件还需要一个plist文件配合:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>items</key>
<array>
<dict>
<key>assets</key>
<array>
<dict>
<key>kind</key>
<string>software-package</string>
<key>url</key>
<string> https://xxx.xxxx.com/magic/MyGame.ipa</string>
</dict>
</array>
<key>metadata</key>
<dict>
<key>bundle-identifier</key>
<string>com.xxxx.xxxx</string>
<key>bundle-version</key>
<string>alpha</string>
<key>kind</key>
<string>software</string>
<key>title</key>
<string>magic</string>
</dict>
</dict>
</array>
</dict>
</plist>
最后,用这样的html,用户就可以点击下载安装:
<a href="itms-services://?action=download-manifest&url=https://xxx.xxxx.com/magic/MyGame.plist">点击安装(ios)</a>
IOS 7.1以上版本必须要https才可以正常安装。
[ 此帖被nonexist在2014-07-21 08:23重新编辑 ]