Flutter 疑难杂症集合

一. Flutter集成uni小程序sdk

1. 手机连接电脑测试打开uni小程序没问题,打包成apk后debug编译下的apk也没问题,但就是release编译的apk包打不开小程序。

报错情景:点击后页面会闪现一下黑色的背景,然后又跳转回了点击之前的页面。

原因:开启了混淆(minifyEnabled true)但又没有把混淆规则文件放入到指定的android目录中。

解决:

打开android/app/build.gradle文件

minifyEnabled 设置成false,或者把uni小程序sdk中的proguard.cfg文件放入到指定目录中。

bash 复制代码
buildTypes {
        release {
        	// 注意点:minifyEnabled 混淆和shrinkResources移除无用资源需同时为true或false,否则可能导致编译失败!
            minifyEnabled false  //是否进行混淆
            shrinkResources false  //删除无用资源
            //指定混淆规则文件
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro', 'proguard.cfg'
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.debug
        }
    }

2. minifyEnabled 混淆和shrinkResources移除无用资源值不相同时有可能会导致编译报错。

bash 复制代码
landeMacBook-Pro:life_app lan$ flutter build apk


FAILURE: Build failed with an exception.

* Where:
Build file '/Users/lan/Desktop/flutter-demo/life_app/android/build.gradle' line: 25

* What went wrong:
A problem occurred evaluating root project 'android'.
> A problem occurred configuring project ':app'.
   > com.android.builder.errors.EvalIssueException: Removing unused resources requires unused code shrinking to be turned on. See http://d.android.com/r/tools/shrink-resources.html for more information.

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org
相关推荐
kirk_wang17 分钟前
Flutter艺术探索-PlatformView嵌入:在Flutter中显示原生View
flutter·移动开发·flutter教程·移动开发教程
ujainu18 分钟前
Flutter for OpenHarmony 悬浮操作按钮:FloatingActionButton 与扩展菜单的深度优化实践
android·flutter·组件
向哆哆20 分钟前
构建环保之旅:基于 Flutter × OpenHarmony 的垃圾回收个人成就应用
flutter·开源·鸿蒙·openharmony·开源鸿蒙
一起养小猫22 分钟前
Flutter for OpenHarmony 实战 文件存储与数据库操作完全指南
开发语言·jvm·数据库·spring·flutter·harmonyos
向哆哆1 小时前
Flutter × OpenHarmony 跨端实战:垃圾分类应用页面架构与数据结构设计详解
数据结构·flutter·开源·鸿蒙·openharmony
Mr__proto__1 小时前
Flutter 中使用 Autocomplete 实现智能模糊搜索加历史记录提示
flutter
lbb 小魔仙2 小时前
【Harmonyos】开源鸿蒙跨平台训练营DAY8:Flutter鸿蒙开发指南获取轮播图数据
flutter·华为·harmonyos
2501_944396192 小时前
Flutter for OpenHarmony 视力保护提醒App实战 - 性能优化技巧
android·flutter·性能优化
子春一2 小时前
Flutter for OpenHarmony:构建一个专业级 Flutter 节拍器,深入解析定时器、状态同步与音乐节奏交互设计
javascript·flutter·交互
kirk_wang2 小时前
Flutter艺术探索-Flutter插件开发:自定义Plugin实战指南
flutter·移动开发·flutter教程·移动开发教程