diff --git a/docs/.vitepress/config.mts b/docs/.vitepress/config.mts index 861febf..aff5304 100644 --- a/docs/.vitepress/config.mts +++ b/docs/.vitepress/config.mts @@ -68,6 +68,15 @@ export default defineConfig({ { text: '基于OAuth2的FastApi安全验证', link: '/FastAPI/OAuth2' } ] } + ], + '/Flutter/': [ + { + text: 'Flutter', + items: [ + { text: '基础教程', link: '/Flutter/Guide' }, + { text: '实战技巧', link: '/Flutter/Practice' } + ] + } ] }, diff --git a/docs/Flutter/Guide.md b/docs/Flutter/Guide.md new file mode 100644 index 0000000..e69de29 diff --git a/docs/Flutter/Practice.md b/docs/Flutter/Practice.md new file mode 100644 index 0000000..a8dc83f --- /dev/null +++ b/docs/Flutter/Practice.md @@ -0,0 +1,70 @@ +# 安卓签名 +  每次安装/升级软件必须使用同一个签名,否则会将本地数据全部清空。 +## 1. 生成密钥库文件 +  使用keytool命令生成 +```cmd +keytool -genkey -v -keystore android/app/my-release-key.keystore -alias my-key -keyalg RSA -keysize 2048 -validity 10000 +``` + +  根据提示输入相应信息。 +  my.keystore为自定义名称。生成后的文件位于android/app/文件夹内 + +## 2. 配置key.properties +  在android文件夹内新建key.properties文件,并配置信息 +```properties +# 密钥库文件的密码 +storePassword=12345678 +# 密钥本身的密码 +keyPassword=12345678 +# 密钥的别名,在密钥库中标识具体的密钥 +keyAlias=my-key +# 密钥库文件相对于本配置文件的路径 +storeFile=my-release-key.keystore +``` + +## 3. 配置build.gradle.kts +```kts +import java.util.Properties +import java.io.FileInputStream + +// 从根路径加载密钥属性 +val keystoreProperties = Properties() +val keystorePropertiesFile = rootProject.file("key.properties") +if (keystorePropertiesFile.exists()) { + keystoreProperties.load(FileInputStream(keystorePropertiesFile)) +} +``` + +  在android块内新增签名配置 +```kts +android { + // 签名配置 + signingConfigs { + create("release") { + if (keystorePropertiesFile.exists()) { + keyAlias = keystoreProperties.getProperty("keyAlias") + keyPassword = keystoreProperties.getProperty("keyPassword") + storeFile = file(keystoreProperties.getProperty("storeFile")) + storePassword = keystoreProperties.getProperty("storePassword") + } + } + } + + buildTypes { + + release { + signingConfig = if (keystorePropertiesFile.exists()) { + // 使用发布签名 + signingConfigs.getByName("release") + } else { + // 使用默认签名 + signingConfigs.getByName("debug") + } + } + } +} +``` + +  打包为release包时即可生效签名。 +> [!CAUTION] +> 禁止将签名文件上传到Git仓库中。 diff --git a/docs/Flutter/index.md b/docs/Flutter/index.md index 1ce6e3a..dc960da 100644 --- a/docs/Flutter/index.md +++ b/docs/Flutter/index.md @@ -4,3 +4,6 @@ title: Flutter --- # 内容导航 + +- [基础教程](/Flutter/Guide) +- [实战技巧](/Flutter/Practice) \ No newline at end of file