Flutter-安卓打包流程
### 一、使用终端命令生成key
```sh
keytool -genkey -v -keystore key.jks -keyalg RSA -keysize 2048 -validity 10000 -alias key
```
![image](http://uploads.liqingsong.cc/20240313/0af7acf5-e6fc-4c33-b3c7-e98ac18e6d23.png)
> 将生成的 `key.jks` 文件放置到如下图位置
![image](http://uploads.liqingsong.cc/20240313/62a35a00-bfe8-4bb6-b0d0-c46a94f732aa.png)
> 注意:这里的`key.jks`前面的`key`就是你`.jks`文件的名称 可修改的
### 二、在Android目录下创建 `key.properties`
> key.properties文件中需要输入以下内容:
```sh
storePassword=<生成keystore时设置的密码>
keyPassword=<生成keystore时设置的密码>
keyAlias=<生成keystore时的别名>
storeFile=<生成文件的key.jks的文件路径>
```
![image](http://uploads.liqingsong.cc/20240313/ee479f62-3498-4b52-8335-8e57235715d2.png)
### 三、app的`build.gradle`中配置
#### 添加配置1(位置如图)
```sh
def keystorePropertiesFile = rootProject.file("key.properties")
def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
```
![image](http://uploads.liqingsong.cc/20240313/ac1c13f5-a02a-4b90-a282-8d65ae197968.png)
#### 添加配置2(重要,位置如图)
```sh
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile file(keystoreProperties['storeFile'])
storePassword keystoreProperties['storePassword']
}
}
buildTypes {
release {
minifyEnabled false
shrinkResources false
signingConfig signingConfigs.release
}
}
```
> 注意: ` signingConfigs`必须在`buildTypes`前
> 原来是有 `buildTypes`,把以前的这个 `buildTypes`删除,替换上面的 `buildTypes`和` signingConfigs`配置
![image](http://uploads.liqingsong.cc/20240313/dabb31cb-b413-43eb-be08-5b7013bf20f0.png)
### 四、执行`flutter build apk `
```sh
flutter build apk
flutter build apk --release (推荐)
```
![image](http://uploads.liqingsong.cc/20240313/e90ff9db-a10b-4c07-9954-3d6b97598800.png)
### Flutter 打包APP,正式上线遇到的问题
#### 1、The connection errored: Failed host lookup: 'rap2api.taobao.org' This indicates an error..... ,或访问远程图片不显示
> 是因为没有配置网络权限,在android/app/src/main/AndroidManifest.xml中manifest标签中配置一下权限(如图):
```sh
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
```
![image](http://uploads.liqingsong.cc/20240313/6d447fbb-6506-4292-8247-95d1d2884f5b.png)