Flutter 编译时的权限问题

编译运行 Flutter iOS 项目时,如果报权限相关的问题,类似下面的错误:

`flutter run` 输出的错误信息
Launching lib/main.dart on iPhone Xʀ in debug mode...
Running pod install...                                              0.9s
Running Xcode build...                                                  
 ├─Assembling Flutter resources...                           5.3s
 └─Compiling, linking and signing...                         2.3s
Xcode build done.                                            9.1s
Failed to build iOS app
Error output from Xcode build:
↳
    ** BUILD FAILED **


Xcode's output:
↳
    mkdir -p /Users/yrom/Downloads/test1/build/ios/Debug-iphonesimulator/Runner.app/Frameworks
    rsync --delete -av --filter P .*.?????? --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter
    "- Modules" "/Users/yrom/Downloads/test1/.ios/Pods/../Flutter/engine/Flutter.framework"
    "/Users/yrom/Downloads/test1/build/ios/Debug-iphonesimulator/Runner.app/Frameworks"
    building file list ... done
    Flutter.framework/
    Flutter.framework/Flutter
    Flutter.framework/Info.plist
    Flutter.framework/icudtl.dat
    Flutter.framework/_CodeSignature/
    Flutter.framework/_CodeSignature/CodeResources

    sent 94440045 bytes  received 120 bytes  62960110.00 bytes/sec
    total size is 94428117  speedup is 1.00
    Stripped /Users/yrom/Downloads/test1/build/ios/Debug-iphonesimulator/Runner.app/Frameworks/Flutter.framework/Flutter of architectures: armv7 arm64
    Code Signing /Users/yrom/Downloads/test1/build/ios/Debug-iphonesimulator/Runner.app/Frameworks/Flutter.framework with Identity -
    /usr/bin/codesign --force --sign -  --preserve-metadata=identifier,entitlements
    '/Users/yrom/Downloads/test1/build/ios/Debug-iphonesimulator/Runner.app/Frameworks/Flutter.framework'
    /Users/yrom/Downloads/test1/build/ios/Debug-iphonesimulator/Runner.app/Frameworks/Flutter.framework: replacing existing signature
    /Users/yrom/Downloads/test1/build/ios/Debug-iphonesimulator/Runner.app/Frameworks/Flutter.framework: Permission denied
    Command PhaseScriptExecution failed with a nonzero exit code
    note: Using new build systemnote: Planning buildnote: Constructing build description

Could not build the application for the simulator.
Error launching application on iPhone Xʀ.

该问题很有可能是 1.9 版本的问题,根据 issue #40146 中的回答,可通过修改文件 $FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh 以修正该错误:

--- a/packages/flutter_tools/bin/xcode_backend.sh
+++ b/packages/flutter_tools/bin/xcode_backend.sh
@@ -141,7 +141,7 @@ BuildApp() {
     mkdir "${derived_dir}/engine"
     RunCommand cp -r -- "${flutter_podspec}" "${derived_dir}/engine"
     RunCommand cp -r -- "${flutter_framework}" "${derived_dir}/engine"
-    RunCommand find "${derived_dir}/engine/Flutter.framework" -type f -exec chmod a-w "{}" \;
+    RunCommand find "${derived_dir}/engine/Flutter.framework" -type f -iname '.h' -exec chmod a-w "{}" \;
   else
     RunCommand rm -rf -- "${derived_dir}/Flutter.framework"
     RunCommand cp -r -- "${flutter_framework}" "${derived_dir}"

相关资源