The following are operated in the build.gradle of the app module
1. Set the packaged apk name
android { defaultConfig { ... versionCode 2 versionName "1.1" // Set the packaged apk name setProperty("archivesBaseName", "companyName-appName-$versionName") ... } }
2. Set the packaged signature file
1) Create a signature file and store it in the app module directory (for example, name it keystore.jks)
2) Create a keystore.properties file in the project root directory to fill in the relevant verification information of the keystore
storePassword=123456 keyPassword=abcdef keyAlias = aliasName storeFile=keystore.jks
3) Add signature configuration in app build.gradle
def keystorePropertiesFile = rootProject.file("keystore.properties"); def keystoreProperties = new Properties() android { ... signingConfigs { config { keystoreProperties.load(new FileInputStream(keystorePropertiesFile)) storeFile file(keystoreProperties['storeFile']) storePassword keystoreProperties['storePassword'] keyAlias keystoreProperties['keyAlias'] keyPassword keystoreProperties['keyPassword'] /* Signature usage for v1 and v2 Just checking the v1 signature won't affect anything, but on 7.0 the more secure verification method will not be used Only check the V2 signature below 7.0, it will be installed directly and it will show that it is not installed, and if it is above 7.0, the V2 method will be used to verify If you check both V1 and V2, all models will be fine */ v1SigningEnabled true v2SigningEnabled true } } ... }
4) Set the signature configuration used when packaging in app build.gradle
android { ... buildTypes { release { ... signingConfig signingConfigs.config } } ... }
3. Execute the package command in the project root directory or app directory
gradle assembleRelease
The generated apk is in the app/build/outputs/apk directory with a name similar to companyName-appName-1.1-release.apk