I'm trying to get OCLint working with a iOS project. I've installed OCLint using Brew and it has installed correctly (I can check in terminal by running the oclint command).
I've attempted to integrate it by creating a separate target (tutorial here) and creating a new run script. When I build the new target it generates a report.html file but it has no files scanned, Total Files = 0 :/
How can I get it to scan my project? Many thanks.
My script is below:
OCLINT_HOME=/Users/johndoe/Documents/Programs/oclint-0.8.1
export PATH=$OCLINT_HOME/bin:$PATH
hash oclint &> /dev/null
if [ $? -eq 1 ]; then
echo >&2 "oclint not found, analyzing stopped"
exit 1
fi
cd ${TARGET_TEMP_DIR}
if [ ! -f compile_commands.json ]; then
echo "[*] compile_commands.json not found, possibly clean was performed"
echo "[*] starting xcodebuild to rebuild the project.."
# clean previous output
if [ -f xcodebuild.log ]; then
rm xcodebuild.log
fi
cd ${SRCROOT}
xcodebuild clean
#build xcodebuild.log
xcodebuild | tee ${TARGET_TEMP_DIR}/xcodebuild.log
#xcodebuild <options>| tee ${TARGET_TEMP_DIR}/xcodebuild.log
echo "[*] transforming xcodebuild.log into compile_commands.json..."
cd ${TARGET_TEMP_DIR}
#transform it into compile_commands.json
oclint-xcodebuild
fi
echo "[*] starting analyzing"
cd ${TARGET_TEMP_DIR}
oclint-json-compilation-database -v oclint_args "-report-type html -o $OCLINT_HOME/report.html"
Try this from your terminal.
echo "Opening workspace for OCLint detection"
open -a "/Applications/Xcode.app" PATH_TO_YOUR_WORKSPACE
sleep 20
echo "Starting OCLint Check......"
rm -Rf $(pwd)/compile_commands.json
rm -Rf $(pwd)/xcodebuild.log
xcodebuild -target TARGET -configuration Release -scheme OCLint -sdk iphonesimulator
xcodebuild -sdk iphonesimulator | tee xcodebuild.log
oclint-xcodebuild xcodebuild.log
oclint-json-compilation-database -- -o=report.html
oclint-json-compilation-database -v oclint_args "-report-type html -o report.html -rc=LONG_LINE=120" open compile_commands.json open report.html
echo "Finished executing OCLint..."
echo "Closing Xcode"
killall Xcode
exit 0
Open and close Xcode only if your scheme is not getting detected.
Please try this commands your terminal. In your path directory
xcodebuild -project DemoCustomOCLint.xcodeproj -arch i386 -sdk
iphonesimulator11.0 | xcpretty -r json-compilation-database -o compile_commands.json
oclint-json-compilation-database -v -- -report-type html -o report777.html
oclint-json-compilation-database
Related
I'm working with an iOS project that produces a Framework directory at the root of the project when I execute Product -> Build For -> Running in Xcode. I need to be able to automate this process on the command line presumably using xcodebuild. However, I can't seem to determine the correct set of parameters to make this happen. Any insight into how to run this same scenario without the GUI? Do I have to look at using lipo?
This is the generic script I created. It creates a framework with combined device and simulator binaries.
#!/bin/bash
while getopts s:w: flag
do
case "${flag}" in
s) scheme=${OPTARG};;
w) workspace="-workspace ${OPTARG}.xcworkspace";;
esac
done
if [ -z "$scheme" ]
then
echo "$(basename $BASH_SOURCE) -- build XCFramework"
echo ""
echo "$(basename $BASH_SOURCE) -s scheme-name [ -w workspace0-name ]"
echo ""
echo "Run this script from the top-level directory of your framework."
echo "The build result will be here: archives/<scheme-name>.xcframework"
exit
fi
rm -rf archives/$scheme.xcframework
xcodebuild archive \
$workspace \
-scheme $scheme \
-destination "generic/platform=iOS Simulator" \
-archivePath "archives/$scheme-Simulator" \
SKIP_INSTALL=NO \
BUILD_LIBRARY_FOR_DISTRIBUTION=YES
xcodebuild archive \
$workspace \
-scheme $scheme \
-destination "generic/platform=iOS" \
-archivePath "archives/$scheme" \
SKIP_INSTALL=NO \
BUILD_LIBRARY_FOR_DISTRIBUTION=YES
cp -r archives/$scheme-Simulator.xcarchive/Products/Library/Frameworks/. archives/simulator
cp -r archives/$scheme.xcarchive/Products/Library/Frameworks/. archives/ios
function GetUUID() {
local arch=$1
local binary=$2
local dwarfdump_result=$(dwarfdump -u ${binary})
local regex="UUID: (.*) \((.*)\)"
if [[ $dwarfdump_result =~ $regex ]]; then
local result_uuid="${BASH_REMATCH[1]}"
local result_arch="${BASH_REMATCH[2]}"
if [ "$result_arch" == "$arch" ]; then
echo $result_uuid
fi
fi
}
BCSYMBOLMAP_UUID=$(GetUUID "arm64" "archives/$scheme.xcarchive/Products/Library/Frameworks/$scheme.framework/$scheme")
xcodebuild -create-xcframework \
-framework archives/ios/$scheme.framework \
-debug-symbols ${PWD}/archives/$scheme.xcarchive/dSYMs/$scheme.framework.dSYM \
-debug-symbols "${PWD}/archives/$scheme.xcarchive/BCSymbolMaps/${BCSYMBOLMAP_UUID}.bcsymbolmap" \
-framework archives/simulator/$scheme.framework \
-debug-symbols ${PWD}/archives/$scheme-Simulator.xcarchive/dSYMs/$scheme.framework.dSYM \
-output archives/$scheme.xcframework
cd archives
rm -rf $scheme-Simulator.xcarchive $scheme.xcarchive ios simulator
How to Create Custom Universal Framework in Xcode 11.3 and iOS 13, Any run script?
Step 1:
Add new Target from Cross-platform->Aggregate
Step 2:
From build phrases add following as run script:
Type a script or drag a script file from your workspace to insert its path.
FRAMEWORK_NAME=${PROJECT_NAME}
SIMULATOR_LIBRARY_PATH="${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${FRAMEWORK_NAME}.framework"
DEVICE_LIBRARY_PATH="${BUILD_DIR}/${CONFIGURATION}-iphoneos/${FRAMEWORK_NAME}.framework"
DEVICE_BCSYMBOLMAP_PATH="${BUILD_DIR}/${CONFIGURATION}-iphoneos"
DEVICE_DSYM_PATH="${BUILD_DIR}/${CONFIGURATION}-iphoneos/${FRAMEWORK_NAME}.framework.dSYM"
SIMULATOR_DSYM_PATH="${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${FRAMEWORK_NAME}.framework.dSYM"
UNIVERSAL_LIBRARY_DIR="${BUILD_DIR}/${CONFIGURATION}-iphoneuniversal"
FRAMEWORK="${UNIVERSAL_LIBRARY_DIR}/${FRAMEWORK_NAME}.framework"
OUTPUT_DIR="./Build-Framework"
DRPBOX_DIR="/Users/$USER/Dropbox/Frameworks/iTelMessagingKit"
This builds your framework for the target simulator.
Xcodebuild -project ${PROJECT_NAME}.Xcodeproj -UseModernBuildSystem=NO -scheme ${FRAMEWORK_NAME} -sdk iphonesimulator -configuration ${CONFIGURATION} clean install CONFIGURATION_BUILD_DIR=${BUILD_DIR}/${CONFIGURATION}-iphonesimulator
This builds your framework for the device.
Xcodebuild -project ${PROJECT_NAME}.Xcodeproj -UseModernBuildSystem=NO -scheme ${FRAMEWORK_NAME} -sdk iphoneos -configuration ${CONFIGURATION} clean install CONFIGURATION_BUILD_DIR=${BUILD_DIR}/${CONFIGURATION}-iphoneos
Let’s clean up the final directories:
rm -rf "${UNIVERSAL_LIBRARY_DIR}"
mkdir "${UNIVERSAL_LIBRARY_DIR}"
mkdir "${FRAMEWORK}"
rm -rf "$OUTPUT_DIR"
mkdir -p "$OUTPUT_DIR"
Now, we take one of the framework files to our universal folder:
cp -r "${DEVICE_LIBRARY_PATH}/." "${FRAMEWORK}"
Now for the real magic, lipo, add this snippet:
lipo "${SIMULATOR_LIBRARY_PATH}/${FRAMEWORK_NAME}" "${DEVICE_LIBRARY_PATH}/${FRAMEWORK_NAME}" -create -output "${FRAMEWORK}/${FRAMEWORK_NAME}" | echo
cp -r "${FRAMEWORK}" "$OUTPUT_DIR"
cp -r "${FRAMEWORK}" "$DRPBOX_DIR"
I Xcode 9.x, I was using the below script which worked fine :
######################
# Options
######################
REVEAL_ARCHIVE_IN_FINDER=false
FRAMEWORK_NAME="${PROJECT_NAME}"
SIMULATOR_LIBRARY_PATH="${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${FRAMEWORK_NAME}.framework"
DEVICE_LIBRARY_PATH="${BUILD_DIR}/${CONFIGURATION}-iphoneos/${FRAMEWORK_NAME}.framework"
UNIVERSAL_LIBRARY_DIR="${BUILD_DIR}/${CONFIGURATION}-iphoneuniversal"
FRAMEWORK="${UNIVERSAL_LIBRARY_DIR}/${FRAMEWORK_NAME}.framework"
######################
# Build Frameworks
######################
xcodebuild -project "${PROJECT_FILE_PATH}" -target "${TARGET_NAME}"
ONLY_ACTIVE_ARCH=NO -configuration "${CONFIGURATION}" -sdk iphonesimulator
BUILD_DIR="${BUILD_DIR}" OBJROOT="${OBJROOT}" BUILD_ROOT="${BUILD_ROOT}"
CONFIGURATION_BUILD_DIR="${IPHONE_SIMULATOR_BUILD_DIR}" SYMROOT="${SYMROOT}"
ARCHS="i386 x86_64" ENABLE_BITCODE=YES OTHER_CFLAGS="-fembed-bitcode" $ACTION 2>&1
xcodebuild -project "${PROJECT_FILE_PATH}" -target "${TARGET_NAME}"
ONLY_ACTIVE_ARCH=NO -configuration "${CONFIGURATION}" -sdk iphoneos
BUILD_DIR="${BUILD_DIR}" OBJROOT="${OBJROOT}" BUILD_ROOT="${BUILD_ROOT}"
CONFIGURATION_BUILD_DIR="${IPHONE_DEVICE_BUILD_DIR}" SYMROOT="${SYMROOT}"
ARCHS="armv7 armv7s arm64" ENABLE_BITCODE=YES OTHER_CFLAGS="-fembed-bitcode" $ACTION 2>&1
######################
# Create directory for universal
######################
rm -rf "${UNIVERSAL_LIBRARY_DIR}"
mkdir "${UNIVERSAL_LIBRARY_DIR}"
mkdir "${FRAMEWORK}"
######################
# Copy files Framework
######################
cp -r "${DEVICE_LIBRARY_PATH}/." "${FRAMEWORK}"
######################
# Make an universal binary
######################
lipo "${SIMULATOR_LIBRARY_PATH}/${FRAMEWORK_NAME}" "${DEVICE_LIBRARY_PATH}/${FRAMEWORK_NAME}" -create -output "${FRAMEWORK}/${FRAMEWORK_NAME}" | echo
# For Swift framework, Swiftmodule needs to be copied in the universal framework
if [ -d "${SIMULATOR_LIBRARY_PATH}/Modules/${FRAMEWORK_NAME}.swiftmodule/" ]; then
cp -f ${SIMULATOR_LIBRARY_PATH}/Modules/${FRAMEWORK_NAME}.swiftmodule/* "${FRAMEWORK}/Modules/${FRAMEWORK_NAME}.swiftmodule/" | echo
fi
if [ -d "${DEVICE_LIBRARY_PATH}/Modules/${FRAMEWORK_NAME}.swiftmodule/" ]; then
cp -f ${DEVICE_LIBRARY_PATH}/Modules/${FRAMEWORK_NAME}.swiftmodule/* "${FRAMEWORK}/Modules/${FRAMEWORK_NAME}.swiftmodule/" | echo
fi
######################
# On Release, copy the result to release directory
######################
OUTPUT_DIR="${PROJECT_DIR}/Output/${FRAMEWORK_NAME}-${CONFIGURATION}-iphoneuniversal/"
rm -rf "$OUTPUT_DIR"
mkdir -p "$OUTPUT_DIR"
cp -r "${FRAMEWORK}" "$OUTPUT_DIR"
if [ ${REVEAL_ARCHIVE_IN_FINDER} = true ]; then
open "${OUTPUT_DIR}/"
fi
This didn't for Xcode 10. Later I saw that there was some modification required in the script. So I followed this answer to set the script. But after setting this script, when I try to build the Universal framework, Xcode hangs on Building script 1 of 1.
I have been trying to look for the right solution but failing each time.
What is the correct run script for a universal framework (covering all architectures) on Xcode 10 ?
Adding -UseModernBuildSystem=NO to xcodebuild command should work.
xcodebuild -workspace ${PROJECT_NAME}.xcworkspace -scheme ${PROJECT_NAME} -sdk iphonesimulator -configuration ${CONFIGURATION} -UseModernBuildSystem=NO clean build CONFIGURATION_BUILD_DIR=${BUILD_DIR}/${CONFIGURATION}-iphonesimulator 2>&1
xcodebuild -workspace ${PROJECT_NAME}.xcworkspace -scheme ${PROJECT_NAME} -sdk iphoneos -configuration ${CONFIGURATION} -UseModernBuildSystem=NO clean build CONFIGURATION_BUILD_DIR=${BUILD_DIR}/${CONFIGURATION}-iphoneos 2>&1
It should fix your problem.
This is the entire script I'm currently using and which successfully builds universal framework with Xcode 10. Link to gist
Currently, working to make use of latest build system to build universal framework. Shall update the answer soon.
echo "project"
#open "${PROJECT_DIR}"
if [ "true" == ${ALREADYINVOKED:-false} ]
then
echo "RECURSION: Detected, stopping"
else
export ALREADYINVOKED="true"
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-iosuniversal
# make sure the output directory exists
mkdir -p "${UNIVERSAL_OUTPUTFOLDER}"
# Step 1. Build Device and Simulator versions
echo "iphone"
xcodebuild -target "${TARGET_NAME}" ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build
echo "iphonesim"
xcodebuild -target "${TARGET_NAME}" -configuration ${CONFIGURATION} -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build
## Step 2. Copy the framework structure (from iphoneos build) to the universal folder
echo "universal"
cp -R "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.framework" "${UNIVERSAL_OUTPUTFOLDER}/"
# Step 3. Copy Swift modules from iphonesimulator build (if it exists) to the copied framework directory
echo "iphone simulator path"
SIMULATOR_SWIFT_MODULES_DIR="${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${PROJECT_NAME}.framework/Modules/${PROJECT_NAME}.swiftmodule/."
if [ -d "${SIMULATOR_SWIFT_MODULES_DIR}" ]; then
cp -R "${SIMULATOR_SWIFT_MODULES_DIR}" "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework/Modules/${PROJECT_NAME}.swiftmodule"
fi
# Step 4. Create universal binary file using lipo and place the combined executable in the copied framework directory
echo "lipo create"
lipo -create -output "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework/${PROJECT_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${PROJECT_NAME}.framework/${PROJECT_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.framework/${PROJECT_NAME}"
echo "end"
fi
First Generate the Separate build for both simulator and device
while opening your Products folder you will Find the separate build for both
And then use this Run script in your project
After Generating the Script you Find the Folder IOS-Universal in Same product Folder
For me Working fine.
The screenshots below image
Open Terminal, navigate root directory of project and Replace YourUniversalFramework with your project Name and Scheme name(if Required), run the command after successful, It will generate universal folder inside build.
Framework from universal folder is now ready to be consumed by devices and simulators!
Note: Paste whole script on Terminal after changes and Run
Command/Script For .xcodeproj Project
mkdir build
;
xcodebuild clean build \
-project YourUniversalFramework.xcodeproj \
-scheme YourUniversalFramework \
-configuration Release \
-sdk iphoneos \
-derivedDataPath derived_data \
BUILD_LIBRARY_FOR_DISTRIBUTION=YES
;
mkdir build/devices
;
cp -r derived_data/Build/Products/Release-iphoneos/YourUniversalFramework.framework build/devices
;
xcodebuild clean build \
-project YourUniversalFramework.xcodeproj \
-scheme YourUniversalFramework \
-configuration Release \
-sdk iphonesimulator \
-derivedDataPath derived_data \
BUILD_LIBRARY_FOR_DISTRIBUTION=YES
;
mkdir build/simulator
;
cp -r derived_data/Build/Products/Release-iphonesimulator/ build/simulator/
;
mkdir build/universal
;
cp -r build/devices/YourUniversalFramework.framework build/universal/
;
lipo -create \
build/simulator/YourUniversalFramework.framework/YourUniversalFramework \
build/devices/YourUniversalFramework.framework/YourUniversalFramework \
-output build/universal/YourUniversalFramework.framework/YourUniversalFramework
;
cp -r \
build/simulator/YourUniversalFramework.framework/Modules/YourUniversalFramework.swiftmodule/* \
build/universal/YourUniversalFramework.framework/Modules/YourUniversalFramework.swiftmodule/YourUniversalFramework
Command/Script For .xcworkspace Project
mkdir build
;
xcodebuild clean build \
-workspace YourUniversalFramework.xcworkspace \
-scheme YourUniversalFramework \
-configuration Release \
-sdk iphoneos \
-derivedDataPath derived_data \
BUILD_LIBRARY_FOR_DISTRIBUTION=YES
;
mkdir build/devices
;
cp -r derived_data/Build/Products/Release-iphoneos/YourUniversalFramework.framework build/devices
;
xcodebuild clean build \
-workspace YourUniversalFramework.xcworkspace \
-scheme YourUniversalFramework \
-configuration Release \
-sdk iphonesimulator \
-derivedDataPath derived_data \
BUILD_LIBRARY_FOR_DISTRIBUTION=YES
;
mkdir build/simulator
;
cp -r derived_data/Build/Products/Release-iphonesimulator/ build/simulator/
;
mkdir build/universal
;
cp -r build/devices/YourUniversalFramework.framework build/universal/
;
lipo -create \
build/simulator/YourUniversalFramework.framework/YourUniversalFramework \
build/devices/YourUniversalFramework.framework/YourUniversalFramework \
-output build/universal/YourUniversalFramework.framework/YourUniversalFramework
;
cp -r \
build/simulator/YourUniversalFramework.framework/Modules/YourUniversalFramework.swiftmodule/* \
build/universal/YourUniversalFramework.framework/Modules/YourUniversalFramework.swiftmodule/YourUniversalFramework
I recently switched to Xcode 10 and compiled my universal framework. Got this error :
fatal error: lipo: can't open input file:
/Users/testing/Library/Developer/Xcode/DerivedData/MyFramework-darbltkqlhuhbcfjavjyczodjneq/Build/Products/Debug-iphonesimulator/MyFramework.framework/MyFramework
(No such file or directory)
Getting this second error as well :
xcodebuild: error: The project
'/Users/testing/Documents/workspace/MyFramework/MyFramework.xcodeproj'
does not contain a target named ''.
This is the Run Script I have with me :
######################
# Options
######################
REVEAL_ARCHIVE_IN_FINDER=false
FRAMEWORK_NAME="${PROJECT_NAME}"
SIMULATOR_LIBRARY_PATH="${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${FRAMEWORK_NAME}.framework"
DEVICE_LIBRARY_PATH="${BUILD_DIR}/${CONFIGURATION}-iphoneos/${FRAMEWORK_NAME}.framework"
UNIVERSAL_LIBRARY_DIR="${BUILD_DIR}/${CONFIGURATION}-iphoneuniversal"
FRAMEWORK="${UNIVERSAL_LIBRARY_DIR}/${FRAMEWORK_NAME}.framework"
######################
# Build Frameworks
######################
xcodebuild -project "${PROJECT_FILE_PATH}" -target "${TARGET_NAME}"
ONLY_ACTIVE_ARCH=NO -configuration "${CONFIGURATION}" -sdk iphonesimulator
BUILD_DIR="${BUILD_DIR}" OBJROOT="${OBJROOT}" BUILD_ROOT="${BUILD_ROOT}"
CONFIGURATION_BUILD_DIR="${IPHONE_SIMULATOR_BUILD_DIR}" SYMROOT="${SYMROOT}"
ARCHS="i386 x86_64" ENABLE_BITCODE=YES OTHER_CFLAGS="-fembed-bitcode" $ACTION 2>&1
xcodebuild -project "${PROJECT_FILE_PATH}" -target "${TARGET_NAME}"
ONLY_ACTIVE_ARCH=NO -configuration "${CONFIGURATION}" -sdk iphoneos
BUILD_DIR="${BUILD_DIR}" OBJROOT="${OBJROOT}" BUILD_ROOT="${BUILD_ROOT}"
CONFIGURATION_BUILD_DIR="${IPHONE_DEVICE_BUILD_DIR}" SYMROOT="${SYMROOT}"
ARCHS="armv7 armv7s arm64" ENABLE_BITCODE=YES OTHER_CFLAGS="-fembed-bitcode" $ACTION 2>&1
######################
# Create directory for universal
######################
rm -rf "${UNIVERSAL_LIBRARY_DIR}"
mkdir "${UNIVERSAL_LIBRARY_DIR}"
mkdir "${FRAMEWORK}"
######################
# Copy files Framework
######################
cp -r "${DEVICE_LIBRARY_PATH}/." "${FRAMEWORK}"
######################
# Make an universal binary
######################
lipo "${SIMULATOR_LIBRARY_PATH}/${FRAMEWORK_NAME}" "${DEVICE_LIBRARY_PATH}/${FRAMEWORK_NAME}" -create -output "${FRAMEWORK}/${FRAMEWORK_NAME}" | echo
# For Swift framework, Swiftmodule needs to be copied in the universal framework
if [ -d "${SIMULATOR_LIBRARY_PATH}/Modules/${FRAMEWORK_NAME}.swiftmodule/" ]; then
cp -f ${SIMULATOR_LIBRARY_PATH}/Modules/${FRAMEWORK_NAME}.swiftmodule/* "${FRAMEWORK}/Modules/${FRAMEWORK_NAME}.swiftmodule/" | echo
fi
if [ -d "${DEVICE_LIBRARY_PATH}/Modules/${FRAMEWORK_NAME}.swiftmodule/" ]; then
cp -f ${DEVICE_LIBRARY_PATH}/Modules/${FRAMEWORK_NAME}.swiftmodule/* "${FRAMEWORK}/Modules/${FRAMEWORK_NAME}.swiftmodule/" | echo
fi
######################
# On Release, copy the result to release directory
######################
OUTPUT_DIR="${PROJECT_DIR}/Output/${FRAMEWORK_NAME}-${CONFIGURATION}-iphoneuniversal/"
rm -rf "$OUTPUT_DIR"
mkdir -p "$OUTPUT_DIR"
cp -r "${FRAMEWORK}" "$OUTPUT_DIR"
if [ ${REVEAL_ARCHIVE_IN_FINDER} = true ]; then
open "${OUTPUT_DIR}/"
fi
Note : Build Active Architecture solution is not what I want.
Finally, below is the script that worked for me on Xcode 10 :
# Typ######################
# Options
######################
REVEAL_ARCHIVE_IN_FINDER=false
FRAMEWORK_NAME="${PROJECT_NAME}"
SIMULATOR_LIBRARY_PATH="${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${FRAMEWORK_NAME}.framework"
DEVICE_LIBRARY_PATH="${BUILD_DIR}/${CONFIGURATION}-iphoneos/${FRAMEWORK_NAME}.framework"
UNIVERSAL_LIBRARY_DIR="${BUILD_DIR}/${CONFIGURATION}-iphoneuniversal"
FRAMEWORK="${UNIVERSAL_LIBRARY_DIR}/${FRAMEWORK_NAME}.framework"
######################
# Build Frameworks
######################
xcodebuild -project ${PROJECT_NAME}.xcodeproj -scheme ${PROJECT_NAME} -sdk iphonesimulator -configuration ${CONFIGURATION} -UseModernBuildSystem=NO clean build CONFIGURATION_BUILD_DIR=${BUILD_DIR}/${CONFIGURATION}-iphonesimulator 2>&1
xcodebuild -project ${PROJECT_NAME}.xcodeproj -scheme ${PROJECT_NAME} -sdk iphoneos -configuration ${CONFIGURATION} -UseModernBuildSystem=NO clean build CONFIGURATION_BUILD_DIR=${BUILD_DIR}/${CONFIGURATION}-iphoneos 2>&1
######################
# Create directory for universal
######################
rm -rf "${UNIVERSAL_LIBRARY_DIR}"
mkdir "${UNIVERSAL_LIBRARY_DIR}"
mkdir "${FRAMEWORK}"
######################
# Copy files Framework
######################
cp -r "${DEVICE_LIBRARY_PATH}/." "${FRAMEWORK}"
######################
# Make an universal binary
######################
lipo "${SIMULATOR_LIBRARY_PATH}/${FRAMEWORK_NAME}" "${DEVICE_LIBRARY_PATH}/${FRAMEWORK_NAME}" -create -output "${FRAMEWORK}/${FRAMEWORK_NAME}" | echo
# For Swift framework, Swiftmodule needs to be copied in the universal framework
if [ -d "${SIMULATOR_LIBRARY_PATH}/Modules/${FRAMEWORK_NAME}.swiftmodule/" ]; then
cp -f ${SIMULATOR_LIBRARY_PATH}/Modules/${FRAMEWORK_NAME}.swiftmodule/* "${FRAMEWORK}/Modules/${FRAMEWORK_NAME}.swiftmodule/" | echo
fi
if [ -d "${DEVICE_LIBRARY_PATH}/Modules/${FRAMEWORK_NAME}.swiftmodule/" ]; then
cp -f ${DEVICE_LIBRARY_PATH}/Modules/${FRAMEWORK_NAME}.swiftmodule/* "${FRAMEWORK}/Modules/${FRAMEWORK_NAME}.swiftmodule/" | echo
fi
######################
# On Release, copy the result to release directory
######################
OUTPUT_DIR="${PROJECT_DIR}/Output/${FRAMEWORK_NAME}-${CONFIGURATION}-iphoneuniversal/"
rm -rf "$OUTPUT_DIR"
mkdir -p "$OUTPUT_DIR"
cp -r "${FRAMEWORK}" "$OUTPUT_DIR"
if [ ${REVEAL_ARCHIVE_IN_FINDER} = true ]; then
open "${OUTPUT_DIR}/"
fi
I am working on a cordova app and I managed to create the ipa from command line with a script.
echo "" > $PROJECT_DIR/cordova/build.xcconfig
echo "CODE_SIGN_IDENTITY = iPhone Distribution: XXXXXXX" >> $PROJECT_DIR/cordova/build.xcconfig
echo "CODE_SIGN_RESOURCE_RULES_PATH = \$(SDKROOT)/ResourceRules.plist" >> $PROJECT_DIR/cordova/build.xcconfig
echo "IPHONEOS_DEPLOYMENT_TARGET = 7.0" >> $PROJECT_DIR/cordova/build.xcconfig
cordova build ios --device
xcrun \
-sdk iphoneos PackageApplication \
-v "$PRODUCT_DIR/$TARGET.app" \
-o "$OUTDIR/$TARGET.ipa" \
--embed "$PROVISONING_PROFILE" \
--sign "$IDENTITY"
This works just fine, but I get this warning when I upload to Apple TestFlight.
Do you guys have any hint on this? Maybe I can add a line in the .xcconfig which seems pretty handy!
I figured what was wrong! The --release flag was missing. Now I can build without opening XCode!
echo "\n > patching cordova xconfig for distribution\n"
echo "" > $PROJECT_DIR/cordova/build.xcconfig
echo "CODE_SIGN_IDENTITY = $IDENTITY" >> $PROJECT_DIR/cordova/build.xcconfig
echo "CODE_SIGN_RESOURCE_RULES_PATH = \$(SDKROOT)/ResourceRules.plist" >> $PROJECT_DIR/cordova/build.xcconfig
echo "IPHONEOS_DEPLOYMENT_TARGET = 7.0" >> $PROJECT_DIR/cordova/build.xcconfig
echo "\n > cleanup $OUTDIR/$TARGET.ipa\n"
rm -vf $OUTDIR/$TARGET.ipa
echo "\n > build project\n"
cordova build ios --release --device
echo "\n > creating ipa at $OUTDIR/$TARGET.ipa\n"
cd $BASE_DIR
xcrun \
-sdk iphoneos PackageApplication \
-v "$PRODUCT_DIR/$TARGET.app" \
-o "$OUTDIR/$TARGET.ipa" \
--embed "$PROVISONING_PROFILE" \
--sign "$IDENTITY"