Speed channel packaging tool
- V2.0.0-2017.06.23 – New release, supports V2 signature mode, includes several optimizations
Special note
SigningConfigs (v2SigningEnabled True) supports the APK Signature Scheme V2, which requires you to enable the APK Signature Scheme V2 in signingConfigs (v2SigningEnabled True). Look at v1.0.9 here.
Packer-ng-plugin is the next generation of Android channel packaging tool Gradle plugin, support rapid packaging, 100 channel packages only takes 10 seconds, the speed is more than 300 times of Gradle-Packer-plugin, can be easily used in CI system integration. At the same time provides command line packaging script, channel reading provides Python and C language implementation.
Use guide
To modify the project root directorybuild.gradle
buildscript {
dependencies{
classpath 'Com. McXiaoke. Packer - ng: plugin: 2.0.0'}}Copy the code
apply plugin: 'packer'
dependencies {
compile 'Com. McXiaoke. Packer - ng: helper: 2.0.0'
} Copy the code
Note:plugin
和 helper
The version number of the
Plug-in Configuration Example
packer {
archiveNameFormat = '${buildType}-v${versionName}-${channel}'
archiveOutput = new File(project.rootProject.buildDir, "apks")
//Douban channelList = [' * * ', 'Google/',' Chinese / @ # market 'and' 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")]}Copy the code
- archiveNameFormat– Specifies the format template for the final output channel package file name, described below. The default is
${appPkg}-${channel}-${buildType}-v${versionName}-${versionCode}
(optional) - archiveOutput– Specifies where the final output channel package is stored. The default is
${project.buildDir}/archives
(optional) - ChannelList – specifies the channelList. See the example
- ChannelMap – Specifies different channel list files based on productFlavor, as shown in an example
- ChannelFile – Specifies the channel list File. The File type is shown in the example
Note: The channelList, channelMap, and channelFile attributes cannot be used at the same time. Select one of them as required. If the three attributes exist at the same time, their priorities are as follows: ChannelList > channelMap > channelFile. In addition, these three attributes are overridden by the -pchannels command.
The channel name list file is a plain text file that is read line by line, one channel per line, and whitespace at the beginning and end of the line is ignored. If there are any comments, the channel name and the comment are separated by #.
It is recommended to use standard Chinese and English and digits for channel names, and do not use special characters or invisible characters. Example: channels. TXT
Integrated packaging
-
ProductFlavors is not used in the project
./gradlew clean apkRelease Copy the code
-
ProductFlavors is used in the project
If multiple flavors are specified in the project, you need to specify the name of the flavor to be packaged. Assume that you have two Paid Free flavors, run the following command to package them:
./gradlew clean apkPaidRelease ./gradlew clean apkFreeReleaseCopy the code
Using./gradlew clean apkRelease directly prints all flavor channel packages.
-
Specify the list of channels directly with an argument (which overrides properties in build.gradle) :
./gradlew clean apkRelease -Pchannels=ch1,ch2,douban,googleCopy the code
This can be used when the number of channels is small.
-
Specify the location of the channel list file with an argument (which overrides properties in build.gradle) :
./gradlew clean apkRelease [email protected]Copy the code
Use the @ symbol to specify the location of the channel list file, using a path relative to the project root.
-
You can also specify the output directory and file name format template:
./gradlew clean apkRelease -Poutput=build/apks ./gradlew clean apkRelease -Pformat=${versionName}-${channel}Copy the code
Channels Output format can be used in combination, and the command line argument overrides the build.gradle attribute.
-
Gradle packaging command description
Apk ${flavor}${buildType} buildType = release, beta = someOtherType, beta = someOtherType Assume that the flavor is Paid, that the release type corresponds to apkPaidRelease, that the beta type corresponds to apkPaidBetaBeta, and so on.
-
Special note
If you are using another compression tool or hardening feature, use the command line script to package the channel information. The channel information should be added at the end of the APK process.
In addition to using Gradle integration, you can also use Java scripts provided by the project to package the Jar. Jar is located in the tools directory of this project. Please use the latest version. Here are a few examples.
- Parameter Description:
Packer-ng - represents java-jar packer-ng-2.0.0.jar channels. TXT - replaces the actual path of your channel list file build/archives - replaces the output path of your specified channel package app.apk - Replace it with the actual path to the APK file you want to send the channel package to
Copy the code
- Directly specify channel list packaging:
packer-ng generate --channels=ch1,ch2,ch3 --output=build/archives app.apkCopy the code
- Specify channel list file package:
packer-ng generate [email protected] --output=build/archives app.apkCopy the code
- Verification channel information:
packer-ng verify app.apkCopy the code
- Run the command to view the help
Java jar tools/packer - ng - 2.0.0. Jar -- helpCopy the code
- Python script reading channels:
python tools/packer-ng-v2.py app.apkCopy the code
- C program reading channel:
cd tools
make
make install
packer app.apkCopy the code
Read channels in code
//If channel information is not found or an error is encountered, "" is returned by default.
// com.mcxiaoke.packer.helper.PackerNg
String channel = PackerNg.getChannel(Context)Copy the code
The format template uses the Groovy string template engine. The default filename format is: ${appPkg}-${channel}-${buildType}-v${versionName}-${versionCode}.
If your App package name is com.your.pany, channel name is Google_Play, buildType is release, versionName is 2.1.15, versionCode is 200115, The generated default APK file name is com.your.com phany – google_player-release-2.1.15-20015.apk.
The following variables can be used:
- projectName– Project name
- appName– App Module name
- appPkg –
applicationId
(App package name packageName) - channel– Channel name specified when packaging
- buildType –
buildType
(release/debug/beta, etc.) - flavorName –
flavorName
(Flavor name, such as paid/ Free) - versionName –
versionName
(Version number used for display) - versionCode –
versionCode
(Internal version Number) - buildTime –
buildTime
(Compile build date and time) - fileSHA1 –
fileSHA1
(SHA1 hash of the final APK file)
Other instructions
The channel reading C implementation is built using GenericMakefile. The APK Signing Block reads and writes Java implementations modified from Apksig and Walle. Thank you.
contact
- Blog: blog.mcxiaoke.com
- Github: github.com/mcxiaoke
- Email: [email protected]
The open source project
- Rx 英 文 版 : github.com/mcxiaoke/Rx…
- MQTT Protocol Chinese version: github.com/mcxiaoke/mq…
- Awesome – Kotlin: github.com/mcxiaoke/aw…
- Kotlin – Koi: github.com/mcxiaoke/ko…
- Next Common Component library: github.com/mcxiaoke/An…
- Gradle Channel package: github.com/mcxiaoke/gr…
- EventBus xBus: github.com/mcxiaoke/xB…
- Mushroom rice App: github.com/mcxiaoke/mi…
- Fan No client: github.com/mcxiaoke/fa…
- Volley Mirroring: github.com/mcxiaoke/an…
Copyright 2014-2017 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.
Copy the code