1 去除Debug 标签
问题:默认创建的Flutter应用运行时,屏幕右上角会带Debug标签
解决:在MyApp的build方法中设置debugShowCheckedModeBanner
属性为false
。
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
...
);
}
}
...
2 运行程序报错Error connection to the service protocol
Launching lib/main.dart on Android SDK built for x86 in debug mode...
Running Gradle task 'assembleDebug'...
......
Error connecting to the service protocol: failed to connect to http://127.0.0.1:52037/VrXq5vhCjj4=/
解决:
- 第一种情况,Android模拟器
坚持自己的模拟器所使用的Android SDK版本,然后通过Tools -> SDKManager 下载匹配的platform版本。 - 第二种情况,iOS真机。 iOS13.3.1不支持真机调试,但是不影响Release。所以如果是这个版本的真机没法进行调试。
3 Android toolchain 报错
$ flutter doctor
...
[!] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
• Android SDK at /Users/jiafujia/Library/Android/sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-28, build-tools 28.0.3
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)
✗ Android license status unknown.
Try re-installing or updating your Android SDK Manager.
See https://developer.android.com/studio/#downloads or visit https://flutter.dev/setup/#android-setup for detailed instructions.
...
解决: 通过flutter doctor --android-licenses
查看原因,根据提示信息解决。有可
$ flutter doctor --android-licenses
4 iOS无法真机测试
$ flutter upgrade
$ flutter clean
$ flutter build ios
5 iOS模拟器测试报错
Building for iOS Simulator, but the linked and embedded framework 'App.framework' was built for iOS. (in target 'Runner' from project 'Runner')
这是因为真机测试之后,会生成 ios -> Flutter -> App.framework, 而在iOS中构建的真机动态库和模拟器动态库是不一样的。因此我们无法同时在iOS模拟器和真机测试。
在切换iOS真机和模拟器时,我们需要先手动删除 App.framework这个文件夹,然后重新build,如果是真机测试,build方式 flutter build ios
. 如果是模拟器如下:
$ flutter devices
1 connected device:
iPhone 11 Pro Max • F7B8BFE6-0E23-4777-826F-A132D8A155C2 • ios • com.apple.CoreSimulator.SimRuntime.iOS-13-4 (simulator)
$ flutter run -d F7B
这样就可以在模拟器上进行测试了。
持续更新中...