OSX - Create .app file using ant - macos

I have written an app in Objective-C for running it on Mac(OSX not iOS). I want to use it for direct distribution. In XCode, I can create .app file using Product -> Archive -> Distribute.
How do I create .app file using ant?

I found the answer myself. My ant.xml is as follows
<project name="MacAgent" default="MacCompile">
<property name="keychain.password" value="my_password"/>
<property name="user" value="my_username"/>
<property name="project.id" value="my_project_name"/>
<property name="xcodeHome" value="/Applications/Xcode.app/Contents/Developer"/>
<target name="MacCompile">
<exec executable="security">
<arg value="unlock-keychain"/>
<arg value="-p"/>
<arg value="${keychain.password}"/>
<arg value="/Users/${user}/Library/Keychains/login.keychain"/>
</exec>
<exec executable="${xcodeHome}/usr/bin/xcodebuild">
<arg value="-project"/>
<arg value="${project.id}.xcodeproj"/>
<arg value="clean"/>
<arg value="build"/>
</exec>
</target>
</project>

Related

How to run Maven command in ant script?

I am trying to create an ant task to execute a maven command, but I am getting error while running the ant task
<target name="Junit">
<exec dir="./MServer/BuildServer/Workspc/CustMgmt" executable="cmd">
<arg value="/C"/>
<arg value="E:\EOM Setup\maven-3.3.9\bin\mvn.bat"/>
<arg value="test" />
</exec>
</target>
While am running this, am getting an error:
'E:\EOM' is not recognized as internal or external command, operable program or batch file
(I am running on Windows 7)
You can get around this issue by using Ant's property task with the location attribute (as opposed to the more common value attribute). This will store the value as a properly formatted path. In addition, you can use this to reference mvn.bat instead of typing out the entire path every time.
<target name="Junit">
<property name="mvn.executable" location="E:\EOM Setup\maven-3.3.9\bin\mvn.bat" />
<exec dir="./MServer/BuildServer/Workspc/CustMgmt" executable="cmd">
<arg value="/C"/>
<arg value="${mvn.executable}"/>
<arg value="test" />
</exec>
</target>

Specifying maven project directory in exec tag

I am running this in Bamboo using command task executable=Gradle.
<target name="deploy-jar">
<exec executable="${maven.bin}" >
<arg value="deploy:deploy-file" />
<arg value="-DgroupId=${groupid}" />
<arg value="-DartifactId=${artifact}" />
<arg value="-Dversion=${version}" />
<arg value="-Dpackaging=jar" />
<arg value="-Dfile=${file}" />
<arg value="-Durl=${maven.repo.url}"/>
<arg value="-DrepositoryId=${maven.repo.id}" />
</exec>
</target>
The build is failing due to incorrect executable="${maven.bin}"
Would someone be able to give me the proper maven project location for it to run in Bamboo successfully? or at least an idea.
Thank you!!

xCodeBuild command line/ code signing fail

I was using xcrun with Xcode 6.3 and I wasn't getting any issue.
<exec executable="xcrun" dir="${IOS_PROJECT_ROOT_SRC}" failonerror="true">
<arg line="-sdk ${TARGET_SDK}" />
<arg line="PackageApplication"/>
<arg line="-v ${PROJECT_BUILD_LOCATION_SRC}/${IOS_APP_BUNDLE_NAME}.app" />
<arg line="-o ${PACKAGE_DIR_SRC}/${APP_TARGET}.ipa" />
<arg line="--sign '${CODE_SIGNING_IDENTITY_SRC}'" />
<arg line="--embed ${basedir}/${PROVISONING_PROFILE_SRC}" />
</exec>
However, After I upgraded to xCode 7.3.1, the command started making issues on our app and after investigating, I read that I need to use xcodebuild command to create an archive and export a signed ipa file with our disruption cert.
I am using the following:
First: Clean:
<exec executable="xcodebuild" dir="${IOS_PROJECT_ROOT_SRC}" failonerror="true">
<arg line="-project ${XCODE_PROJECT_NAME}.xcodeproj"/>
<arg line="-alltargets clean"/>
</exec>
Second : Compile:
<exec executable="xcodebuild" dir="${IOS_PROJECT_ROOT_SRC}"
failonerror="true">
<arg line="-project ${XCODE_PROJECT_NAME}.xcodeproj"/>
<arg line="-alltargets" />
<arg line="-sdk ${TARGET_SDK}" />
<arg line="-arch armv7"/>
<arg line="-configuration ${CONFIGURATION_NAME}" />
<arg line="CONFIGURATION_BUILD_DIR='${PROJECT_BUILD_LOCATION_SRC}'"/>
<arg value="clean"/>
<arg value="build"/>
</exec>
Third: Create Archive:
<exec executable="xcodebuild" dir="${IOS_PROJECT_ROOT_SRC}" failonerror="true">
<arg line="-scheme ${XCODE_PROJECT_NAME}" />
<arg line="-sdk ${TARGET_SDK}" />
<arg line="-archivePath ${IOS_PROJECT_ROOT_SRC}/${XCODE_PROJECT_NAME}.xcarchive" />
<arg line="-configuration ${CONFIGURATION_NAME}" />
<arg line="archive"/>
</exec>
Forth : Export the archive to signed IPA.
<exec executable="xcodebuild" dir="${IOS_PROJECT_ROOT_SRC}" failonerror="true">
<arg line="-exportArchive"/>
<arg line="-archivePath ${IOS_PROJECT_ROOT_SRC}/${XCODE_PROJECT_NAME}.xcarchive" />
<arg line="-exportPath ${PACKAGE_DIR_SRC}" />
<arg line="-exportFormat" />
<arg line="IPA" />
<arg line="PROVISIONING_PROFILE ${basedir}/${PROVISONING_PROFILE_SRC}" />
</exec>
However, I'm getting this error:
Codesign check fails : /var/folders/_y/069ykjxd3hv51j9l62flnq2m0000gn/T/12AEA489-05B5-4682-BE29-7527661382B4-14940-000038AD332AE345/BankMobile.app: a sealed resource is missing or invalid
[exec] file missing: /private/var/folders/_y/069ykjxd3hv51j9l62flnq2m0000gn/T/12AEA489-05B5-4682-BE29-7527661382B4-14940-000038AD332AE345/BankMobile.app/archived-expanded-entitlements.xcent
I'm unable to create a signed IPA file, what am I missing?
After three days of working on this I found the full solution which is the following:
First
In your Xcode project you need to remove ResourcesRules.plist from Code Signing Resource Rules Path and set the other code signing flags to --no-strict:
Second:
I removed all the scripts mentioned in the question and added the following:
<property name="CONFIGURATION_NAME" value="Release"/>
<property name="TARGET_SDK" value="iphoneos"/>
<property name="PROVISONING_PROFILE_SRC" value='"Company Mobile In House Distribution"'/>
<exec executable="xcodebuild" dir="${IOS_PROJECT_ROOT_SRC}" failonerror="true">
<arg line="-scheme ${XCODE_PROJECT_NAME}" />
<arg line="-sdk ${TARGET_SDK}" />
<arg line="-archivePath ${IOS_PROJECT_ROOT_SRC}/${XCODE_PROJECT_NAME}.xcarchive" />
<arg line="-configuration ${CONFIGURATION_NAME}" />
<arg line="clean"/>
<arg line="archive"/>
</exec>
<echo level="info">Exporting the Archive file ${XCODE_PROJECT_NAME}.xcarchive</echo>
<exec executable="xcodebuild" dir="${IOS_PROJECT_ROOT_SRC}" failonerror="true">
<arg line="-exportArchive"/>
<arg line="-archivePath ${IOS_PROJECT_ROOT_SRC}/${XCODE_PROJECT_NAME}.xcarchive" />
<arg line="-exportPath ${PACKAGE_DIR_SRC}/${APP_TARGET}.ipa" />
<arg line="-exportProvisioningProfile ${PROVISONING_PROFILE_SRC}"/>
</exec>
The tricky part is the value for -exportProvisioningProfile. This value is NOT the UUID of the provisioning profile.
It is the exact name appears in your xCode account under Provisioning Profiles, it MUST be surrounded by double quotes like "".
[Review the PROVISONING_PROFILE_SRC value property carefully and update based on your own provisioning name as I added single quotes first then surrounded my provision name with double quotes]:

Ant build executes cordova

I created an ant build for my cordova project as following:
<project default="build">
<target name="init-android">
<exec executable="cordova">
<arg value="platform"/>
<arg value="add"/>
<arg value="android"/>
</exec>
<exec executable="cordova">
<arg value="build"/>
</exec>
</target>
</project>
But I got this error:
C:\path_to_project\build.xml:3: Execute failed: java.io.IOException:
Cannot run program "cordova": CreateProcess error=2, The system cannot
find the file specified
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
at java.lang.Runtime.exec(Runtime.java:615)
at org.apache.tools.ant.taskdefs.launcher.Java13CommandLauncher.exec(Jav
a13CommandLauncher.java:41)
I can run cordova command with no problem from the command prompt, I have:
JAVA_HOME = C:/Program Files/Java/jdk1.7.0_10/
ANT_HOME = C:\Program Files\Java\apache-ant-1.9.2
NODEJS_HOME = C:\Program Files\nodejs
and they are all in my path. I don't understand why it doesn't work. Please help. Thanks
Generally when working with a Java application to launch programs in Windows, I often have to execute cmd.exe and pass it the full path to the program I actually want to run. This allows system environment variables and such to be set up the way you expect. Try this:
<project default="build">
<target name="init-android">
<exec executable="cmd.exe">
<arg value="/C"/>
<arg value="cordova"/>
<arg value="platform"/>
<arg value="add"/>
<arg value="android"/>
</exec>
<exec executable="cmd.exe">
<arg value="/C"/>
<arg value="cordova"/>
<arg value="build"/>
</exec>
</target>
</project>
If that still doesn't work, give the full path for cordova. An environment variable should work if you have one defined.

Launching Windows Explorer from ANT?

Is there any way of launching Windows Explorer from ant without stopping the build?
Here is what I have so far:
<project default="default">
<target name="default">
<fail unless="customerName">
You need to set the customerName.
-DcustomerName=Value
</fail>
<fail unless="htmlCode">
You need to set the htmlCode.
-DcustomerName=Value
</fail>
<exec executable="cmd">
<arg value="-b">
</exec>
<exec executable="explorer">
<arg value='"C:\working_copies\${customerName}\${htmlCode}"' />
</exec>
<exec executable="explorer">
Unfortunately the code above pauses for each window opened and I don't get both my explorer windows at once.
This should work:
<exec executable="cmd.exe"
dir="C:\working_copies\${customerName}\${htmlCode}">
<arg line="/c explorer ." />
</exec>

Resources