Publish cho Android
Bước 1: Tạo một keystore
Nếu đã có keystore thì bỏ qua bước này và thực hiện bước tiếp theo. Nếu không thì thực hiện đoạn lệnh bên dưới với <path> là đường dẫn tạo file key:
keytool -genkey -v -keystore key.jks -keyalg RSA -keysize 2048 -validity 10000 -alias key -storetype JKS
Bước 2: Tham chiếu keystore vào trong ứng dụng
Tạo file có tên key.properties trong thư mục android trong đó password, keyAlias là những thông tin khi tạo key.
storePassword=<password>
keyPassword=<password>
keyAlias=key
storeFile=<path>/key.jks
Bước 3: Cấu hình gradle
Thay đổi file <dir>/android/app/build.gradle
tại các vị trí:
Thay đoạn android {
bởi thông tin keystore
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
android {
Thay đoạn
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
}
}
Bởi đoạn
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile file(keystoreProperties['storeFile'])
storePassword keystoreProperties['storePassword']
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
Bước 4: Tạo file release
Chạy lệnh bên dưới để release apk tại thư mục build\app\outputs\apk\release
flutter build apk
Hoặc chạy lệnh bên dưới để release file dưới dạng appbundle tại thư mục build\app\outputs\bundle\release
flutter build appbundle
Một số trường hợp cần lấy SHA1/SHA256 Key cho 2 chế độ debug và relase. Thì có thể chạy lệnh như bên dưới:
Debug key
keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android
Release Key
keytool -list -v -keystore {keystore_name} -alias {alias_name}
Bước 5: Publish lên CH Play
Truy cập vào Google Console để tạo một Ứng dụng mới hoặc update ứng dụng cũ bằng file dạng appbundle (*.aab) hoặc file apk (*.apk) .
Last updated
Was this helpful?