写点什么

Flutter 如何发布安卓应用?,flutter 文档发布组件

用户头像
Android架构
关注
发布于: 刚刚

替换应用图标

安卓提供了如下尺寸的图标配置文件,在 Flutter 项目下的 android/app/src/main/res 对应尺寸目录下可以应用图标文件。


替换启动页

应用启动页图片在 Flutter 项目下的 android/app/src/main/drawable 下的 launch_background.xml 配置文件中,默认是一个白色底,xml 问卷如下所示:


<?xml version="1.0" encoding="utf-8"?>


<layer-list xmlns:android="http://schemas.android.com/apk/res/android">


<item android:drawable="@android:color/white" />


<!-- <item>


<bitmap


android:gravity="center"


android:src="@mipmap/launch_image" />


</item> -->


</layer-list>


注释掉的部分可以用来设置启动页图片,需要注意部分机型的尺寸未必和启动页图片一致,因此可以设置启动页的背景色与启动页图片边缘一致。


<?xml version="1.0" encoding="utf-8"?>


<layer-list xmlns:android="http://schemas.android.com/apk/res/android">


<item android:drawable="@android:color/white" />


<item>


<bitmap


android:gravity="center"


android:src="@mipmap/launch_image" />


</item>


</layer-list>

设置访问权限

在 android/app/src 下的 AndroidManifest.xml(注意不是 src/profile 文件夹下的 AndroidManifest.xml 文件)文件中设置应用权限,如访问网络,相册,摄像头等。开发环境是在 android/src/debug 的 AndroidManifest.xml 中设置。下面是一个示例的文件:


<manifest xmlns:android="http://schemas.android.com/apk/res/android"


package="com.example.animation_demo">


<uses-permission android:name="android.permission.INTERNET"/>


<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>


<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>


<application


android:name="io.flutter.app.FlutterApplication"


android:label="动画演示"


android:icon="@mipmap/ic_launcher">


<activity


android:name=".MainActivity"


android:launchMode="singleTop"


android:theme="@style/LaunchTheme"


android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"


android:hardwareAccelerated="true"


android:windowSoftInputMode="adjustResize">


<intent-filter>


<action android:name="android.intent.action.MAIN"/>


<category android:name="android.intent.category.LAUNCHER"/>


</intent-filter>


</activity>


<!-- Don't delete the meta-data below.


This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->


<meta-data


android:name="flutterEmbedding"


android:value="2" />


</application>


</manifest>

配置版本发布参数

在 android/app/build.gradle 文件检查配置是否正确:


1.applicaitonId:应用唯一 AppId,如 com.lios.helloworld


2.versionCode:应用程序版本号


3.versionName:版本号字符串


4.minSdkVersion:指定最低的 API 级别


5.targetSdkVersion:指定应用程序设计运行的 API 级别


如下所示:


android {


compileSdkVersion 28


sourceSets {


main.java.srcDirs += 'src/main/kotlin'


}


lintOptions {


disable 'InvalidPackage'


}


defaultConfig {


// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).


applicationId "com.example.animation_demo"


minSdkVersion 16


targetSdkVersion 28


versionCode flutterVersionCode.toInteger()


versionName flutterVersionName


testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"


}


buildTypes {


release {


// TODO: Add your own signing config for the release build.


// Signing with the debug keys for now, so `flutter ru


《Android学习笔记总结+最新移动架构视频+大厂安卓面试真题+项目实战源码讲义》
浏览器打开:qq.cn.hn/FTe 免费领取
复制代码


n --release` works.


signingConfig signingConfigs.debug


}


}


}


这里面可以看到 versionCode 和 versionName 是从 flutterVersionCode 和 flutterVersionName 中引入的,其中这两个变量在 build.gradle 上面有定义。先从 local.properties 中读取,若没有再在该文件中定义,因此可以在 localProperties 中设置或在 build.gradle 中设置(优先取 local.properties 中的值)。


def flutterVersionCode = localProperties.getProperty('flutter.versionCode')


if (flutterVersionCode == null) {


flutterVersionCode = '1'


}


def flutterVersionName = localProperties.getProperty('flutter.versionName')


if (flutterVersionName == null) {


flutterVersionName = '1.0'


}

生成应用签名

创建 keystore,如果之前创建过了,在 key.properties 中引入即可。


#其中~/key.jks 是将 keystore 文件 key.jks 存储在~/目录下


keytool -genkey -v -keystore ~/key.jks -keyalg RSA -keysize 2048 -validity 10000 -alias key


按提示输入密码和组织信息即可。


输入密钥库口令:


再次输入新口令:


您的名字与姓氏是什么?


您的组织单位名称是什么?

用户头像

Android架构

关注

还未添加个人签名 2021.10.31 加入

还未添加个人简介

评论

发布
暂无评论
Flutter 如何发布安卓应用?,flutter文档发布组件