Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -110,47 +110,14 @@ public class Util {
def jarPath = jar.absolutePath
if (jarPath.contains(File.separator + FD_INTERMEDIATES + File.separator + "replugin-jar")) {
//
}else if (!jarPath.contains(projectDir)) {
String jarZipDir = project.getBuildDir().path +
File.separator + FD_INTERMEDIATES + File.separator + "exploded-aar" +
File.separator + Hashing.sha1().hashString(jarPath, Charsets.UTF_16LE).toString() + File.separator + "class";
if (unzip(jarPath, jarZipDir)) {
def jarZip = jarZipDir + ".jar"
includeJars << jarPath
classPath << jarZipDir
visitor.setBaseDir(jarZipDir)
Files.walkFileTree(Paths.get(jarZipDir), visitor)
map.put(jarPath, jarZip)
}
} else {
}else{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里无需if...else逻辑,jarPath不会有build临时目录

//重定向jar
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里严格说,不是重定向文件,只是将文件解压到临时目录。请移除该注释。

String md5 = md5File(jar);
File reJar = new File(injectDir + File.separator + md5 + ".jar");
jarPath = reJar.getAbsolutePath()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里不要复用之前的jarPath 变量,重新定义个reJarPath


boolean needInject = false
if (reJar.exists()) {
//检查修改插件版本
JarPatchInfo info = infoMap.get(jar.getAbsolutePath());
if (info != null) {
if(!activityMd5.equals(info.manifestActivitiesMd5)){
needInject = true
}else if (!AppConstant.VER.equals(info.pluginVersion)) {
//版本变化了
needInject = true
} else {
if (!md5.equals(info.jarMd5)) {
//原始jar内容变化
needInject = true
}
}
} else {
//无记录
needInject = true
}
} else {
needInject = true;
}
boolean needInject = checkNeedInjector(infoMap, jar, reJar, activityMd5, md5);

//设置重定向jar
setJarInput(jarInput, reJar)
if (needInject) {
Expand Down Expand Up @@ -194,6 +161,34 @@ public class Util {
return md5
}


def static checkNeedInjector( Map<String, JarPatchInfo> infoMap, File jar,File reJar,String activityMd5,String md5){
boolean needInject = false
if (reJar.exists()) {
//检查修改插件版本
JarPatchInfo info = infoMap.get(jar.getAbsolutePath());
if (info != null) {
if(!activityMd5.equals(info.manifestActivitiesMd5)){
needInject = true
}else if (!AppConstant.VER.equals(info.pluginVersion)) {
//版本变化了
needInject = true
} else {
if (!md5.equals(info.jarMd5)) {
//原始jar内容变化
needInject = true
}
}
} else {
//无记录
needInject = true
}
} else {
needInject = true;
}
return needInject;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

代码逻辑可以精简为:

def static checkNeedInjector(Map<String, JarPatchInfo> infoMap, File jar, File reJar, String activityMd5, String md5) {

        boolean needInject = true

        if (reJar.exists()) {
            JarPatchInfo info = infoMap.get(jar.getAbsolutePath());
            if (info != null) {
                if (activityMd5.equals(info.manifestActivitiesMd5)
                        && AppConstant.VER.equals(info.pluginVersion)
                        && md5.equals(info.jarMd5)) {
                    needInject = false
                }
            }
        }

        return needInject;
    }

/**
* 读取修改jar的记录
*/
Expand Down