Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
查郁 committed Nov 27, 2017
1 parent 9be25d0 commit d21a3ef
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 29 deletions.
4 changes: 2 additions & 2 deletions atlas-gradle-plugin/atlas-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ tasks.findByName("test").enabled=false
dependencies {
compile localGroovy()
compile gradleApi()
compile "com.taobao.android:dex_patch:1.4.4.13"
compile "com.taobao.android:dex_patch:1.4.4.15"
compile "com.android.tools.build:gradle:2.3.3"
compile "org.apache.commons:commons-lang3:3.4"
compile "commons-lang:commons-lang:2.6"
Expand All @@ -246,4 +246,4 @@ dependencies {
}


version = '2.3.3.rc38-zy'
version = '2.3.3.rc41'
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ public Set<String> getExcludeClasses() {
if (excludeClasses.size() > 0){
return excludeClasses;
}else {
return Sets.newHashSet("Landroid/taobao/atlas/framework/FrameworkProperties;","Landroid/taobao/atlas/bundleInfo/AtlasBundleInfoGenerator;","Lc8/As;");
return Sets.newHashSet("Landroid/taobao/atlas/framework/FrameworkProperties;","Landroid/taobao/atlas/bundleInfo/AtlasBundleInfoGenerator;");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,16 +209,16 @@

package com.taobao.android.builder.tasks.manager;

import java.util.ArrayList;
import java.util.List;

import com.android.build.gradle.internal.tasks.BaseTask;
import com.taobao.android.builder.tools.concurrent.ExecutorServicesHelper;
import org.apache.commons.lang3.StringUtils;
import org.gradle.api.DefaultTask;
import org.gradle.api.GradleException;
import org.gradle.api.tasks.TaskAction;

import java.util.ArrayList;
import java.util.List;

/**
* Created by wuzhong on 2016/10/13.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,21 +209,6 @@

package com.taobao.android.builder.tools.multidex.mutli;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
import java.util.List;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.jar.JarOutputStream;
import java.util.zip.ZipEntry;

import com.android.build.gradle.internal.api.AppVariantContext;
import com.android.build.gradle.internal.transforms.JarMerger;
import com.taobao.android.builder.extension.MultiDexConfig;
Expand All @@ -234,6 +219,13 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.*;
import java.util.*;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.jar.JarOutputStream;
import java.util.zip.ZipEntry;

/**
* Created by wuzhong on 2017/6/16.
*/
Expand All @@ -243,6 +235,9 @@ public class JarRefactor {

private AppVariantContext appVariantContext;
private MultiDexConfig multiDexConfig;
private boolean splitJar = false;

private static final int MAX_CLASSES = 1000;

public JarRefactor(AppVariantContext appVariantContext,
MultiDexConfig multiDexConfig) {
Expand All @@ -252,6 +247,7 @@ public JarRefactor(AppVariantContext appVariantContext,

public Collection<File> repackageJarList(Collection<File> files) throws IOException {


List<String> mainDexList = new MainDexLister(appVariantContext, multiDexConfig).getMainDexList(files);

List<File> jarList = new ArrayList<>();
Expand Down Expand Up @@ -295,6 +291,7 @@ public Collection<File> repackageJarList(Collection<File> files) throws IOExcept

for (File jar : jarList) {
File outJar = new File(dir, FileNameUtils.getUniqueJarName(jar) + ".jar");

result.add(outJar);
JarFile jarFile = new JarFile(jar);
JarOutputStream jos = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(outJar)));
Expand Down Expand Up @@ -327,8 +324,11 @@ public Collection<File> repackageJarList(Collection<File> files) throws IOExcept
if (pathList.isEmpty()) {
FileUtils.copyFile(jar, outJar);
}

if (!appVariantContext.getAtlasExtension().getTBuildConfig().isFastProguard() && outJar.getName().equals("main.jar")){
splitMainJar(result,outJar,1);
}
}

IOUtils.closeQuietly(mainJarOuputStream);

Collections.sort(result, new NameComparator());
Expand All @@ -338,6 +338,53 @@ public Collection<File> repackageJarList(Collection<File> files) throws IOExcept
return result;
}

private void splitMainJar(List<File> result, File outJar, int index) throws IOException {
boolean hasClass = false;
File splitOutJar = new File(outJar.getParentFile(), FileNameUtils.getUniqueJarName(outJar) + "-" + (index + 1) + ".jar");
File splitOutJarMain = new File(outJar.getParentFile(), FileNameUtils.getUniqueJarName(outJar) + "-" + (index) + ".jar");
JarOutputStream jos = new JarOutputStream(
new BufferedOutputStream(new FileOutputStream(splitOutJar)));
JarOutputStream josMain = new JarOutputStream(
new BufferedOutputStream(new FileOutputStream(splitOutJarMain)));
JarFile jarFile = new JarFile(outJar);
try {


Enumeration<JarEntry> entryEnumeration = jarFile.entries();
int i = 0;
while (entryEnumeration.hasMoreElements()) {
JarEntry jarEntry = entryEnumeration.nextElement();
if (jarEntry.getName().endsWith(".class")) {
i++;
}
if (i > MAX_CLASSES) {
hasClass = true;
copyStream(jarFile.getInputStream(jarEntry), jos, jarEntry, jarEntry.getName());
} else {
copyStream(jarFile.getInputStream(jarEntry), josMain, jarEntry, jarEntry.getName());
}
}
IOUtils.closeQuietly(jos);
IOUtils.closeQuietly(josMain);
jarFile.close();
if (!hasClass) {
FileUtils.deleteQuietly(splitOutJar);
return;
} else {
FileUtils.deleteQuietly(outJar);
result.remove(outJar);
result.add(splitOutJar);
result.add(splitOutJarMain);
}
splitMainJar(result, splitOutJar, index + 1);
}catch (Exception e){

}finally {

}

}

private void copyStream(InputStream inputStream, JarOutputStream jos, JarEntry ze, String pathName) {
try {

Expand Down
2 changes: 1 addition & 1 deletion atlas-gradle-plugin/dexpatch/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ dependencies {

group 'com.taobao.android'

version "1.4.4.13-zy"
version "1.4.4.15"

Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,7 @@ private byte[] writeDex(DexFile outputDex) {
DxConsole.err.println("\ntrouble writing output: " +
ex.getMessage());
}
ex.printStackTrace();
return null;
}
return outArray;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ public void addContents(DexFile file) {
TypeIdsSection typeIds = file.getTypeIds();

//去除debuginfo
// if (code.hasPositions() || code.hasLocals()) {
// debugInfo = new DebugInfoItem(code, isStatic, ref);
// byteData.add(debugInfo);
// }
if (code.hasPositions() || code.hasLocals()) {
debugInfo = new DebugInfoItem(code, isStatic, ref);
byteData.add(debugInfo);
}

if (code.hasAnyCatches()) {
for (Type type : code.getCatchTypes()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ public PatchInfo createBasePatchInfo(File file) {
patchBundleInfo.setVersion(artifactBundleInfo.getVersion());
patchBundleInfo.setPatchType(bundleTypes.get(artifactBundleInfo.getPkgName()) == null? 0:bundleTypes.get(artifactBundleInfo.getPkgName()));
patchBundleInfo.setName(artifactBundleInfo.getPkgName());
if (!modifyBundles.contains(artifactBundleInfo.getPkgName())){
if (!modifyBundles.contains(artifactBundleInfo.getPkgName().replace("_","."))){
patchBundleInfo.setInherit(true);
}
patchBundleInfo.setApplicationName(artifactBundleInfo.getApplicationName());
Expand All @@ -676,7 +676,7 @@ public PatchInfo createBasePatchInfo(File file) {
patchBundleInfo.setDependency(artifactBundleInfo.getDependency());
patchBundleInfo.setBaseVersion(artifactBundleInfo.getBaseVersion());
patchInfo.getBundles().add(patchBundleInfo);
} else if (modifyBundles.contains(artifactBundleInfo.getPkgName())) {
} else if (modifyBundles.contains(artifactBundleInfo.getPkgName().replace("_","."))) {
PatchBundleInfo patchBundleInfo = new PatchBundleInfo();
patchBundleInfo.setNewBundle(false);
patchBundleInfo.setMainBundle(false);
Expand Down

0 comments on commit d21a3ef

Please sign in to comment.