首页 > 解决方案 > 在颤振中构建不成功

问题描述

当我尝试 flutter build apk --release 时,出现以下错误

FAILURE: Build failed with an exception.                                

* Where:                                                                
Build file 

'/Users/flutter/Documents/project_name/android/
build.gradle' line: 27

* What went wrong:                                                      
A problem occurred evaluating root project 
'android'.                   
> A problem occurred configuring project ':app'.                        
> 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                              

BUILD FAILED in 33s   

当我为 ios 构建时,我得到了输出。但尺寸非常大,大约 400 mb。

如何解决所有这些问题......

标签: androidiosflutter

解决方案


不确定是什么问题,但根据错误日志,您必须从代码中删除所有未使用的资源,然后您必须在 gradle 中进行设置。

android {
...
buildTypes {
    release {
        shrinkResources true
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'),
                'proguard-rules.pro'
    }
}}

此外,如果您将删除未使用的资源,它将减少 iOS 构建的大小。

快乐的编码...


推荐阅读