1. 程式人生 > >MAC之Qt在Xcode8上編譯錯誤( 二)

MAC之Qt在Xcode8上編譯錯誤( 二)

升級成Xcode8之後Qt編譯之後經常會出現以下幾個錯誤,其中:

Project ERROR: Xcode not set up properly. You may need to confirm the license agreement by running /usr/bin/xcodebuild.

下面介紹另外幾個常見的錯誤和解決辦法:

錯誤1:

Project ERROR: Current iphonesimulator SDK version (10.0) is too old. Please upgrade Xcode.

明明已經是最新的SDK版本,但是在編譯的過程中還是會說版本不對,我也嘗試了最新版本的Qt,在官網下載了Qt 5.7,還是會有這個問題,這裡確實是Qt的配置檔案不對,需要修改“QT_DIR/5.7/ios/mkspecs/macx-ios-clang/features/sdk.prf”裡的內容,直接將:

lessThan(QMAKE_MAC_SDK_VERSION, "8.0"): \
    error("Current $$QMAKE_MAC_SDK SDK version ($$QMAKE_MAC_SDK_VERSION) is too old. Please upgrade Xcode.")

這句話刪除,不要修改QMAKE_MAC_SDK_VERSION的版本,8.0改成10.0貌似沒有用,還是直接刪了吧,前後diff的檔案如下:

192:features shirny$ diff sdk.prf sdk_bak.prf 
14a15,17
> lessThan(QMAKE_MAC_SDK_VERSION, "8.0"
): \ > error("Current $$QMAKE_MAC_SDK SDK version ($$QMAKE_MAC_SDK_VERSION) is too old. Please upgrade Xcode.") >

錯誤2:

先看看報錯,著實很無語:

xcodebuild build -scheme test  -sdk iphonesimulator  -configuration Debug  -destination "id=12.9 inch" -destination-timeout 1
Build settings from command line:
    SDKROOT = iphonesimulator10.0
xcodebuild: error: Unable to find a destination matching the provided destination specifier: { id:12.9 inch } Unsupported device specifier option. The device “My Mac” does not support the following options: id Please supply only supported device specifier options. Available destinations for the "test" scheme: { platform:iOS Simulator, id:B3F40C24-5D60-4E50-9752-72FCEBE12124, OS:10.0, name:iPad Air } { platform:iOS Simulator, id:0EC6E7D4-29AE-467E-8690-06F5562BCFF3, OS:10.0, name:iPad Air 2 } { platform:iOS Simulator, id:277E2258-C60B-4813-BE20-42B7698CEBE5, OS:10.0, name:iPad Pro (9.7 inch) } { platform:iOS Simulator, id:63A51897-9CA4-4F78-903B-5DB2D6DA1135, OS:10.0, name:iPad Pro (12.9 inch) } { platform:iOS Simulator, id:8D9B0429-EE0B-4F2A-88BD-863FF3363265, OS:10.0, name:iPad Retina } { platform:iOS Simulator, id:30B53E9C-785A-49B4-AECE-217CCFD1FA31, OS:10.0, name:iPhone 5 } { platform:iOS Simulator, id:E021930D-5D58-4C3E-B0C3-26C2BE7BA28E, OS:10.0, name:iPhone 5s } { platform:iOS Simulator, id:7008A8CE-1542-4E3B-8DFA-4D5FD81A6B73, OS:10.0, name:iPhone 6 } { platform:iOS Simulator, id:0FD3D8EB-F3FB-4D48-86C3-A92DFA3B1C6E, OS:10.0, name:iPhone 6 Plus } { platform:iOS Simulator, id:E455FB97-B46D-47FC-8559-573FF9572196, OS:10.0, name:iPhone 6s } { platform:iOS Simulator, id:400435BC-8C7D-42AF-92DD-7D79CE35A7D4, OS:10.0, name:iPhone 6s Plus } { platform:iOS Simulator, id:1E6768EC-132A-4997-9052-E1F189466081, OS:10.0, name:iPhone 7 } { platform:iOS Simulator, id:7447D592-68E5-44A6-9997-DCC65984EB92, OS:10.0, name:iPhone 7 Plus } { platform:iOS Simulator, id:60038664-3B47-4C86-BC52-5C762EFBEC66, OS:10.0, name:iPhone SE } Ineligible destinations for the "test" scheme: { platform:iOS Simulator, id:dvtdevice-DVTiOSDeviceSimulatorPlaceholder-iphonesimulator:placeholder, name:Generic iOS Simulator Device } make: *** [xcodebuild-debug-iphonesimulator] Error 70

關於iOS Simulator報錯了,修改方法:
進入“QT_DIR/5.7/ios/mkspecs/macx-ios-clang ”修改xcodebuild.mk
Replace:

IPHONESIMULATOR_GENERIC_DESTINATION := "id=$(shell xcrun simctl list devices | grep -E 'iPhone|iPad' | grep -v unavailable | perl -lne 'print $$1 if /((.*?))/' | tail -n 1)"

With:

IPHONESIMULATOR_GENERIC_DESTINATION := "id=$(shell xcrun simctl list devices | grep -E 'iPhone|iPad' | grep -v unavailable | awk 'match ($$0, /\(([A-F0-9\-]*\))/ ) { print substr ($$0, RSTART+1, RLENGTH-2) }' | tail -n 1)"

前後diff的檔案對比:

192:macx-ios-clang shirny$ diff xcodebuild.mk xcodebuild_bak.mk 
74c74
< IPHONESIMULATOR_GENERIC_DESTINATION := "id=$(shell xcrun simctl list devices | grep -E 'iPhone|iPad' | grep -v unavailable | awk 'match ($$0, /\(([A-F0-9\-]*\))/ ) { print substr ($$0, RSTART+1, RLENGTH-2) }' | tail -n 1)"
---
> IPHONESIMULATOR_GENERIC_DESTINATION := "id=$(shell xcrun simctl list devices | grep -E 'iPhone|iPad' | grep -v unavailable | perl -lne 'print $$1 if /\((.*?)\)/' | tail -n 1)"

你以為到這裡就結束了,最起碼我是這麼認為的。

錯誤3

The following build commands failed: CopyPNGFile Debug-iphonesimulator/Test01.app/Default-568h@2x.png Test01.xcodeproj/Default-568h@2x.png

這個錯誤還是Xcode8搞得鬼,原因就是系統有兩個xcrun檔案,產生了衝突,所以進入“/Applications/Xcode.app/Contents/Developer/usr/bin/”修改“copying”:
Replace:

my $PNGCRUSH = `xcrun -f pngcrush`;

With:

my $PNGCRUSH = `/usr/bin/xcrun -f pngcrush`;

到這裡我已經能編譯成功了

/usr/bin/codesign --force --sign - --timestamp=none /Users/shirny/build-test-iphonesimulator_clang_Qt_5_7_0_for_iOS-Debug/Debug-iphonesimulator/test.app
/Users/shirny/build-test-iphonesimulator_clang_Qt_5_7_0_for_iOS-Debug/Debug-iphonesimulator/test.app: replacing existing signature

** BUILD SUCCEEDED **

23:44:44: 程序"/usr/bin/make"正常退出。
23:44:44: Elapsed time: 00:02.

目前遇到的雷區就上面幾個,暫時先總結這些,有其他問題可以一起交流交流