欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

如何使用Flutter發(fā)布安卓應(yīng)用

 更新時間:2021年05月17日 10:23:11   作者:島上碼農(nóng)  
應(yīng)用開發(fā)完了,當(dāng)然需要發(fā)布了,下面來看看用 Flutter 開發(fā)的應(yīng)用如何發(fā)布,本文只關(guān)注 Android 版本的發(fā)布

設(shè)置應(yīng)用的名稱,包名、應(yīng)用圖標(biāo)和啟動

安卓的應(yīng)用資源配置在main/AndroidManifest.xml中設(shè)置,文件內(nèi)容如下:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.gesture_demo">
    <!-- io.flutter.app.FlutterApplication is an android.app.Application that
         calls FlutterMain.startInitialization(this); in its onCreate method.
         In most cases you can leave this as-is, but you if you want to provide
         additional functionality it is fine to subclass or reimplement
         FlutterApplication and put your custom class here. -->
    <application
        android:name="io.flutter.app.FlutterApplication"
        android:label="gesture_demo"
        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>

Flutter生成的文件建議是大部分內(nèi)容可以保留不動,但是可以根據(jù)需要進行修改。
具體可能要修改的內(nèi)容如下:

屬性名 用途 說明
package 應(yīng)用包名 安卓應(yīng)用的唯一標(biāo)識符,一般為com.xxxx.xxx格式
android:label 應(yīng)用顯示名稱 默認(rèn)為工程名,需要根據(jù)實際情況修改
android:icon 應(yīng)用圖標(biāo) 替換指定的圖標(biāo)文件即可
meta-data
   android:name
資源名稱 不可更改,用于Flutter生成安卓插件
meta-data
  value
資源值 不可更改,用于Flutter生成安卓插件

替換應(yīng)用圖標(biāo)

安卓提供了如下尺寸的圖標(biāo)配置文件,在Flutter項目下的android/app/src/main/res對應(yīng)尺寸目錄下可以應(yīng)用圖標(biāo)文件。

尺寸別名 圖標(biāo)大小 屏幕尺寸
mipmap-mdpi 48x48 320×480
mipmap-hdpi 72x72 480×800,480×854
mipmap-xhdpi 96x96 1280*720,720p
mipmap-xxhdpi 144x144 1920*1080,1080p
mipmap-xxxhdpi 192x192 3840×2160,4k

替換啟動頁

應(yīng)用啟動頁圖片在Flutter項目下的android/app/src/main/drawable下的launch_background.xml配置文件中,默認(rèn)是一個白色底,xml問卷如下所示:

<?xml version="1.0" encoding="utf-8"?>
<!-- Modify this file to customize your launch splash screen -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@android:color/white" />

    <!-- You can insert your own image assets here -->
    <!-- <item>
        <bitmap
            android:gravity="center"
            android:src="@mipmap/launch_image" />
    </item> -->
</layer-list>

注釋掉的部分可以用來設(shè)置啟動頁圖片,需要注意部分機型的尺寸未必和啟動頁圖片一致,因此可以設(shè)置啟動頁的背景色與啟動頁圖片邊緣一致。

<?xml version="1.0" encoding="utf-8"?>
<!-- Modify this file to customize your launch splash screen -->
<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>

設(shè)置訪問權(quán)限

在android/app/src下的AndroidManifest.xml(注意不是src/profile文件夾下的AndroidManifest.xml文件)文件中設(shè)置應(yīng)用權(quán)限,如訪問網(wǎng)絡(luò),相冊,攝像頭等。開發(fā)環(huán)境是在android/src/debug的AndroidManifest.xml中設(shè)置。下面是一個示例的文件:

<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>

配置版本發(fā)布參數(shù)

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

  1. applicaitonId:應(yīng)用唯一AppId,如com.lios.helloworld
  2. versionCode:應(yīng)用程序版本號
  3. versionName:版本號字符串
  4. minSdkVersion:指定最低的API級別
  5. targetSdkVersion:指定應(yīng)用程序設(shè)計運行的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 run --release` works.
            signingConfig signingConfigs.debug
        }
    }
}

這里面可以看到versionCode和versionName是從flutterVersionCode和flutterVersionName中引入的,其中這兩個變量在build.gradle上面有定義。先從local.properties中讀取,若沒有再在該文件中定義,因此可以在localProperties中設(shè)置或在build.gradle中設(shè)置(優(yōu)先取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'
}

生成應(yīng)用簽名

創(chuàng)建keystore,如果之前創(chuàng)建過了,在key.properties中引入即可。

#其中~/key.jks是將keystore文件key.jks存儲在~/目錄下
keytool -genkey -v -keystore ~/key.jks -keyalg RSA -keysize 2048 -validity 10000 -alias key

按提示輸入密碼和組織信息即可。

輸入密鑰庫口令:  
再次輸入新口令: 
您的名字與姓氏是什么?
  [Unknown]:  lag
您的組織單位名稱是什么?
  [Unknown]:  island-coder
您的組織名稱是什么?
  [Unknown]:  RD
您所在的城市或區(qū)域名稱是什么?
  [Unknown]:  Coder
您所在的省/市/自治區(qū)名稱是什么?
  [Unknown]:  Island
該單位的雙字母國家/地區(qū)代碼是什么?
  [Unknown]:  CN
CN=lag, OU=island-coder, O=RD, L=Coder, ST=Island, C=CN是否正確?
  [否]:  Y

正在為以下對象生成 2,048 位RSA密鑰對和自簽名證書 (SHA256withRSA) (有效期為 10,000 天):
	 CN=lag, OU=island-coder, O=RD, L=Coder, ST=Island, C=CN
[正在存儲/Users/lag/key.jks]

在android目錄下創(chuàng)建一個key.properties文件,用于引用密鑰庫信息:

storePassword={密鑰庫密碼} #
keyPassword={證書密碼}
keyAlias=key    #對應(yīng)命令行的-alias后的別名
storeFile=/Users/lag/key.jks  #對應(yīng)命令生成的key.jks的據(jù)對路徑

修改配置文件

在build.gradle文件中,在android下增加以下內(nèi)容:

	signingConfigs {
        release {
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile = file(keystoreProperties['storeFile'])
            storePassword = keystoreProperties['storePassword']
        }
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.release
            
        }
    }

打包

在項目目錄下,運行下面的命令:

flutter build apk

默認(rèn)按release打包,生成的apk在build.app/outputs/apk/app-release.apk下。

注意事項

修改AndroidManifest.xml文件后,flutter打包可能存在緩存,此時運行下面的命令,清除掉緩存再次打包即可。

flutter clean

以上就是如何使用Flutter發(fā)布安卓應(yīng)用的詳細(xì)內(nèi)容,更多關(guān)于Flutter發(fā)布安卓應(yīng)用的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • Android中Volley框架下保持會話方法

    Android中Volley框架下保持會話方法

    這個是基于session的一個網(wǎng)絡(luò)會話,手機app給服務(wù)器發(fā)送登陸請求的時候,服務(wù)器返回的網(wǎng)絡(luò)response(networkRespone)的頭(head)里面存放著你想要的sessionid。這篇文章主要介紹了Android中Volley框架下保持會話方法的相關(guān)資料,需要的朋友可以參考下
    2016-11-11
  • Android利用CircleImageView實現(xiàn)圓形頭像的方法

    Android利用CircleImageView實現(xiàn)圓形頭像的方法

    這篇文章主要介紹了Android利用CircleImageView實現(xiàn)圓形頭像的方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-10-10
  • Android WebView的使用方法總結(jié)

    Android WebView的使用方法總結(jié)

    這篇文章主要介紹了 Android WebView的使用方法總結(jié)的相關(guān)資料,功能有指定網(wǎng)頁打開,跳轉(zhuǎn)網(wǎng)頁,傳值等,需要的朋友可以參考下
    2017-07-07
  • Android編程實現(xiàn)自定義PopupMenu樣式示例【顯示圖標(biāo)與設(shè)置RadioButton圖標(biāo)】

    Android編程實現(xiàn)自定義PopupMenu樣式示例【顯示圖標(biāo)與設(shè)置RadioButton圖標(biāo)】

    這篇文章主要介紹了Android編程實現(xiàn)自定義PopupMenu樣式功能,結(jié)合實例形式分析了Android顯示圖標(biāo)與設(shè)置RadioButton圖標(biāo)相關(guān)操作技巧,需要的朋友可以參考下
    2017-01-01
  • Android中關(guān)于自定義相機預(yù)覽界面拉伸問題

    Android中關(guān)于自定義相機預(yù)覽界面拉伸問題

    這篇文章主要為大家詳細(xì)介紹了Android中關(guān)于自定義相機預(yù)覽界面拉伸問題,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-02-02
  • Android OpenGL仿自如APP裸眼3D效果詳解

    Android OpenGL仿自如APP裸眼3D效果詳解

    之前自如團隊發(fā)布了一個自如客APP裸眼3D效果的實現(xiàn)。本文將通過Android OpenGL實現(xiàn)這一裸眼3D效果,文中的示例代碼講解詳細(xì),感興趣的可以學(xué)習(xí)一下
    2022-01-01
  • Android編程讀取sd卡中圖片的方法

    Android編程讀取sd卡中圖片的方法

    這篇文章主要介紹了Android讀取sd卡中圖片的方法,涉及Android權(quán)限操作,目錄及文件操作的相關(guān)技巧,非常簡單實用,需要的朋友可以參考下
    2016-04-04
  • 你該知道的Gradle配置知識總結(jié)

    你該知道的Gradle配置知識總結(jié)

    這篇文章主要給大家介紹了關(guān)于Gradle配置的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對各位Android開發(fā)者們具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考學(xué)習(xí),下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。
    2017-10-10
  • Android開發(fā)自學(xué)筆記(六):聲明權(quán)限和Activity

    Android開發(fā)自學(xué)筆記(六):聲明權(quán)限和Activity

    這篇文章主要介紹了Android開發(fā)自學(xué)筆記(六):聲明權(quán)限和Activity,本文是上一篇的補充,需要的朋友可以參考下
    2015-04-04
  • Android通過GPS獲取定位的流程步驟

    Android通過GPS獲取定位的流程步驟

    這篇文章主要給大家簡單介紹一下Android如何通過GPS獲取定位的方式,文中有詳細(xì)的流程步驟和代碼示例,介紹的非常詳細(xì),需要的朋友可以參考下
    2023-07-07

最新評論