前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Flutter 开发出现的那些 Bugs 和解决方案「持续更新... 」

Flutter 开发出现的那些 Bugs 和解决方案「持续更新... 」

作者头像
Jimmy_is_jimmy
发布2022-09-16 14:38:18
9500
发布2022-09-16 14:38:18
举报
文章被收录于专栏:call_me_R

记录 Flutter 开发过程中遇到的一些问题和相关的解决方案~

1. --no-sound-null-safety 错误 on vscode

上面是VSCode编辑器中空校验错误。解决方案如下:

代码语言:javascript
复制
// vscode 编辑器项目根目录中创建文件 .vscode/launch.json
// 添加内容
"args": [
  "--no-sound-null-safety"
]

// 完整的文件代码示例
{
  "configurations":[
    {
      "name": "jimmy flutter demo",
      "program": "lib/main.dart",
      "request": "launch",
      "type": "dart",
      "args": [
        "--no-sound-null-safety"
      ]
    }
  ]
}

// 之后重新运行项目即可

2. 设置 flutter_screenutil 报错

直接引用包 flutter_screenutil 去使用,会报错使用不了 ScreenUtil().setWidth(width) 等方法。

这个错误就是我们并没有按照官网进行使用。需要根据官网逐步进行。

这里我使用方式一 -- 在app中使用它一次。

代码语言:javascript
复制
void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    //填入设计稿中设备的屏幕尺寸,单位dp
    return ScreenUtilInit(
      designSize: const Size(360, 690),
      minTextAdapt: true,
      splitScreenMode: true,
      builder: (context , child) {
        return MaterialApp(
          debugShowCheckedModeBanner: false,
          title: 'First Method',
          // You can use the library anywhere in the app even in theme
          theme: ThemeData(
            primarySwatch: Colors.blue,
            textTheme: Typography.englishLike2018.apply(fontSizeFactor: 1.sp),
          ),
          home: child,
        );
      },
      child: const HomePage(title: 'First Method'),
    );
  }
}

3. 构建安卓应用包出错

在应用开发完成之后,构建安卓的图标文件,可能会出现报错:

代码语言:javascript
复制
✗ ERROR: InvalidConfigException 
Cannot not find minSdk from android/app/build.gradle or android/local.propertiesSpecify minSdk in either android/app/build.gradle or android/local.properties
#0      createIconsFromConfig (package:flutter_launcher_icons/main.dart:96:7)
#1      createIconsFromArguments (package:flutter_launcher_icons/main.dart:60:7)
#2      main (file:///Users/jimmy/Documents/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_launcher_icons-0.9.3/bin/main.dart:7:26)
#3      _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:295:32)
#4      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:192:12)

可以在android/local.properties文件中添加内容:

代码语言:javascript
复制
flutter.versionName=1.0.0
flutter.versionCode=1
flutter.minSdkVersion=30

在应用开发完成之后,针对安卓应用去打包,可能会出现报错:

Execution failed for task ':app:processReleaseMainManifest'. Manifest merger failed : uses-sdk:minSdkVersion 16 cannot be smaller than version 21 declared in library

这是因为minSdkVersion的问题,我们更改下相关的文件版本即可:

代码语言:javascript
复制
// 解决方案
// android/app/build.gradle

defaultConfig {
        // // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        // applicationId "com.example.jimmy_flutter_demo"
        // // You can update the following values to match your application needs.
        // // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
        // minSdkVersion flutter.minSdkVersion
        // targetSdkVersion flutter.targetSdkVersion
        // versionCode flutterVersionCode.toInteger()
        // versionName flutterVersionName
        
        applicationId "com.example.jimmy_flutter_demo"
        minSdkVersion 21 // 更改最小的版本
        targetSdkVersion 31
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

如果构建成功,你会看到输出目录提示内容类似下面:

代码语言:javascript
复制
✓  Built build/app/outputs/flutter-apk/app-armeabi-v7a-release.apk (7.5MB).

目前暂时遇到这些Bug,后续会持续更新... 欢迎关注收藏

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022-07-30,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 1. --no-sound-null-safety 错误 on vscode
  • 2. 设置 flutter_screenutil 报错
  • 3. 构建安卓应用包出错
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档