Skip to content
This repository has been archived by the owner on Jan 7, 2023. It is now read-only.

Commit

Permalink
using sourceDir first, release v1.0.9
Browse files Browse the repository at this point in the history
  • Loading branch information
mcxiaoke committed Mar 2, 2017
1 parent 04da0aa commit 07ab81f
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 27 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
VERSION_NAME=1.0.8
VERSION_CODE=108
VERSION_NAME=1.0.9
VERSION_CODE=109

GROUP=com.mcxiaoke.gradle

Expand Down
10 changes: 5 additions & 5 deletions helper/src/main/java/com/mcxiaoke/packer/helper/PackerNg.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,12 @@ private static String getSourceDir(final Object context)
final Class<?> applicationInfoClass = Class.forName("android.content.pm.ApplicationInfo");
final Method getApplicationInfoMethod = contextClass.getMethod("getApplicationInfo");
final Object appInfo = getApplicationInfoMethod.invoke(context);
// try ApplicationInfo.publicSourceDir
final Field publicSourceDirField = applicationInfoClass.getField("publicSourceDir");
String sourceDir = (String) publicSourceDirField.get(appInfo);
// try ApplicationInfo.sourceDir
Field sourceDirField = applicationInfoClass.getField("sourceDir");
String sourceDir = (String) sourceDirField.get(appInfo);
if (sourceDir == null) {
// try ApplicationInfo.sourceDir
final Field sourceDirField = applicationInfoClass.getField("sourceDir");
// try ApplicationInfo.publicSourceDir
sourceDirField = applicationInfoClass.getField("publicSourceDir");
sourceDir = (String) sourceDirField.get(appInfo);
}
if (sourceDir == null) {
Expand Down
17 changes: 10 additions & 7 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@

## 特别提示

**请使用最新版本的PackerNg,如果使用的Android Gradle Plugin版本大于2.2.0,请务必在 `signingConfigs` 里增加 `v2SigningEnabled false` 禁用新版签名模式,详细的说明见这里:[兼容性问题说明](compatibility.md)**
- **请使用最新版本的PackerNg,如果使用的Android Gradle Plugin版本大于2.2.0,请务必在 `signingConfigs` 里增加 `v2SigningEnabled false` 禁用新版签名模式,详细的说明见这里:[兼容性问题说明](compatibility.md)**

- **如果你同时使用 [tinker](https://github.com/Tencent/tinker) ,请使用`1.0.9`以后的版本,同时阅读tinker的文档,确保没有兼容问题。**

## 最新版本

- **v1.0.9 - 2017.03.03** - 获取APK文件路径时优先读取sourceDir
- **v1.0.8 - 2016.10.20** - 移除对旧版打包工具的扩展属性兼容
- **v1.0.7 - 2016.08.09** - 优化签名校验和渠道写入,完善异常处理
- **v1.0.6 - 2016.08.05** - V2签名模式兼容问题提示,打包脚本优化
Expand All @@ -20,7 +23,7 @@

## 项目介绍

[**packer-ng-plugin**](https://github.com/mcxiaoke/packer-ng-plugin) 是下一代Android渠道打包工具Gradle插件,支持极速打包,**100**个渠道包只需要**10**秒钟,速度是 [**gradle-packer-plugin**](https://github.com/mcxiaoke/gradle-packer-plugin)**300**倍以上,可方便的用于CI系统集成,支持自定义输出目录和最终APK文件名,依赖包: `com.mcxiaoke.gradle:packer-ng:1.0.7` 简短名:`packer`,可以在项目的 `build.gradle` 中指定使用,还提供了命令行独立使用的Java和Python脚本。实现原理见本文末尾。
[**packer-ng-plugin**](https://github.com/mcxiaoke/packer-ng-plugin) 是下一代Android渠道打包工具Gradle插件,支持极速打包,**100**个渠道包只需要**10**秒钟,速度是 [**gradle-packer-plugin**](https://github.com/mcxiaoke/gradle-packer-plugin)**300**倍以上,可方便的用于CI系统集成,支持自定义输出目录和最终APK文件名,依赖包: `com.mcxiaoke.gradle:packer-ng:1.0.9` 简短名:`packer`,可以在项目的 `build.gradle` 中指定使用,还提供了命令行独立使用的Java和Python脚本。实现原理见本文末尾。

## 使用指南

Expand All @@ -34,7 +37,7 @@ buildscript {
......
dependencies{
// add packer-ng
classpath 'com.mcxiaoke.gradle:packer-ng:1.0.8'
classpath 'com.mcxiaoke.gradle:packer-ng:1.0.9'
}
}
```
Expand All @@ -45,7 +48,7 @@ buildscript {
apply plugin: 'packer'
dependencies {
compile 'com.mcxiaoke.gradle:packer-helper:1.0.8'
compile 'com.mcxiaoke.gradle:packer-helper:1.0.9'
}
android {
Expand Down Expand Up @@ -123,7 +126,7 @@ market是你的渠道名列表文件,market文件是基于**项目根目录**

**特别提示:如果你同时使用其它的资源压缩工具或应用加固功能,请使用命令行脚本打包增加渠道信息,增加渠道信息需要放在APK处理过程的最后一步。**

如果不想使用Gradle插件,这里还有两个命令行打包脚本,在项目的 `tools` 目录里,分别是 `PackerNg-1.0.7.jar``PackerNg-1.0.7.py`,使用命令行打包工具,在Java代码里仍然是使用`helper`包里的 `PackerNg.getMarket(Context)` 读取渠道。
如果不想使用Gradle插件,这里还有两个命令行打包脚本,在项目的 `tools` 目录里,分别是 `PackerNg-1.0.9.jar``PackerNg-1.0.9.py`,使用命令行打包工具,在Java代码里仍然是使用`helper`包里的 `PackerNg.getMarket(Context)` 读取渠道。

#### Java脚本

Expand Down Expand Up @@ -170,8 +173,8 @@ packer {
* *versionName* - `versionName` (显示用的版本号)
* *versionCode* - `versionCode` (内部版本号)
* *buildTime* - `buildTime` (编译构建日期时间)
* *fileMD5* - `fileMD5 ` (最终APK文件的MD5哈希值) (**v1.0.5新增**)
* *fileSHA1* - `fileSHA1 ` (最终APK文件的SHA1哈希值) (**v1.0.5新增**)
* *fileMD5* - `fileMD5 ` (最终APK文件的MD5哈希值)
* *fileSHA1* - `fileSHA1 ` (最终APK文件的SHA1哈希值)

## 实现原理

Expand Down
22 changes: 11 additions & 11 deletions sample/build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
buildscript {
ext.packer_version = '1.0.8'
ext.packer_version = '1.0.9-SNAPSHOT'

repositories {
maven { url '/tmp/repo/' }
jcenter()
// maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
}

dependencies {
classpath "com.android.tools.build:gradle:2.2.1"
// classpath "com.mcxiaoke.gradle:packer-ng:$packer_version"
classpath "com.mcxiaoke.gradle:packer-ng:$packer_version"
}
}

Expand All @@ -20,11 +20,11 @@ repositories {
}

apply plugin: 'com.android.application'
// apply plugin: 'packer'
apply plugin: 'packer'

// https://code.google.com/p/android/issues/detail?id=171089
dependencies {
// compile project(':helper')
// compile project(':helper')
compile "com.mcxiaoke.gradle:packer-helper:$packer_version"
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:24.1.1'
Expand All @@ -39,12 +39,12 @@ dependencies {
}
}

// packer {
// checkSigningConfig = true
// checkZipAlign = true
// archiveNameFormat = '${appPkg}-${flavorName}-${buildType}-v${versionName}-${versionCode}-${fileMD5}'
// archiveOutput = file(new File(project.rootProject.buildDir.path, "myapks"))
// }
packer {
checkSigningConfig = true
checkZipAlign = true
archiveNameFormat = '${appPkg}-${flavorName}-${buildType}-v${versionName}-${versionCode}-${fileMD5}'
archiveOutput = file(new File(project.rootProject.buildDir.path, "myapks"))
}

android {
compileSdkVersion Integer.parseInt(project.COMPILE_SDK_VERSION)
Expand Down
Binary file removed tools/PackerNg-1.0.7.jar
Binary file not shown.
Binary file added tools/PackerNg-1.0.9.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions tools/PackerNg-1.0.7.py → tools/PackerNg-1.0.9.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# @Author: mcxiaoke
# @Date: 2015-11-26 16:52:55
# @Last Modified by: mcxiaoke
# @Last Modified time: 2016-08-15 17:03:22
# @Last Modified time: 2017-03-02 18:30:36
from __future__ import print_function
import os
import sys
Expand All @@ -13,7 +13,7 @@
from apkinfo import APK
from string import Template

__version__ = '1.0.7' # 2016.08.09
__version__ = '1.0.9' # 2017.03.03

ZIP_SHORT = 2
MARKET_PATH = 'markets.txt'
Expand Down

0 comments on commit 07ab81f

Please sign in to comment.