如何使用Proguard缩小Flutter应用程序? [英] How to minify a Flutter app with Proguard?
问题描述
我已经制作了Flutter应用.该发行版APK约为14MB.我搜索了一些方法以最小化此问题,并发现了以下几点: https://flutter.io/android-release /#enabling-proguard
I already made a Flutter app. The release apk is about 14MB. I searched methods to minify this and found this ons: https://flutter.io/android-release/#enabling-proguard
但是我的问题是,我如何才能知道我在步骤1中使用的所有其他库?是否有任何命令可以了解它们,或者仅仅是我添加到pubspec.yaml
的所有依赖项?
But my question is, how can I get to know all my used additional libraries for step 1? Are there any commands to know them or is it just all the dependencies that I added to the pubspec.yaml
?
如何我需要在该文件/android/app/proguard-rules.pro
中实施吗?
How do I need to implement them in this file /android/app/proguard-rules.pro
?
推荐答案
首先,我们将在构建文件中启用缩小和模糊处理.找到位于/android/app/
文件夹中的build.gradle
文件,并以粗体添加行
First, we will enable shrinking and obfuscation in the build file. Find build.gradle
file which sits inside /android/app/
folder and add lines in bold
android {
...
buildTypes {
release {
signingConfig signingConfigs.debug
minifyEnabled true
useProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
接下来,我们将创建一个配置,该配置将保留整个Flutter包装器代码.创建/android/app/proguard-rules.pro
文件并插入到其中:
Next we will create a configuration which will preserve entire Flutter wrapper code. Create /android/app/proguard-rules.pro
file and insert inside:
#Flutter Wrapper
-keep class io.flutter.app.** { *; }
-keep class io.flutter.plugin.** { *; }
-keep class io.flutter.util.** { *; }
-keep class io.flutter.view.** { *; }
-keep class io.flutter.** { *; }
-keep class io.flutter.plugins.** { *; }
这篇关于如何使用Proguard缩小Flutter应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!