对Gradle 7.x的支持,欢迎提PR,或者Fork自己修改(2022.06.27)
Extremely fast channel packaging tool
The V2 version only supports APK Signature Scheme v2
, which requires v2SigningEnabled true
in signingConfigs
to enable the new version of the signature mode. If you need to use the older version, see v1.0.9 here.
packer-ng-plugin is the next generation Android channel packaging tool Gradle plug-in. It supports extremely fast packaging. It only takes 10 seconds to produce 100 channel packages. The speed is more than 300 times that of gradle-packer-plugin . It can be easily used for CI system integration. At the same time, a command line packaging script is provided, and channel reading is implemented in Python and C language.
Maven Central
// build.gradle
buildscript {
dependencies{
classpath ' com.mcxiaoke.packer-ng:plugin:2.0.1 '
}
}
apply plugin : ' packer '
// build.gradle
dependencies {
compile ' com.mcxiaoke.packer-ng:helper:2.0.1 '
}
Note: The version numbers of plugin
and helper
need to be consistent
packer {
archiveNameFormat = ' ${buildType}-v${versionName}-${channel} '
archiveOutput = new File (project . rootProject . buildDir, " apks " )
// channelList = ['*Douban*', 'Google/', '中文/@#市场', 'Hello@World',
// 'GradleTest', '20070601!@#$%^&*(){}:"<>?-=[];',./']
// channelFile = new File(project.rootDir, "markets.txt")
channelMap = [
" Cat " : project . rootProject . file( " channels/cat.txt " ),
" Dog " : project . rootProject . file( " channels/dog.txt " ),
" Fish " : project . rootProject . file( " channels/channels.txt " )
]
}
${appPkg}-${channel}-${buildType}-v${versionName}-${versionCode}
(optional) )${project.buildDir}/archives
(optional) Note: channelList
/ channelMap
/ channelFile
cannot be used at the same time. Just choose one according to the actual situation. When the three properties exist at the same time, the priority is: channelList
> channelMap
> channelFile
. In addition, these three properties will be overwritten by the command line parameter -Pchannels
.
The channel name list file is a plain text file, read line by line, with one channel per line. Blanks at the beginning and end of the line will be ignored. If there are comments, use #
to separate the channel name and the comments.
It is recommended that the channel name use standard Chinese, English and numbers as much as possible, and do not use special characters and invisible characters. Example: channels.txt
productFlavors
are not used in the project
./gradlew clean apkRelease
productFlavors
are used in the project
If multiple flavor
are specified in the project, you need to specify the name of flavor
needs to be packaged in the channel. Assume that you have two flavor
, Paid
Free
, and the command when packaging is as follows:
./gradlew clean apkPaidRelease
./gradlew clean apkFreeRelease
Directly using ./gradlew clean apkRelease
will output the channel packages of all flavor
.
Directly specify the channel list through parameters (will override the properties in build.gradle
):
./gradlew clean apkRelease -Pchannels=ch1,ch2,douban,google
This method can be used when the number of channels is small.
Specify the location of the channel list file through parameters (will override the properties in build.gradle
):
./gradlew clean apkRelease [email protected]
Use the @ symbol to specify the location of the channel list file, using a relative path relative to the project root directory.
You can also specify the output directory and file name format template:
./gradlew clean apkRelease -Poutput=build/apks
./gradlew clean apkRelease -Pformat= ${versionName} - ${channel}
These parameters channels
output
format
can be used in combination, and the command line parameters will override the corresponding properties of build.gradle
.
Gradle packaging command instructions
The name of the task packaged by the channel is apk${flavor}${buildType}
The buildType is usually release, or it can be beta or someOtherType that you specify. If there is no flavor
, you can ignore it. The first letter needs to be capitalized when using it. Assume that flavor
is Paid
, release
The task name corresponding to the type is apkPaidRelease
, the task name corresponding to the beta
type is apkPaidBetaBeta
, and so on for the others.
Special reminder
If you use other resource compression tools or application hardening functions at the same time, please use command line script packaging to add channel information. Adding channel information needs to be placed in the last step of the APK processing process.
In addition to using Gradle integration, you can also use the Java script packaging provided by the project. Jar is located in the tools
directory of this project. Please use the latest version. Hereinafter, packer-ng
is used to refer to java -jar tools/packer-ng-2.0.1.jar
, here are a few examples.
packer-ng - 表示 java -jar packer-ng-2.0.1.jar
channels.txt - 替换成你的渠道列表文件的实际路径
build/archives - 替换成你指定的渠道包的输出路径
app.apk - 替换成你要打渠道包的APK文件的实际路径
packer-ng generate --channels=ch1,ch2,ch3 --output=build/archives app.apk
packer-ng generate [email protected] --output=build/archives app.apk
packer-ng verify app.apk
java -jar tools/packer-ng-2.0.1.jar --help
python tools/packer-ng-v2.py app.apk
cd tools
make
make install
packer app.apk
// 如果没有找到渠道信息或遇到错误,默认返回的是""
// com.mcxiaoke.packer.helper.PackerNg
String channel = PackerNg . getChannel ( Context )
The format template uses the Groovy string template engine. The default file name format is: ${appPkg}-${channel}-${buildType}-v${versionName}-${versionCode}
.
If your App package name is com.your.company
, channel name is Google_Play
, buildType
is release
, versionName
is 2.1.15
, versionCode
is 200115
, then the file name of the generated default APK is com.your.company-Google_Player-release-2.1.15-20015.apk
.
The following variables are available:
applicationId
(App package name packageName)buildType
(release/debug/beta, etc.)flavor
(flavor name, such as paid/free, etc.)versionName
(version number used for display)versionCode
(build number)buildTime
(compile build date and time)fileSHA1
(SHA1 hash of the final APK file) The C language implementation of channel reading is built using GenericMakefile, and the Java implementation of APK Signing Block reading and writing is modified from apksig and walle. I would like to express my gratitude.
Copyright 2014 - 2021 Xiaoke Zhang
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.