口味😋: 不同口味使用各自的Android密钥库文件进行打包签名

This commit is contained in:
葛佳祥 2024-01-29 16:26:02 +08:00
parent 44686a1ba2
commit c881790eb5
7 changed files with 85 additions and 37 deletions

View File

@ -2,15 +2,36 @@
A new Flutter project.
## Getting Started
## 配置签名
为发布渠道创建JAVA密钥储存(密钥库)文件 `.jks`,或者 `.keystore` 文件。
This project is a starting point for a Flutter application.
```bash
keytool -genkey -v -keystore android/app/sky.jks -keyalg RSA -keysize 2048 -validity 10000 -alias upload
```
A few resources to get you started if this is your first Flutter project:
请记住你输入的主密码和键密码
- [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab)
- [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook)
因为本项目将会发布2个以上的渠道所以密钥库也会有2个以上请注意区分 同一个发布渠道必须使用同一个密钥库,不要生成多个。
For help getting started with Flutter development, view the
[online documentation](https://docs.flutter.dev/), which offers tutorials,
samples, guidance on mobile development, and a full API reference.
为了编译管理方便,我们将密钥库文件放在了项目代码内。
`key.properties` 文件用于存放密钥库的相关信息,但是我们不用这个文件,而是直接在 `build.gradle` 中写入密钥库的相关信息。
因为我们将密钥库文件本身都已经储存在git中了也就没必要再单独存放密钥信息了。
## 编译
```bash
flutter build apk --split-per-abi --release --flavor dev -t lib/main_dev.dart
```
## 获取编译包的签名
用于APP备案国内商店上架等
需要使用到`apksigner`工具对于Windows来说它在`C:\Users\myUser\AppData\Local\Android\Sdk\build-tools\34.0.0\lib`
`git bash` 中我需要使用 `apksigner.bat` 来使用它;在其它系统中应该可以直接使用 `apksigner` 命令即可。
参阅:[How to find signature of apk file?](https://stackoverflow.com/questions/38558623/how-to-find-signature-of-apk-file)
```bash
apksigner verify --print-certs -v build/app/outputs/flutter-apk/app-sky-release.apk
```

View File

@ -8,6 +8,8 @@ GeneratedPluginRegistrant.java
# Remember to never publicly share your keystore.
# See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app
key.properties
**/*.keystore
**/*.jks
# 因为我们要管理多个项目所以这里不要忽略keystore
# 而且我们的代码库是私有的,不存在泄露问题
#key.properties
#**/*.keystore
#**/*.jks

View File

@ -28,7 +28,27 @@ apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
signingConfigs {
pre {
storeFile file("starlock.keystore")
storePassword '123456'
keyAlias = 'starlock'
keyPassword '123456'
}
sky {
// CN=Unknown, OU=Unknown, O=Unknown, L=Unknown, ST=Unknown, C=Unknown
storeFile file("sky.jks")
storePassword 'sky2028'
keyAlias = 'upload'
keyPassword 'sky0s9x'
}
xhj {
storeFile file("xhj.jks")
storePassword 'xhj8872'
keyAlias = 'upload'
keyPassword 'xhj3md9'
}
}
// ----- BEGIN flavorDimensions (autogenerated by flutter_flavorizr) -----
flavorDimensions "flavor-type"
@ -46,18 +66,21 @@ android {
sky {
dimension "flavor-type"
applicationId "com.skychip.lock"
signingConfig signingConfigs.sky
resValue "string", "app_name", "锁通通"
}
xhj {
dimension "flavor-type"
applicationId "com.xhjcn.lock"
signingConfig signingConfigs.xhj
resValue "string", "app_name", "鑫锁"
}
}
// ----- END flavorDimensions (autogenerated by flutter_flavorizr) -----
compileSdkVersion flutter.compileSdkVersion
compileSdkVersion flutter.compileSdkVersion
ndkVersion flutter.ndkVersion
lintOptions{
@ -81,7 +104,6 @@ android {
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "cn.starlock.lock"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
@ -92,37 +114,35 @@ android {
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
signingConfig signingConfigs.pre
// 使 flutter build apk --split-per-abi
// ndk在同一个个包中包含多个架构
ndk {
//SO库架构so
abiFilters "armeabi", "armeabi-v7a", "arm64-v8a", "x86","x86_64"
// abiFilters "armeabi", "armeabi-v7a", "arm64-v8a", "x86","x86_64"
}
// armeabi 32armeabi-v7a 32arm64-v8a 64
// armeabi: 56ARM处理器
// armeabi-v7a: 7 ARM
// arm64-v8a: 864ARM处理器2016891000+
// x86:
// x86_64: 64
// 2011armeabi-v7a
splits {
abi {
enable true
reset()
include 'armeabi-v7a', 'arm64-v8a'
universalApk false
}
}
}
signingConfigs {
release {
storeFile file("starlock.keystore")
storePassword '123456'
keyAlias = 'starlock'
keyPassword '123456'
}
debug {
storeFile file("starlock.keystore")
storePassword '123456'
keyAlias = 'starlock'
keyPassword '123456'
}
}
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
productFlavors.sky.signingConfig signingConfigs.sky
productFlavors.xhj.signingConfig signingConfigs.xhj
}
debug {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --debug` works.
signingConfig signingConfigs.debug
}
}
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -33,6 +33,7 @@ flavors:
icon: "assets/icon/dev.png"
android:
applicationId: "com.starlock.lock.dev"
pre:
app:
name: "星锁"
@ -45,10 +46,14 @@ flavors:
icon: "assets/icon/sky.png"
android:
applicationId: "com.skychip.lock"
customConfig:
signingConfig: signingConfigs.sky
xhj:
app:
name: "鑫锁"
icon: "assets/icon/xhj.png"
android:
applicationId: "com.xhjcn.lock"
customConfig:
signingConfig: signingConfigs.xhj
ide: idea