Flutter 疑难杂症集合

一. Flutter集成uni小程序sdk

1. 手机连接电脑测试打开uni小程序没问题,打包成apk后debug编译下的apk也没问题,但就是release编译的apk包打不开小程序。
报错情景:点击后页面会闪现一下黑色的背景,然后又跳转回了点击之前的页面。
原因:开启了混淆(minifyEnabled true)但又没有把混淆规则文件放入到指定的android目录中。
解决:
打开android/app/build.gradle文件
minifyEnabled 设置成false,或者把uni小程序sdk中的proguard.cfg文件放入到指定目录中。

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移除无用资源值不相同时有可能会导致编译报错。

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

你可能感兴趣的:(flutter)