Flutter Bug总结(持续更新)

image.png
Problem 1.上传App Store构建版本,上传成功,App Store Connect并不显示构建版本?

权限未配置齐全
升到iOS10之后,需要设置权限的有:
麦克风权限:Privacy - Microphone Usage Description 是否允许此App使用你的麦克风?
相机权限: Privacy - Camera Usage Description 是否允许此App使用你的相机?
相册权限: Privacy - Photo Library Usage Description 是否允许此App访问你的媒体资料库?
通讯录权限: Privacy - Contacts Usage Description 是否允许此App访问你的通讯录?
蓝牙权限:Privacy - Bluetooth Peripheral Usage Description 是否许允此App使用蓝牙?
语音转文字权限:Privacy - Speech Recognition Usage Description 是否允许此App使用语音识别?
日历权限:Privacy - Calendars Usage Description
定位权限:Privacy - Location When In Use Usage Description
定位权限: Privacy - Location Always Usage Description
位置权限:Privacy - Location Usage Description
媒体库权限:Privacy - Media Library Usage Description
健康分享权限:Privacy - Health Share Usage Description
健康更新权限:Privacy - Health Update Usage Description
运动使用权限:Privacy - Motion Usage Description
音乐权限:Privacy - Music Usage Description
提醒使用权限:Privacy - Reminders Usage Description
Siri使用权限:Privacy - Siri Usage Description
电视供应商使用权限:Privacy - TV Provider Usage Description
视频用户账号使用权限:Privacy - Video Subscriber Account Usage Description

Problem 2.上传App Store构建版本,上传成功,App Store Connect显示正在处理中,过一会版消失?

工程中引用权限插件有问题 预估为私有api访问 去除插件上传成功
权限处理插件
permission_handler: 2.1.2
提交应用到iTunes Connect时构建版本“正在处理”后直接消失——此构建版本无效

Problem 3.Flutter不在代码中设置不能抓包?

Flutter中http请求抓包解决方案

Problem 4.Error: Expected an identifier, but got ''. const

flutter clean

Problem 5.Flutter杂症( flutter packages pub run build_runner build )

--delete-conflicting-outputs
//清除之前生成的文件,如果直接运行下面的不行。可以先尝试运行这个
flutter packages pub run build_runner clean
//可以直接运行这个
flutter packages pub run build_runner build --delete-conflicting-outputs
Flutter杂症( flutter packages pub run build_runner build )

Problem 6.Flutter SocketException: Failed to create server socket (OS Error: Permission denied, errno = 13), address = 127.0.0.1, port = 0
Launching lib\main.dart on Android SDK built for x86 in debug mode...
Built build\app\outputs\apk\debug\app-debug.apk.
I/flutter ( 7011): Observatory server failed to start after 1 tries
I/flutter ( 7011): Observatory server failed to start after 2 tries
I/flutter ( 7011): Observatory server failed to start after 3 tries
I/flutter ( 7011): Observatory server failed to start after 4 tries
I/flutter ( 7011): Observatory server failed to start after 5 tries
I/flutter ( 7011): Observatory server failed to start after 6 tries
I/flutter ( 7011): Observatory server failed to start after 7 tries
I/flutter ( 7011): Observatory server failed to start after 8 tries
I/flutter ( 7011): Observatory server failed to start after 9 tries
I/flutter ( 7011): Observatory server failed to start after 10 tries
I/flutter ( 7011): Observatory server failed to start after 11 tries
I/flutter ( 7011): Could not start Observatory HTTP server:
I/flutter ( 7011): SocketException: Failed to create server socket (OS Error: Permission denied, errno = 13), address = 127.0.0.1, port = 0
I/flutter ( 7011): #0      _NativeSocket.bind (dart:io/runtime/bin/socket_patch.dart:591:7)
I/flutter ( 7011): <asynchronous suspension>
I/flutter ( 7011): #1      _RawServerSocket.bind (dart:io/runtime/bin/socket_patch.dart:1206:26)
I/flutter ( 7011): #2      _ServerSocket.bind (dart:io/runtime/bin/socket_patch.dart:1466:29)
I/flutter ( 7011): #3      ServerSocket.bind (dart:io/runtime/bin/socket_patch.dart:1457:26)
I/flutter ( 7011): #4      _HttpServer.bind (dart:_http/http_impl.dart:2520:25)
I/flutter ( 7011): #5      HttpServer.bind (dart:_http/http.dart:227:19)
I/flutter ( 7011): #6      Server.startup.poll (dart:vmservice_io/server.dart:355:36)
I/flutter ( 7011): <asynchronous suspension>
I/flutter ( 7011): #7      Server.startup (dart:vmservice_io/server.dart:367:23)
I/flutter ( 7011): <asynchronous suspension>
I/flutter ( 7011): #8      main (dart:vmservice_io/vmservice_io.dart:253:12)
I/flutter ( 7011): 
在android工程AndroidManifest.xml配置
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
image.png
Problem 6.Flutter在安卓部分真机上不显示图标(显示为flutter icon)

安卓系统图标缓存问题 切换主题即可 (究极大法:出厂重置)

Problem 7.Flutter项目中在代码端判断当前运行模式并取不同的url地址
static String initHost() {

    const String inProduction = const String.fromEnvironment("dart.vm.product");

    if (inProduction == "true") {
      // 线上地址
    } else if (inProduction == "false") {
      // 线下地址
    } else {
      // 测试地址
    }
  }
Problem 8.如何将Flutter应用程序迁移到AndroidX

Flutter应用程序迁移到AndroidX
https://flutter.dev/docs/development/packages-and-plugins/androidx-compatibility

Problem 9.
    Building App.framework for arm64...
    Building AOT snapshot in release mode (ios-release)...             33.2s
    Built to build/aot/.
    Snapshotting (IOSArch.armv7) exited with non-zero exit code: 1
    Snapshotting (IOSArch.arm64) exited with non-zero exit code: 0
    cp: build/aot/App.framework: No such file or directory
    error: cannot parse the debug map for 'build/aot/App.framework/App': No such file or directory
    Failed to generate debug symbols (dSYM) file for build/aot/App.framework/App.

在之前版本构建flutter是成功的,但是我在升级Xcode11-beta macOS10.15时构建发生过以上错误

解决:Xcode-Architectures-Valid Architectures- armv7

Problem 10.Flutter打包iOS上传App Store报错是因为framework 包含了x86_64, i386 架构,这个是苹果不允许的
App Store Connect Operation Error
Communication error. Please use diagnostic mode to check connectivity. You need to have outbound access to TCP port 443.

App Store Connect Operation Error
ERROR ITMS-90087: "Unsupported Architectures. The executable for Runner.app/Frameworks/Flutter.framework contains unsupported architectures '[x86_64]'."

App Store Connect Operation Error
ERROR ITMS-90209: "Invalid Segment Alignment. The app binary at 'Runner.app/Frameworks/Flutter.framework/Flutter' does not have proper segment alignment. Try rebuilding the app with the latest Xcode version."

App Store Connect Operation Error
ERROR ITMS-90125: "The binary is invalid. The encryption info in the LC_ENCRYPTION_INFO load command is either missing or invalid, or the binary is already encrypted. This binary does not seem to have been built with Apple's linker."

App Store Connect Operation Warning
WARNING ITMS-90080: "The executable 'Payload/Runner.app/Frameworks/Flutter.framework' is not a Position Independent Executable. Please ensure that your build settings are configured to create PIE executables. For more information refer to Technical Q&A QA1788 - Building a Position Independent Executable in the iOS Developer Library."
WX20200702-131749.png
APP_PATH="${TARGET_BUILD_DIR}/${WRAPPER_NAME}"

# This script loops through the frameworks embedded in the application and
# removes unused architectures.
find "$APP_PATH" -name '*.framework' -type d | while read -r FRAMEWORK
do
FRAMEWORK_EXECUTABLE_NAME=$(defaults read "$FRAMEWORK/Info.plist" CFBundleExecutable)
FRAMEWORK_EXECUTABLE_PATH="$FRAMEWORK/$FRAMEWORK_EXECUTABLE_NAME"
echo "Executable is $FRAMEWORK_EXECUTABLE_PATH"

EXTRACTED_ARCHS=()

for ARCH in $ARCHS
do
echo "Extracting $ARCH from $FRAMEWORK_EXECUTABLE_NAME"
lipo -extract "$ARCH" "$FRAMEWORK_EXECUTABLE_PATH" -o "$FRAMEWORK_EXECUTABLE_PATH-$ARCH"
EXTRACTED_ARCHS+=("$FRAMEWORK_EXECUTABLE_PATH-$ARCH")
done

echo "Merging extracted architectures: ${ARCHS}"
lipo -o "$FRAMEWORK_EXECUTABLE_PATH-merged" -create "${EXTRACTED_ARCHS[@]}"
rm "${EXTRACTED_ARCHS[@]}"

echo "Replacing original executable with thinned version"
rm "$FRAMEWORK_EXECUTABLE_PATH"
mv "$FRAMEWORK_EXECUTABLE_PATH-merged" "$FRAMEWORK_EXECUTABLE_PATH"

done
Problem 11.如果Flutter检测到您的项目不支持Xcode 11.4及其以上,则可能会转到此。

https://flutter.dev/docs/development/ios-project-migration

Building for iOS, but the linked and embedded framework 'App.framework' was built for iOS Simulator.
Building for iOS Simulator, but the linked and embedded framework 'App.framework' was built for iOS.

根据文档提示进行就可以,在这里我要提醒注意两点,
1.删除App.framework 和Flutter.framework 不要彻底删除,删除引用即可
2.第五步,如果已经存在Flutter 或者 "Flutter" 不需要执行这一步

推荐阅读更多精彩内容