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

时间:2015-02-19 14:29:34

标签: android ios ant jenkins kony

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

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

环境:使用Kony Studio 6.0的Mac OSX 10.10.2。

2 个答案:

答案 0 :(得分:3)

您需要复制" 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生成。

答案 1 :(得分:2)

编辑开始

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

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

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

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

评论您是否对进一步的构建过程感兴趣,并且我会考虑撰写有关此内容的博文:)

编辑结束

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

首先我创建了一个设置脚本,其中包含我的构建配置(所有要输入的值都显示为<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发布的魔术。

#!/bin/bash

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

_project_name=$1

# Targets
_target_android_phone=$2
_target_android_tablet=$3
_target_ios_phone=$4
_target_ios_tablet=$5

# Middleware Config
_middleware_ipaddress=$6
_middleware_httpport=$7
_middleware_httpsport=$8

# Build confif
_removeprintstatements=$9
_build=${10}

# Build tools Config
_android_home=${11}
_eclipse_equinox=${12}
_ant_bin_dir=${13}
_ios_dummy_project_zip=${14}

# OS Code Signing
_ios_code_sign_identity=${15}
_ios_provisioning_profile_uuid=${16}
_ios_provisioning_profile_name=${17}

# Android signing
_android_zipalign=${18}
_android_storepass=${19}
_android_keyalias=${20}
_android_keypass=${21}
_android_keystore=${22}



_sleep_while_xcode_startup=15


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


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

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

    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

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