当前位置:网站首页>App signature in flutter
App signature in flutter
2022-08-02 14:55:00 【shinechow】
First, create a keystore
1. Enter the command first:
keytool -genkey -v -keystore ./key.jks -keyalg RSA -keysize 2048 -validity 10000 -alias key
2. Enter relevant parameters as prompted, as shown in the following figure
Second, refer to the keystore (
1. Create a file named
that contains a reference to the keystore:
storePassword=The password entered in the key.jks file created in the first stepkeyPassword=password entered in the key.jks file created in the first stepkeyAlias=key //.jks file name, here we created key.jks, so it is keystoreFile=The storage path of the key.jks file created in the first step, such as: C:/Users//key.jks
Note:
- Keep the file private and do not put it in public source control; The path in
storeFile
is a relative path starting with
, so it is recommended to use an absolute path in order to prevent unnecessary errorsli>/android/app/
2. Configure the signature in gradle
Configure signing for your app by editing the
file
(1)Adddef keystorePropertiesFile = rootProject.file("key.properties")def keystoreProperties = new Properties()keystoreProperties.load(new FileInputStream(keystorePropertiesFile))signingConfigs {release {keyAlias keystoreProperties['keyAlias']keyPassword keystoreProperties['keyPassword']storeFile file(keystoreProperties['storeFile'])storePassword keystoreProperties['storePassword']}}(2) Modify buildTypesbuildTypes {release {signingConfig signingConfigs.releasendk{ // This part must be added, otherwise it may cause the successfully compiled release package to crash on the real machineabiFilters "armeabi-v7a"}}debug {ndk {//It should be added here, otherwise there will be problems with the debug package. The last three are optional. It is recommended to add x86 or some simulators will report errors.abiFilters "armeabi", "armeabi-v7a", "arm64-v8a", "x86"}}}
Note:
Therelease
package may crash in the real machine because the so file of l
causing "compatibility" issues on ibflutter
of arm64
was not introduced in the package.arm64
mobile phones.
The main problem is that the so library is referenced. The arm64cpu architecture is backward compatible, that is, the cpu of the arm64
architecture can use the arm32 .so
file.The real reason for the problem is when we reference the so library (the so library is referenced in the referenced third-party library).
Three, turn on obfuscation
Flutter does not enable Android obfuscation by default.
If you use a third-party Java or Android library, maybe you want to reduce the size of the apk file or prevent the code from being reversed.
Configuration Obfuscation
Create a /android/app/proguard-rules.pro
file and add the following rules:
#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.** { *; }Copy code
Note: The above configuration only confuses the Flutter engine library, any other library (such as Firebase) needs to add the corresponding rules.
Enable obfuscation/compression
Open the /android/app/build.gradle
file and locate the buildTypes
block.
Set minifyEnabled
and useProguard
to true
in the release
configuration, and then point the obfuscated file to the previous stepcreated file.
android {...buildTypes {release {signingConfig signingConfigs.releaseminifyEnabled trueuseProguard trueproguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'}}}
Fourth, build a release APK
If you complete the signing steps, the APK will be signed.
Using the command line:
cd
- Run
flutter build apk
(flutter build
will include the--release
option by default).
The packaged release APK is located at
.
5. Install the release APK on the device
Follow the steps below to install the APK built in the previous step on a connected Android device
- Connect your Android device to your computer with USB
- Run
cd
. - Run
flutter install
.
边栏推荐
猜你喜欢
随机推荐
MySQL知识总结 (八) InnoDB的MVCC实现机制
Tornado framework routing system introduction and (IOloop.current().start()) start source code analysis
1.RecyclerView是什么
vscode编译keil工程,烧录程序
spark资源调度和任务调度
Redis数据库相关指令
[ROS] (02) Create & compile ROS package Package
宝塔搭建PHP自适应懒人网址导航源码实测
使用flutter小记
ng-style:动态控制样式
原码、反码、补码和移码
MySQL知识总结 (六) MySQL调优
C语言日记 4 变量
安装使用——百家CMS微商城说明文档(2)
redis基础
Eslint规则大全
ConstraintLayout从入门到放弃
C语言sizeof和strlen的区别
c语言三子棋详解!!! (电脑智能下棋)(附上完整代码)
主存储器(二)