ก๊วนซอฟท์แวร์ </softganz> SoftGang (Gang Software)

Web &amp; Software Developer Gang.

Flutter App Guide

by Little Bear @13 ส.ค. 68 10:06 ( IP : 171...39 ) | Tags : Flutter , App

Create new app

flutter create --org com.yourdomain appname

Change app version

File: pubspec.yaml

version: 1.0.00+1

Create app icon

Add dependencie in file pubspec.yaml

dependencies:
...
flutterlaunchericons: ^0.14.4
And add
flutterlaunchericons:
 imagepath: "assets/icons/logo512.png"
  android: true
  ios: true
  removealphaios: true

Then run command in terminal

# dart run flutterlaunchericons:main

เอาคำว่า "DEBUG" ของเธอคืนไป

ใส่ไว้ใน MaterialApp

debugShowCheckedModeBanner: false

Change AndroidManifest.xml

File: android/app/src/main/AndroidManifest.xml

Change from

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

To

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:dist="http://schemas.android.com/apk/distribution"
    >

Add permission

File: android/app/src/main/AndroidManifest.xml

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESSNETWORKSTATE" />
    <uses-permission android:name="android.permission.WRITEEXTERNALSTORAGE" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.ACCESSFINELOCATION" />
    <uses-permission android:name="android.permission.ACCESSCOARSELOCATION" />
    <uses-feature android:name="android.hardware.camera" />

Change app label

File: android/app/src/main/AndroidManifest.xml

        android:label="My App"

InAppWebView

Add InAppWebView provider

        <provider
            android:name="com.pichillilorenzo.flutterinappwebviewandroid.InAppWebViewFileProvider"
            android:authorities="${applicationId}.flutterinappwebviewandroid.fileprovider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILEPROVIDERPATHS"
                android:resource="@xml/provider_paths" />
        </provider>

Flutter command

Clean

flutter clean

Get

flutter pub get

Run release

flutter run --release

Add dependencies แล้ว แต่ import package ไม่ได้

flutter packages get
Close project and re-open project

Build app for Play Store

Generate JKS file : ถ้ายังไม่มีการสร้างไฟล์ .jks ให้สร้างขึ้นมาก่อน

keytool -genkey -v -keystore /Users/name/appname.jks -keyalg RSA -keysize 2048 -validity 10000 -alias release
ดูข้อมูลในไฟล์ .jks
keytool -v -list -keystore appname.jks
ดูข้อมูลในไฟล์ .apk
keytool -printcert -jarfile appname.apk

#กำหนดการ keystore ไว้ใน app สร้างไฟล์ [project]/android/key.properties แล้ว copy code ด้านล่างไปใส่

storePassword=<password from previous step>
keyPassword=<password from previous step>
keyAlias=upload
storeFile=<location of the key store file, such as /Users/<user name>/upload-keystore.jks>

คำเตือน เก็บรักษาไฟล์ key.properties ไว้ให้ดี อย่างส่งขึ้น git เด็ดขาด

กำหนดค่าเพื่อ signing ใน gradle

1.แก้ไขไฟล์ [project]/android/app/build.gradle.kts

import java.util.Properties
import java.io.FileInputStream
val keyProperties = Properties().apply {
    val file = rootProject.file("key.properties")
    if (file.exists()) {
        load(FileInputStream(file))
    }
}

android { ... }

2.หา buildTypes

   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
       }
   }
แทนที่ด้วย
    signingConfigs {
        create("release") {
            keyAlias = keyProperties["keyAlias"] as String
            keyPassword = keyProperties["keyPassword"] as String
            storeFile = keyProperties["storeFile"]?.let { file(it) }
            storePassword = keyProperties["storePassword"] as String
        }
        // You can also create other signing configs like "debug" if needed
    }
    buildTypes {
        release {
            signingConfig = signingConfigs.getByName("release")
            // signingConfig signingConfigs.release
        }
    }

Build

flutter build appbundle

ผลลัพท์ของการ build จะอยู่ที่

build/app/outputs/bundle/release/app-release.aab

ติดขั้นตอนอัพโหลดขึ้น play store

"Your Android App Bundle is signed with the wrong key. Ensure that your App Bundle is signed with the correct signing key and try again. Your App Bundle is expected to be signed with the certificate with fingerprint"

ลองหาทางแก้ไข ก็ไม่หาย แต่พอลองอัพหลายครั้ง ก็ยังขึ้น error แต่ปุ่มให้ SAVE สามารถใช้งานได้ ก็เลยผ่าน

ลองอัพ version ใหม่ ปรากฎว่า ไม่ขึ้น error

App Permission

การจัดการ App Permission

หัวข้ออื่น

ที่มา

ที่มา: