1

My aim is to build a Kony Project for the Jenkins CI. So basically I need to know how to build the project on the unix commandline. When using Kony Studio my project builds without issues.

I've already managed to build an android .apk using ant on the build.xml in the project directory. This also builds a .kar file for ios. How do I now trigger the ipa build via xcode using the commandline?

Environment: Mac OSX 10.10.2 with Kony Studio 6.0.

1
  • To build iOS apps from the command line, you can use xcodebuild. Commented Feb 25, 2015 at 21:19

2 Answers 2

5

You need to copy the "com.kony.ios_5.5.x.jar" file and rename it to "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)

Now the app will run in xcode. Archive and proceed with IPA generation.

3

EDIT START

As of Kony 7 there is a better way to do headless builds:

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

Basically use the HeadlessBuild.properties to configure your build and launch it with ant. It's a struggle in the beginning but we got a successful build of android and iOS via Jenkins.

Note: Building multiple projects at the same time does not seem to work (e.g. for multiple build types) and results in an error message. You'll have to build sequentially.

Comment if you're interested in the further build process and I'll consider writing a blog post about this :)

EDIT END

Finished a first version of a shell script to build a Kony Project for Android and iOS for Jenkins. Its far from elegant or perferct but it might be a good start for anyone who stumbles accross this post.

First I created a settings script which contains the configuration of my build (all values-to-be-entered are shown as <value> tags):

#!/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

I then have the actual script which does the build job as descripted at the top of the first script. Here we also do the Magic which Sam posted.

#!/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 ''

In the jenkins configuration I now only call the first script by executing a shell script:

cd KonyTemplate
sh ./jenkins_build.sh

If anyone has any suggestions to improve this little script (and there most definitely are plenty), I'm sure we'll all be happy to hear them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.