Skip to content

Commit

Permalink
支持FastMode,更新到V1.1.7版本
Browse files Browse the repository at this point in the history
  • Loading branch information
leontli committed Feb 24, 2018
1 parent 31566c9 commit 473f4fb
Show file tree
Hide file tree
Showing 28 changed files with 299 additions and 174 deletions.
Binary file removed app/baseApk/v1-base-debug.apk
Binary file not shown.
Binary file removed app/baseApk/v2-base-debug.apk
Binary file not shown.
17 changes: 11 additions & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ apply plugin: 'channel'
buildscript {
repositories {
maven {
url "file:///Users/zhangkaqi/localMaven"
url "file:///Users/leontli/localMaven"
}
google()
jcenter()
Expand All @@ -15,16 +15,21 @@ buildscript {
}
}

//rebuildChannel {
// baseDebugApk = new File(project.projectDir, "baseApk/v1-base-debug.apk")
// baseReleaseApk = new File(project.projectDir, "baseApk/v2-base-debug.apk")
//}
channel{
//isFastMode = true
}

rebuildChannel {
baseDebugApk = new File(project.projectDir, "baseApk/v1-base-debug.apk")
baseReleaseApk = new File(project.projectDir, "baseApk/v2-base-debug.apk")
//isFastMode = true
}

android {
compileSdkVersion rootProject.compileSdkVersion
buildToolsVersion rootProject.buildToolsVersion
defaultConfig {
applicationId "leon.com.apkchannelpackage"
applicationId "com.leon.dolly"
minSdkVersion rootProject.minSdkVersion
targetSdkVersion rootProject.targetSdkVersion
versionCode 1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package leon.com.apkchannelpackage;
package com.leon.dolly;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
Expand All @@ -21,6 +21,6 @@ public void useAppContext() throws Exception {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();

assertEquals("leon.com.apkchannelpackage", appContext.getPackageName());
assertEquals("com.leon.dolly", appContext.getPackageName());
}
}
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="leon.com.apkchannelpackage">
package="com.leon.dolly">

<application
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<activity android:name="com.leon.dolly.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
* limitations under the License.
*/

package leon.com.apkchannelpackage;
package com.leon.dolly;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
import com.leon.channel.helper.ChannelReaderUtil;
import com.leon.dolly.R;

public class MainActivity extends AppCompatActivity {
private static final String TAG = "MainActivity";
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="leon.com.apkchannelpackage.MainActivity">
tools:context="com.leon.dolly.MainActivity">

<TextView
android:id="@+id/channel"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package leon.com.apkchannelpackage;
package com.leon.dolly;

import org.junit.Test;

Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ext {


GROUP = 'com.leon.channel'
VERSION = '1.1.6'
VERSION = '1.1.7'

//POM_PACKAGING = "pom"
POM_DESCRIPTION = "VasDolly"
Expand All @@ -28,7 +28,7 @@ ext {
buildscript {
repositories {
maven {
url "file:///Users/zhangkaqi/localMaven"
url "file:///Users/leontli/localMaven"
}
google()
jcenter()
Expand All @@ -43,7 +43,7 @@ buildscript {
allprojects {
repositories {
maven {
url "file:///Users/zhangkaqi/localMaven"
url "file:///Users/leontli/localMaven"
}
google()
jcenter()
Expand Down
12 changes: 10 additions & 2 deletions channel.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
leon
ltlovezh
c1
c2
c3
c4
c5
c6
c7
c8
c9
c10
Binary file modified command/jar/VasDolly.jar
Binary file not shown.
90 changes: 68 additions & 22 deletions command/src/main/java/com/leon/channel/command/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public static void main(String[] args) {
String cmdPut = "put";//插入
String cmdSignMode = "-s";//签名方式
String cmdChannel = "-c";//渠道信息
String cmdFast = "-f";//极速模式:生成渠道包不进行校验(速度可以提升10倍以上)
String cmdMultiThreadChannel = "-mtc";//基于V1签名生成多渠道包时,使用多线程模式
String cmdHelp = "help";

Expand All @@ -43,16 +44,19 @@ public static void main(String[] args) {
" " + cmdPut + " put channel information\n" +
" " + cmdHelp + " get help\n\n" +
"general args:\n\n" +
" " + cmdSignMode + " [arg] signature mode , only fit 'get'\n" +
" " + cmdChannel + " [arg] channel information\n" +
" " + cmdMultiThreadChannel + " [arg] multithread to v1 , only fit 'put'\n\n" +
" " + cmdSignMode + " signature mode , only fit 'get'\n" +
" " + cmdChannel + " [arg] channel information\n" +
" " + cmdMultiThreadChannel + " [arg] multithread to v1 , only fit 'put'\n" +
" " + cmdFast + " fast mode : generate channel apk without checking(speed can be increased by up to 10 times), only fit 'put'\n\n" +
"for example:\n\n" +
" java -jar VasDolly.jar get -s /home/user/test.apk\n" +
" java -jar VasDolly.jar get -c /home/user/test.apk\n" +
" java -jar VasDolly.jar put -c \"channel1,channel2\" /home/user/base.apk /home/user/\n" +
" java -jar VasDolly.jar put -mtc \"channel1,channel2\" /home/user/base.apk /home/user/\n" +
" java -jar VasDolly.jar put -c channel.txt /home/user/base.apk /home/user/\n" +
" java -jar VasDolly.jar put -mtc channel.txt /home/user/base.apk /home/user/\n\n" +
" java -jar VasDolly.jar put -mtc channel.txt /home/user/base.apk /home/user/\n" +
" java -jar VasDolly.jar put -c channel.txt -f /home/user/base.apk /home/user/\n" +
" java -jar VasDolly.jar put -mtc channel.txt -f /home/user/base.apk /home/user/\n\n" +
"Use commas to write multiple channels , you can also use channel file.\n";

if (args.length == 0 || args[0] == null || args[0].trim().length() == 0) {
Expand Down Expand Up @@ -90,30 +94,72 @@ public static void main(String[] args) {
} else {
System.out.print("\n\nPlease enter the correct command!");
}

} else if (command0.equals(cmdPut)) { //插入
if (command1.equals(cmdChannel) || command1.equals(cmdMultiThreadChannel)) { //插入渠道信息
boolean isMultiThread = command1.equals(cmdMultiThreadChannel);
if (args.length >= 5) {
if (command1.equals(cmdChannel) || command1.equals(cmdMultiThreadChannel) || command1.equals(cmdFast)) { //插入渠道信息
boolean isMultiThread = false;
boolean isFastMode = false;
if (args.length == 5 || args.length == 6) {
//baseApk
String baseApkPath = args[3].trim();
String baseApkPath = args[args.length - 2].trim();
File baseApk = new File(baseApkPath);
if (!baseApk.exists()) {
System.out.print("\n\nApk file does not exist!");
if (baseApk.isDirectory()) {
System.out.print("\n\nBase Apk cannot be a directory!");
return;
} else if (baseApk.isDirectory()) {
System.out.print("\n\nThe file path cannot be a directory!");
} else if (!baseApk.exists()) {
System.out.print("\n\nBase Apk does not exist!");
return;
}
//base
String outPutPath = args[4].trim();
File outPutDir = new File(outPutPath);
if (!outPutDir.isDirectory()) {
System.out.print("\n\nThe output path cannot be a file , must be a directory!");
return;
//output directory
String outPutPath = args[args.length - 1].trim();
File outputDir = new File(outPutPath);
if (outputDir.exists()) {
if (!outputDir.isDirectory()) {
System.out.print("\n\nThe output path must be a directory!");
return;
}
} else {
if (!outputDir.mkdirs()) {
System.out.print("\n\nThe output path mkdirs directory fail!");
return;
}
}

String channels = "";
if (args.length == 5) {
isFastMode = false;
if (command1.equals(cmdChannel) || command1.equals(cmdMultiThreadChannel)) {
isMultiThread = command1.equals(cmdMultiThreadChannel);
channels = args[2].trim();
} else {
System.out.print("\n\nPlease enter the correct command!");
return;
}
} else if (args.length == 6) {
if (command1.equals(cmdChannel) || command1.equals(cmdMultiThreadChannel)) {
if (cmdFast.equals(args[3].trim())) {
isMultiThread = command1.equals(cmdMultiThreadChannel);
channels = args[2].trim();
isFastMode = true;
} else {
System.out.print("\n\nPlease enter the correct command!");
return;
}
} else if (command1.equals(cmdFast)) {
isFastMode = true;
if (args[2].equals(cmdChannel) || args[2].equals(cmdMultiThreadChannel)) {
isMultiThread = args[2].equals(cmdMultiThreadChannel);
channels = args[3].trim();
} else {
System.out.print("\n\nPlease enter the correct command!");
return;
}
} else {
System.out.print("\n\nPlease enter the correct command!");
return;
}
}

//渠道信息
String channels = args[2].trim();
File channelFile = new File(channels);
List<String> channelList = new ArrayList<>();
//渠道文件
Expand All @@ -123,12 +169,12 @@ public static void main(String[] args) {
String[] channelArray = channels.split(",");
channelList = Arrays.asList(channelArray);
}
Util.writeChannel(baseApk, channelList, outPutDir,isMultiThread);
Util.writeChannel(baseApk, channelList, outputDir, isMultiThread, isFastMode);
} else {
System.out.print("\n\nPlease enter the correct command!");
}
} else {
System.out.print("\n\n'put' only support -c arg!");
System.out.print("\n\n'put' only support -c or -mtc arg!");
}
} else {
System.out.print("\n\nPlease enter the correct command!");
Expand Down
40 changes: 24 additions & 16 deletions command/src/main/java/com/leon/channel/command/ThreadManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ public void destory() {
* @param channelList
* @param outputDir
*/
public void generateV1Channel(File baseApk, List<String> channelList, File outputDir) {
public void generateV1Channel(File baseApk, List<String> channelList, File outputDir, boolean isFastMode) {
String apkName = baseApk.getName();
setChannelNum(channelList.size());
for (String channel : channelList) {
String apkChannelName = Util.getChannelApkName(apkName, channel);
System.out.println("generateV1Channel , channel = " + channel + " , apkChannelName = " + apkChannelName);
File destFile = new File(outputDir, apkChannelName);
mExecutorService.execute(new ChanndelRunnable(baseApk, destFile, channel));
mExecutorService.execute(new ChanndelRunnable(baseApk, destFile, channel, isFastMode));
}
try {
mChannelountDownLatch.await();
Expand All @@ -96,7 +96,7 @@ public void generateV1Channel(File baseApk, List<String> channelList, File outpu
}

if (mChannelSuccessNum.get() != mChannelNum) {
System.out.println("need generate channel num : " + mChannelNum + " , but success only num : " + mChannelSuccessNum.get() + " , success apk list : " + mChannelSuccessList);
System.out.println("Fail , need generate channel num : " + mChannelNum + " , but success only num : " + mChannelSuccessNum.get() + " , success apk list : " + mChannelSuccessList);
} else {
System.out.println("Success , total generate channel num : " + mChannelNum + " , APK list : " + mChannelSuccessList);
}
Expand All @@ -114,35 +114,43 @@ class ChanndelRunnable implements Runnable {
File mBaseApk;
File mDestFile;
String mChannel;
boolean mIsFastMode;

public ChanndelRunnable(File baseFile, File destfile, String channel) {
public ChanndelRunnable(File baseFile, File destfile, String channel, boolean isFastMode) {
this.mBaseApk = baseFile;
this.mDestFile = destfile;
this.mChannel = channel;
this.mIsFastMode = isFastMode;
}

@Override
public void run() {
String threadName = Thread.currentThread().getName();
try {
Util.copyFileUsingStream(mBaseApk, mDestFile);
Util.copyFileUsingNio(mBaseApk, mDestFile);
V1SchemeUtil.writeChannel(mDestFile, mChannel);
//verify channel info
if (V1SchemeUtil.verifyChannel(mDestFile, mChannel)) {
System.out.println("Thread : " + threadName + " generateV1Channel , " + mDestFile + " add channel success");
} else {
throw new RuntimeException("Thread : " + threadName + " generateV1Channel , " + mDestFile + " add channel failure");
}
//verify v1 signature
if (VerifyApk.verifyV1Signature(mDestFile)) {
if (mIsFastMode) {
mChannelSuccessNum.incrementAndGet();//表示生成渠道包成功
mChannelSuccessList.add(mDestFile.getName());
System.out.println("Thread : " + threadName + " , generateV1Channel , after add channel , " + mDestFile + " v1 verify success");
System.out.println("Thread : " + threadName + " , generateV1Channel , " + mDestFile + " fastMode success");
} else {
throw new RuntimeException("Thread : " + threadName + " generateV1Channel , after add channel , " + mDestFile + " v1 verify failure");
//1. verify channel info
if (V1SchemeUtil.verifyChannel(mDestFile, mChannel)) {
System.out.println("Thread : " + threadName + " , generateV1Channel , " + mDestFile + " add channel success");
} else {
throw new RuntimeException("Thread : " + threadName + " , generateV1Channel , " + mDestFile + " add channel failure");
}
//2. verify v1 signature
if (VerifyApk.verifyV1Signature(mDestFile)) {
mChannelSuccessNum.incrementAndGet();//表示生成渠道包成功
mChannelSuccessList.add(mDestFile.getName());
System.out.println("Thread : " + threadName + " , generateV1Channel , after add channel , " + mDestFile + " v1 verify success");
} else {
throw new RuntimeException("Thread : " + threadName + " , generateV1Channel , after add channel , " + mDestFile + " v1 verify failure");
}
}
} catch (Exception e) {
System.out.println("Thread : " + threadName + " generateV1Channel , error , please check it");
System.out.println("Thread : " + threadName + " , generateV1Channel , error , please check it");
e.printStackTrace();
} finally {
mChannelountDownLatch.countDown();
Expand Down
Loading

0 comments on commit 473f4fb

Please sign in to comment.