[英]xcodebuild is not compiling the project unless it is opened using Xcode atleast only once for cocoapods integrated project
我有一個可可豆莢的項目。
這是我用來構建項目的命令。
/ usr / bin / xcodebuild -scheme Jenkins -workspace /Users/Shared/Jenkins/Documents/Jenkins/Jenkins2/Jenkins.xcworkspace -configuration Release clean build CONFIGURATION_BUILD_DIR = / Users / Shared / Jenkins / Documents / JenkinsTestNuu / app'CODE_SIGN_IDENTITY = iPhone分布:XXXX yay(3G5FKTZJ2K)'PRODUCT_BUNDLE_IDENTIFIER = com.XXXX.two PROVISIONING_PROFILE = 6e6506e9-8233-4886-9084-ce21e8f8bbae
上面的腳本只有在Xcode可以關閉之后至少使用Xcode打開一次才能正常工作。
如果項目尚未打開,那么如果我運行腳本,則輪子在下面旋轉而沒有任何進展,例如在下圖中
如果它打開一次而不是下面的紡車,將顯示如下
===清潔目標XWebView OF PROJECT Pods with CONFIGURATION Release ===
檢查依賴項
Clean.Remove clean /Users/Shared/Jenkins/Documents/JenkinsTestNuu/app/XWebView.framework.dSYM builtin-rm -rf /Users/Shared/Jenkins/Documents/JenkinsTestNuu/app/XWebView.framework.dSYM
Clean.Remove clean /Users/Shared/Jenkins/Library/Developer/Xcode/DerivedData/appanme-bqjwbjcqisegldeaonpytprisnig/Build/Intermediates/Pods.build/Release-iphoneos/XWebView.build builtin-rm -rf / Users / Shared / Jenkins /圖書館/開發商/ Xcode中/ DerivedData / appanme-bqjwbjcqisegldeaonpytprisnig /編譯/中間體/ Pods.build /釋放-的iPhoneOS / XWebView.build
Clean.Remove clean /Users/Shared/Jenkins/Documents/JenkinsTestNuu/app/XWebView.framework builtin-rm -rf /Users/Shared/Jenkins/Documents/JenkinsTestNuu/app/XWebView.framework
===清潔目標配置釋放的項目吊艙的吊艙===
檢查依賴關系等...
在任何非cocoapods項目中都沒有觀察到這個問題。
那么原因是什么以及如何解決它?
為什么會這樣?
Xcode Vs 打開的項目之間的快速diffMerge工具分析是 迄今為止Xcode未打開的同一個項目
從這里我們可以看到許多與Xcode在.xcodeproj中打開后創建的方案相關文件
所以xcodebuild通過使用與方案相關的元數據創建.app,但因為沒有針對其失敗構建的方案
怎么解決這個?
由於缺少元數據,因此無法構建,因此需要打開Xcode,以便Xcode自動創建文件,因此需要構建一些方案。
但是當你打開Xcode時,這個Scheme相關文件是在xcuserdata下創建的,這是針對特定用戶的。 即每個用戶獲得自己的文件,保存打開的狀態文件夾,打開最后一個文件等...
將此文件保留給我們並不明智。
通過選中“ 管理方案 ”下的“ 共享”復選框可以解決該問題
這會將方案從您單獨的xcuserdata下移到可以通過源代碼控制提交的共享文件夾中 ,您可以安全地忽略xcuserdata並將共享文件夾保留在源代碼管理中
現在我們可以在不打開Xcode的情況下構建代碼,即使只有一次。
品牌 ( UI,構建設置和功能 )
使用終端
Branding.sh
#Author: Durai Amuthan(h.duraiamuthan@gmail.com)
#This is to achieve multiple branding of an iOS app by configuring the variables below
#************ Configuring the brand starts ************
#Directory path where .xcworkspace or .xcodeproj exists
PathOfProjectDirectory=/Users/Shared/Jenkins/Documents/JenkinsTestNuu/New/
#Path where info.plist exists
PathOfInfoPlist=$PathOfProjectDirectory/XxYyZz
#Path to icons where new iTunesArtwork and application icon exixts
#Note: Make sure proper naming conventions of file has been followed
PathOfNewIcons=/Users/Shared/Jenkins/Documents/icons-two
#Path to asset resource where you have kept your application icon.
PathOfAppIconSet=$PathOfProjectDirectory/XxYyZz/Icon.xcassets/AppIcon.appiconset
#Path where do you want the .app file has to be kept
PathToApp=/Users/Shared/Jenkins/Documents/JenkinsTestNuu/app
#Path where do you want the .ipa file has to kept
PathToIpa=/Users/Shared/Jenkins/Documents/JenkinsTestNuu/ipa
#Cocoapods project or project that involves more than one modules are scheme based
isWorkspaceBased=true
#Path of the Project (.xcodeproj) - applicable for workspace(.xcworkspace) based project
PathofProjectFile=$PathOfProjectDirectory/XxYyZz.xcodeproj
#Path of the Workspace (.xcworkspace)
PathofWorkspaceFile=$PathOfProjectDirectory/XxYyZz.xcworkspace
#Name of the target - applicable only for non-workspace(.xcodeproj) based projects
Target=XxYyZz
#Scheme of the iOS app
Scheme=XxYyZz
#To ascertain Cocoapods has been used or not
isCocoaPodsBased=true
#Configuration of the app (Debug -(Development) or Release(Adhoc or Distribution))
Config=Release
#For giving access to signing idetity found in KeyChain
LoginKeychainPath=/Users/Shared/Jenkins/Library/Keychains/login.keychain
LoginKeyChainPassword=xxyyzz
#Name of the code signing identity.You can find the name in Keychain or xcode build setting
CodeSigningIdentity='iPhone Distribution: Xx Yy Zz Limited (3Z5MHUYJ2L)'
#Path of the provisioning profile
PathToMobileProvision=/Users/Shared/Jenkins/Desktop/BrandingTest.mobileprovision
#UUID value found inside Provisioning profile has to be given
#Do not forget to install provisiong profile in the system
ProvisioningProfileIdentity=6e6506e9-8233-4886-9084-zf21e8f8bbae
#Bundle identifier of the app
BundleIdentifier=com.xxyy.zz
#AppVersion of the app
AppVersion=2.2.2
#App Name
Appname=Two
#************ Configuring the brand ends ************
#** Creatting the build based on configuration starts **
cd $PathOfInfoPlist
echo "****************** Setting App Name ******************"
/usr/libexec/PlistBuddy -c "Set :CFBundleName $Appname" info.plist
/usr/libexec/PlistBuddy -c "Set :CFBundleDisplayName $Appname" info.plist
echo "app name has been set as $Appname"
cd $PathOfProjectDirectory
echo "****************** Setting AppVersion ******************"
/usr/bin/agvtool new-marketing-AppVersion $AppVersion
/usr/bin/agvtool new-AppVersion -all $AppVersion
echo "****************** Changing app icons & iTunes Artwork ******************"
cp -R $PathOfNewIcons/*.png $PathOfAppIconSet
echo "App icons has been changed at $PathOfNewIcons"
cp -R $PathOfNewIcons/iTunesArtwork@2x $PathOfProjectDirectory/XxYyZz
cp -R $PathOfNewIcons/iTunesArtwork $PathOfProjectDirectory/XxYyZz
echo "iTunesArtwork has been changed at $PathOfProjectDirectory"
#Unlock login keychain
security unlock-keychain -p $LoginKeyChainPassword $LoginKeychainPath
if $isCocoaPodsBased == 'true'
then
echo "****************** Installing Cocoapods **********************"
/usr/local/bin/pod install
echo "Cocoapods has been installed"
fi
echo "****************** Creating .app ******************"
if $isWorkspaceBased == 'true'
then
/usr/bin/xcodebuild -scheme $Scheme -workspace $PathofWorkspaceFile -configuration $Config clean build CONFIGURATION_BUILD_DIR=$PathToApp "CODE_SIGN_IDENTITY=$CodeSigningIdentity" "PRODUCT_BUNDLE_IDENTIFIER=$BundleIdentifier" "PROVISIONING_PROFILE=$ProvisioningProfileIdentity"
else
/usr/bin/xcodebuild -target $Target -project $PathofProjectFile -configuration $Config clean build CONFIGURATION_BUILD_DIR=$PathToApp "CODE_SIGN_IDENTITY=$CodeSigningIdentity" "PRODUCT_BUNDLE_IDENTIFIER=$BundleIdentifier" "PROVISIONING_PROFILE=$ProvisioningProfileIdentity"
fi
echo ".app has been generated at $PathToApp"
echo "****************** Creating .ipa *******************"
/usr/bin/xcrun -sdk iphoneos PackageApplication -v $PathToApp/XxYyZz.app -o $PathToIpa/$Appname.ipa --embed $PathToMobileProvision --sign "$CodeSigningIdentity"
echo "$Appname.ipa has been generated at $PathToIpa"
#** Creatting the build based on configuration ends **
該文件具有自我描述性,您可以輕松理解。 只需在文件中配置變量值並按如下所示調用它
sh Branding.sh
供參考:
如果你想要除了App Icon和iTunesArtwork之外還要更改其他一些圖標,請使用cp
命令,例如
cp path/to/source path/to/destination
要了解更多信息請做cp man
使用上述文件,您可以為UI和Build Settings進行Branding 。
對於功能性品牌 ,你必須保持
品牌特定的URL
與品牌相關的其他輸入
在一個單獨的plist文件中,這樣在構建應用程序時也可以根據各自的品牌更改這些內容
在編碼方面,您可以自定義應用程序以讀取plist中的值
功能定義:
func getPlistFile()->Dictionary<String,AnyObject>? {
var dictPlistFile:Dictionary<String,AnyObject>?
if let path = NSBundle.mainBundle().pathForResource("plistfile", ofType: "plist") {
if let dictValue = NSDictionary(contentsOfFile: path) as? Dictionary<String, AnyObject> {
dictPlistFile=dictValue
}
}
return dictPlistFile
}
功能調用:
var Value=getPlistFile()?["Key"]
您可以在構建應用程序時使用PlistBuddy根據品牌更改密鑰的值
這是語法
/usr/libexec/PlistBuddy -c "Set :Key Value" plistfile.plist
使用詹金斯
我們可以在jenkins中有效地重用shell腳本
1.你必須使用Add Parameter ...在jenkins的shell腳本中參數化所有變量...就像在下面的截圖中我為一個變量做的那樣,你必須為所有其他變量做
2.在Build Step中選擇 Execute shell
3.復制基於配置啟動 創建構建和基於配置結束 創建構建之間的腳本並將其粘貼到Execute Shell中
注意:
資源規則
在通過非xcode接口構建和打包應用程序時,在某些版本中存在關於Xcode的ResourceRules的已知錯誤。
因此,它必須被運行一次去激活資源規則路徑驗證在Xcode .The資源規則路徑被棄用的功能和蘋果不接受自帶的資源規則的應用程序 ,但如果我們建立一個應用程序,而無需使用Xcode中驗證錯誤說法還沒有找到資源規則來反擊我們必須只運行一次腳本。
xcode_fix_PackageApplicationResourceRules.sh
#!/bin/sh
# A script to patch xcrun PackageInstallation so that it doesn't use the deprecated --resource-rules
# See "Do not use the --resource-rules flag or ResourceRules.plist. They have been obsoleted and will be rejected."
# under https://developer.apple.com/library/mac/technotes/tn2206/_index.html#//apple_ref/doc/uid/DTS40007919-CH1-TNTAG205
# Reported as Apple bug #19384243
#
# should be run as a user who can modify the PackageApplication file
xcodedir=$1
function usage {
# FIXME we cannot parse args properly because 2 are optional...
echo "USAGE: $0 xcodedir"
echo " xcodedir: an install dir like /Application/Xcode6.1.1.app"
}
if [[ $# -ne 1 ]]; then
echo "ERROR: invalid number of arguments"
usage
exit -1
fi
pi="$xcodedir/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/PackageApplication"
piorig="$piOrig"
if [[ ! -f "$pi" ]]; then
echo "$pi file not found. Invalid argument ?"
usage
exit -1
fi
grep resource-rules "$pi"
if [[ $? -ne 0 ]]; then
echo "PackageApplication doesn't use resource-rules. Skipping"
exit 0
fi
if [[ -f "$piorig" ]]; then
echo "Backup file $piorig already exist. Aborting"
exit -1
fi
perl -p -i'Orig' -e 'BEGIN{undef $/;} s/,resource-rules(.*sign}).*ResourceRules.plist"/$1/smg' "$pi"
echo $?
解鎖鑰匙串
每當您在終端中運行Branding.sh時,它都會提示用戶名和密碼作為其訪問系統密鑰鏈
每當您在jenkins中運行作業時,您將收到“ 不允許用戶交互 ”錯誤
所以要解決這個問題,你必須遵循以下步驟
供應配置文件
如果你發現 “ 找不到匹配的配置文件 ”,請確保雙擊並通過Xcode安裝它。
您安裝的那一刻,您將在〜/ Library / MobileDevice / Provisioning Profiles /中看到UUID.mobileprovision
此UUID是移動設備內部的值,表示已安裝配置文件。
我希望這可以幫助你
您需要在構建項目之前運行pod install
,以便CocoaPods 獲取 Jenkins工作Podfile
指定的Podfile
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.