Android Studio signature configuration and use Walle multi-channel package

6188347-dc054fd5fc5d762e.jpg
Aoraki_ZH-CN7776353328_1920x1080.jpg

This blog is mainly my learning process, summarize, there is something wrong trouble pointed out that study together progress

Foreword

Also recently got an e-book "Android + Gradle Definitive Guide" to learn a wave of Gradle knowledge, try to configure signature settings and configuration Walle multi-channel package. Reading Time: 15 minutes

signature

View mode

  We can by clicking on the top left corner of the Build-> Generate Signed APK-> Next, if there is no jks files, you need to create, and then select the corresponding Build Type packaged.

  For some do not shelves App, this wave operation can also be accepted, but if you want to upload to the platform each country will need to repeat this as many times, we can help people Gaosi ..., Gradle can learn through this article signature configuration and configuration Walle practice multi-channel package.

Gradle configuration signature

  We first look at the new project default app gradle default main configuration file as follows,


6188347-06a95bc28074b171
app gradle default main configuration file
  1. Ready to work

First, we generate good jks files into the project directory


6188347-f34f26e91c4b56dc
project directory
  1. Modify app build.gradle
defaultConfig {
    ....
    
signingConfigs {
        release {
            storeFile file(../ymcandroid.jks)//签名文件路径
            storePassword ymc******
            keyAlias key0
            keyPassword ymc******//签名密码
            println("====== signingConfigs.release ======")
        }
    }
    

  The above-described variable code part are packaged in a view corresponding jks file we need to add information.


6188347-03af3f0be21eb09c
Here Insert Picture Description
  • Pit: signingConfigs block of code must be written on the front buildTypes, otherwise this will be reported the following error: Could not find property 'debugConfig' on SigningConfig container.
  1. Package Release apk package

  We in the project path app / build / outputs can see our packaged apk.

  There is also up and down my buildTypes configuration

buildTypes {
        release {
            minifyEnabled false
            //是否移除无用资源
            zipAlignEnabled true
            signingConfig signingConfigs.release
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

  Above is already a simple signature, but I need to upload to this wanAndroid project on Github, so we are here to talk about ignore files, uploading git, we will ignore the part of the file, the file I was ignored in the project configuration

# Built application files  //
*.apk
*.ap_
# Files for the ART/Dalvik VM
*.dex
# Java class files
*.class
# Generated files
bin/
gen/
out/
# Gradle files
.gradle/
build/
# Local configuration file (sdk path, etc)
local.properties
/local.properties
# Proguard folder generated by Eclipse
proguard/
# Log Files
*.log
# Android Studio Navigation editor temp files
.navigation/
# Android Studio captures folder
captures/
# Intellij
*.iml
.idea/workspace.xml
# Keystore files
*.jks

*.iws
.idea/

  We may find we will want to configure local.properties jks file in which the password information.

ndk.dir=E\:\\AndroidSDK\\ndk-bundle
sdk.dir=E\:\\AndroidSDK

keystore.path=../ymcandroid.jks
keystore.password=ymc******
keystore.alias=key0
keystore.alias_password=ymc******

  Here we need to modify the app build.gradle file will replace the plaintext place

def keystoreFilepath = ''
def keystorePSW = ''
def keystoreAlias = ''
def keystoreAliasPSW = ''
// default keystore file, PLZ config file path in local.properties
def keyfile = file('s.keystore.temp')

Properties properties = new Properties()
// local.properties file in the root director
properties.load(project.rootProject.file('local.properties').newDataInputStream())
keystoreFilepath = properties.getProperty("keystore.path")

if (keystoreFilepath) {
    keystorePSW = properties.getProperty("keystore.password")
    keystoreAlias = properties.getProperty("keystore.alias")
    keystoreAliasPSW = properties.getProperty("keystore.alias_password")
    keyfile = file(keystoreFilepath)
}

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "cn.white.ymc.wanandroidmaster"
        minSdkVersion 19
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
    }

    signingConfigs {
        release {
            storeFile keyfile//签名文件路径
            storePassword keystorePSW
            keyAlias keystoreAlias
            keyPassword keystoreAliasPSW  //签名密码
            println("====== signingConfigs.release ======")
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            //是否移除无用资源
            zipAlignEnabled true
            signingConfig signingConfigs.release
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            //签名文件存在,则签名
            if (keyfile.exists()) {
                println("WITH -> buildTypes -> release: using jks key")
                signingConfig signingConfigs.release
            }else {
                println("WITH -> buildTypes -> release: using default key")
            }

        }
    }
}
dependencies {
    ...

  The code above the main change is the use of local grammar gradle read local.properties documents, access to which information, if there is a signature on the package. This way we can guarantee the security of the key documents.

  Signature finished, we need to look at the configuration and Walle part Gradle related operations.

Walle Package

Why the US Mission multi-channel package

  Packaged more quickly through traditional channels package productFlavors way, within channels 10 also can accept, if 100 channels package, to be dead, while the use of the US group Walle time multi-channel package of way just want to make a packet.
  More flexible configuration config file can be configured for different channels, each channel customization package configuration additional information APK channel package.

principle

The entire APK (ZIP file format) can be divided into four blocks:

Contents of ZIP entries(from offset 0 until the start of APK Signing Block)
APK Signing Block
ZIP Central Directory
ZIP End of Central Directory


6188347-f11782f73249e4c6.png
Here Insert Picture Description

This is the APK package format V2 signature package, the new application signature scheme has a good backwards compatibility, fully compatible with versions earlier than Android 7.0 (Nougat) is. Blocks 1,3,4 are protected block is not allowed to modify the protection zone. US group packed manner, writing is extended information (channel information) ID-value in the block 2, and saved to the APK. In this way, each playing a channel simply copy a package APK, then you can add an ID-value in the APK.

walle Configuration

Build.gradle root directory of the project file to add plug-ins rely Walle Gradle

classpath 'com.meituan.android.walle:plugin:1.1.6'

App of build.gradle file apply this plug-in and add AAR on the number of channels for reading

apply plugin: 'walle'

dependencies {
    compile 'com.meituan.android.walle:library:1.1.6'
}

We create a separate gradle to save the configuration plug multlple-channel.gradle, reads as follows

apply plugin: 'walle'

walle {
    // 指定渠道包的输出路径
    apkOutputFolder = new File("${project.buildDir}/outputs/channels")
    // 定制渠道包的APK的文件名称
    apkFileNameFormat = '${appName}-${channel}-${buildType}-v${versionName}-${versionCode}-${buildTime}.apk';
    // 渠道配置文件
    channelFile = new File("${project.getProjectDir()}/channel")
}

Section configuration parsing

apkOutputFolder: Specifies the output path channel packet, the default value is new File ( "{appName} - {channel} .apk

Variable Meaning

projectName - Project name
appName - App Module name
packageName - applicationId (App package name packageName)
buildType - buildType (Release / Debug, etc.)
Channel - Channel name (channel name corresponding to the channels packaged in)
versionName - versionName (version number is displayed using)
versionCode - versionCode (build number)
Buildtime - Buildtime (build date compile time)
fileSHA1 - fileSHA1 (final SHA1 hash APK file)
flavorName - compiled builds productFlavors name

Be sure to remember the introduction of the app build.gradle file Upon completion

apply from: 'multlple-channel.gradle'

Next, configure channelFile

meituan # 美团
samsungapps #三星
hiapk
anzhi
xiaomi # 小米
91com
gfan
appchina
nduoa
3gcn
mumayi
10086com
wostore
189store
lenovomm
hicloud
meizu
wandou
# Google Play
# googleplay
# 百度
baidu
#
# 360
360cn
#
# 应用宝
myapp

Above-market platform, readers can cut their own need to leave, then we use Android Studio to package


6188347-575e0e9dd4ee12f7
Here Insert Picture Description

After the package will experience a period of time, and so successful, we open the configuration output address


6188347-ecd7eb913c7c7fc6
Here Insert Picture Description

You can see the various channels we need to install the package.

Reference blog:
Walle GitHub
Android Studio signature

Guess you like

Origin blog.csdn.net/weixin_34168700/article/details/91011102