如何使用命令行构建 Kony iOS 项目

How to build a Kony iOS Project using commandline

我的目标是为 Jenkins CI 建立一个 Kony 项目。所以基本上我需要知道如何在 unix 命令行上构建项目。使用 Kony Studio 时,我的项目构建没有问题。

我已经在项目目录的 build.xml 上使用 ant 构建了一个 android .apk。这也为 ios 构建了一个 .kar 文件。 我现在如何使用命令行通过xcode触发 ipa 构建?

环境:Mac OSX 10.10.2 与 Kony Studio 6.0。

您需要复制“com.kony.ios_5.5.x.jar”文件并重命名为“” com.kony.ios_5.5.x.zip".

    Unzip the "com.kony.ios_5.5.x.zip",
    The unzipped folder contains 5 files, one of it is "**iOS-GA-5.5.x.zip**".
    Make sure that you DO NOT delete any of these 5 files.

    Unzip the "iOS-GA-5.5.x.zip" , it will give you the "VMAppWithKonylib" folder.

    Now, close all the xcodes you might have open.

    Then delete data at path Users/(UserName)/Library/Developer/Xcode/DerivedData

    Now go to Terminal

    Navigates upto Gen folder using cd (e.g. cd /Users/foo/Desktop/VMAppWithKonylib/gen)

    Type pearl extract.pl <KAR file path> and launch the Xcode and do a build. (e.g. perl extract.pl /Users/foo/Downloads/konyappiphone-193.kAR)

Now type open <xcodeproj path>. (e.g. open /Users/foo/Desktop/VMAppWithKonylib/VMAppWithKonylib.xcodeproj)

现在应用程序将 运行 xcode。存档并继续生成 IPA。

编辑开始

从 Kony 7 开始,有更好的无头构建方法:

http://docs.kony.com/konylibrary/visualizer/visualizer_user_guide/Content/CommandLine.htm

基本上使用 HeadlessBuild.properties 配置您的构建并使用 ant 启动它。一开始是一场斗争,但我们通过 Jenkins 成功构建了 android 和 iOS。

注意:同时构建多个项目似乎不起作用(例如,对于多个构建类型)并导致出现错误消息。您必须按顺序构建。

如果您对进一步的构建过程感兴趣,请发表评论,我会考虑写一篇关于此的博客 post:)

编辑结束

完成了 shell 脚本的第一个版本,为 Jenkins Android 和 iOS 构建了一个 Kony 项目。 它远非优雅或完美,但对于任何偶然发现此 post 的人来说,这可能是一个好的开始。

首先,我创建了一个设置脚本,其中包含我的构建配置(所有要输入的值都显示为 <value> 标签):

#!/bin/bash

# This script builds a Kony Project with following steps
# 1.  Inject settings into global.properties, build.properties, middleware properties
# 2.  Build Project by executing ant build.xml 
# 2.1 When building android apps these are already packed as .apk
# 2.2 APK is signed 
# 3.  If iOS app is build the iOS dumyWorkspace (VMAppWithKonylib) is unzipped and filled with KAR file from ant build
# 3.1 the iOS app is archived 
# 3.2 this iOS app is signed and exported as ipa
# 4.  all APK and IPA files are copied to deploys folder.

# Note: The Directory the Kony Project is inside must be the name of the Kony Project. otherwise it will not build. This means, that if you clone your project from repository you'll have to put it into a folder or already have it checkedin as a folder.

_project_name=<Kony Application Project name. e.g. KonyTemplate>

# Targets
_target_android_phone=true
_target_android_tablet=false
_target_ios_phone=true
_target_ios_tablet=false

# Middleware Config
_middleware_ipaddress=127.0.0.1
_middleware_httpport=8080
_middleware_httpsport=443

# tools
_android_home=<android sdk home>
_android_zipalign=<zipalign in android build-tools>
_eclipse_equinox=<eclipse equinox jar in kony studio. e.g. /Users/userxyz/Kony_Studio/plugins/org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar
_ant_bin_dir=<ant binary directory e.g. /usr/local/bin>

# you will need this parameter if you build an ios project. It is the You can retrieve it like this:
# - search for file "com.kony.ios_x.x.x.GA_vxxxxxxxxxxxx.jar" in Kony_Studio/plugins/ Folder
# - copy it to another folder and rename it as .zip
# - unzip 
# - retrieve file "iOS-GA-x.x.x.zip" and copy it to destination referenced in _ios_dummy_project_zip variable
_ios_dummy_project_zip=<location of kony ios workspaced (zipeed). e.g. /Applications/Kony/Kony_Studio/iOS-GA-6.0.2.zip>

# OS Code Signing
_ios_code_sign_identity='<code sign identity>'
_ios_provisioning_profile_uuid='<xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx>'
_ios_provisioning_profile_name='<provisioning profile name'

# Android signing
_android_storepass=<keystore password>
_android_keyalias=<keystore alias>
_android_keypass=<key password>
_android_keystore=<keystore file within kony project directory. e.g. keystore.jks>

# Settings End
############################################################

# Execute
sh ./jenkins_build_internal.sh $_project_name $_target_android_phone $_target_android_tablet $_target_ios_phone $_target_ios_tablet $_middleware_ipaddress $_middleware_httpport $_middleware_httpsport $_removeprintstatements $_build $_android_home $_eclipse_equinox $_ant_bin_dir $_ios_dummy_project_zip "$_ios_code_sign_identity" "$_ios_provisioning_profile_uuid" "$_ios_provisioning_profile_name" $_android_zipalign $_android_storepass $_android_keyalias $_android_keypass $_android_keystore

然后我有了实际的脚本,它按照第一个脚本顶部的描述执行构建作业。在这里,我们还制作了 Sam post 编写的 Magic。

#!/bin/bash

####################
# Settings

_project_name=

# Targets
_target_android_phone=
_target_android_tablet=
_target_ios_phone=
_target_ios_tablet=

# Middleware Config
_middleware_ipaddress=
_middleware_httpport=
_middleware_httpsport=

# Build confif
_removeprintstatements=
_build=

# Build tools Config
_android_home=
_eclipse_equinox=
_ant_bin_dir=
_ios_dummy_project_zip=

# OS Code Signing
_ios_code_sign_identity=
_ios_provisioning_profile_uuid=
_ios_provisioning_profile_name=

# Android signing
_android_zipalign=
_android_storepass=
_android_keyalias=
_android_keypass=
_android_keystore=



_sleep_while_xcode_startup=15


#######################
# Define functions


function escape_slashes {
    sed 's/\//\\//g' 
}

function change_line {
    local OLD_LINE_PATTERN=; shift
    local NEW_LINE=; shift
    local FILE=

    local NEW=$(echo "${NEW_LINE}" | escape_slashes)
    sed -i .bak '/'"${OLD_LINE_PATTERN}"'/s/.*/'"${NEW}"'/' "${FILE}"
    mv "${FILE}.bak" /tmp/
}


#######################
# Dump Settings
echo "##### Executing Jenkins Kony Build #####"
echo "#     Android Phone = " $_target_android_phone
echo "#     Android Tablet = " $_target_android_tablet
echo "#     iOS Phone = " $_target_ios_phone
echo "#     iOS Tablet = " $_target_ios_tablet
echo "##### Executing Jenkins Kony Build #####"
echo ''

#######################
# Clean 

echo "# cleaning up"
rm -rf binaries
rm -rf jssrc

#######################
# Inject properties 
echo "# injecting properties"

change_line "^android=" "android=$_target_android_phone" build.properties
change_line "^androidtablet=" "androidtablet=$_target_android_tablet" build.properties
change_line "^iphone=" "iphone=$_target_ios_phone" build.properties
change_line "^ipad=" "ipad=$_target_ios_tablet" build.properties

change_line "^android.home=" "android.home=$_android_home" global.properties
change_line "^eclipse.equinox.path=" "eclipse.equinox.path=$_eclipse_equinox" global.properties

change_line "^httpport=" "httpport=$_middleware_httpport" middleware.properties
change_line "^httpsport=" "httpsport=$_middleware_httpsport" middleware.properties
change_line "^ipaddress=" "ipaddress=$_middleware_ipaddress" middleware.properties


#######################
# Execute Main Build - Ant

echo "## Execute Kony Ant Build - Start ##"
export PATH=$PATH:${_ant_bin_dir}
ant -file build.xml
echo "## Execute Kony Ant Build - Done ##"
echo ''

#######################
# Android app signing

if [ ${_target_android_phone} == "true" -o  ${_target_android_tablet} == "true" ]
    then
    set +x
    echo "## Execute Android signing APK - Start ##"
    cd binaries/android

    jarsigner -storepass "${_android_storepass}" -keypass "${_android_keypass}" -keystore ../../${_android_keystore} luavmandroid.apk ${_android_keyalias} -signedjar luavmandroid-signed_unaligned.apk
    ${_android_zipalign} -v 4 luavmandroid-signed_unaligned.apk luavmandroid-signed.apk
    cd -
    echo "## Execute Android signing APK - Done ##"
    echo ''
fi


#######################
# Check and execute optional ios Workspace build for iphone
if [ ${_target_ios_phone} == "true" ]
    then
    echo "## Execute Kony iOS Workspace creation - Start ##"
    cd ..
    echo "# unzipping workspace #"
    rm -rf VMAppWithKonylibiphone
    unzip $_ios_dummy_project_zip -d .
    mv VMAppWithKonylib VMAppWithKonylibiphone
    cd VMAppWithKonylibiphone
    cd gen

    echo "# filling workspace #"
    perl extract.pl ../../webapps/KonyTemplater/kbf/konyappiphone.KAR
    # back to ios Workspace
    cd ..
    echo "## Execute Kony iOS iPhone Workspace creation - Done ##"

    # dirty piece of code to create the scheme files... open xcode and close it again :)
    echo "# opening project to generate scheme"
    open VMAppWithKonylib.xcodeproj
    sleep ${_sleep_while_xcode_startup}
    echo "# close project"
    osascript -e 'quit app "Xcode"'

    echo "## Execute Kony iOS Archive - Start ##"
    # create signed archive
    xcodebuild -scheme KRelease -archivePath build/Archive.xcarchive archive PROVISIONING_PROFILE="${_ios_provisioning_profile_uuid}" CODE_SIGN_IDENTITY="${_ios_code_sign_identity}"
    echo "## Execute Kony iOS Archive - Done ##"

    echo "## Execute Kony iOS IPA Generation - Start ##"
    # create ipa
    xcodebuild -exportArchive -exportFormat IPA -archivePath build/Archive.xcarchive -exportPath build/KonyiOSApp.ipa -exportProvisioningProfile "${_ios_provisioning_profile_name}"
    echo "## Execute Kony iOS IPA Generation - Done ##"
    echo ''
fi

#######################
# Check and execute optional ios Workspace build for ipad
if [ ${_target_ios_tablet} == "true" ]
    then
    echo "## Execute Kony iOS Workspace creation - Start ##"
    cd ..
    echo "# unzipping workspace #"
    rm -rf VMAppWithKonylibipad
    unzip $_ios_dummy_project_zip -d .
    mv VMAppWithKonylib VMAppWithKonylibipad
    cd VMAppWithKonylibipad
    cd gen

    echo "# filling workspace #"
    perl extract.pl ../../webapps/KonyTemplater/kbf/konyappipad.KAR
    # back to ios Workspace
    cd ..
    echo "## Execute Kony iOS iPhone Workspace creation - Done ##"

    echo "# opening project to generate scheme"
    open VMAppWithKonylib.xcodeproj
    sleep ${_sleep_while_xcode_startup}
    echo "# close project"
    osascript -e 'quit app "Xcode"'

    echo "## Execute Kony iOS Archive - Start ##"
    # create signed archive
    xcodebuild -scheme KRelease -archivePath build/Archive.xcarchive archive PROVISIONING_PROFILE="${_ios_provisioning_profile_uuid}" CODE_SIGN_IDENTITY="${_ios_code_sign_identity}"
    echo "## Execute Kony iOS Archive - Done ##"

    echo "## Execute Kony iOS IPA Generation - Start ##"
    # create ipa
    xcodebuild -exportArchive -exportFormat IPA -archivePath build/Archive.xcarchive -exportPath build/KonyiOSApp.ipa -exportProvisioningProfile "${_ios_provisioning_profile_name}"
    echo "## Execute Kony iOS IPA Generation - Done ##"
    echo ''
fi

echo "## Copy Binaries to ./deploys/ ##"
cd ..
mkdir deploys
cp VMAppWithKonylibipad/build/KonyiOSApp.ipa deploys/app-release-ipad.ipa
cp VMAppWithKonylibiphone/build/KonyiOSApp.ipa deploys/app-release-iphone.ipa
cp ${_project_name}/binaries/android/luavmandroid-signed.apk deploys/app-release-android.apk
echo ''

echo ''
echo "## JENKINS BUILD SUCCESS ##"
echo ''

在 jenkins 配置中,我现在只通过执行 shell 脚本来调用第一个脚本:

cd KonyTemplate
sh ./jenkins_build.sh

如果有人有任何改进这个小脚本的建议(肯定有很多),我相信我们都会很高兴听到他们的意见。