Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

repackage 过程中文件夹路径找不到...\debug\25 does not exist(解决方案) #576

Closed
robining opened this issue May 18, 2018 · 5 comments

Comments

@robining
Copy link

robining commented May 18, 2018

问题详细描述 Detailed description of the problem

在项目集成插件的过程中,apply插件后,编译错误app\build\intermediates\transforms\desugar\UatNStore\debug\25 does not exist.

其它重要信息 Other important information

replugin-host-lib/gradle Version:2.2.4
rePlugin-plugin-lib/gradle Version:2.2.4

Logcat上下文 Logcat context

Unzip Jar ...
[unzip] Expanding: E:\AndroidWorkspace\NewZHD\user\app\build\intermediates\transforms\desugar\UatNStore\debug\24.jar into E:\AndroidWorkspace\NewZHD\user\app\build\intermediates\transforms\desugar\UatNStore\debug\24
Zip file is empty! Ignore
[unzip] Expanding: E:\AndroidWorkspace\NewZHD\user\app\build\intermediates\transforms\desugar\UatNStore\debug\26.jar into E:\AndroidWorkspace\NewZHD\user\app\build\intermediates\transforms\desugar\UatNStore\debug\26

------------------------------中间省略--------------------------------------

Repackage...
E:\AndroidWorkspace\NewZHD\user\app\build\intermediates\transforms\desugar\UatNStore\debug\23.jar
[zip] Building zip: E:\AndroidWorkspace\NewZHD\user\app\build\intermediates\transforms\desugar\UatNStore\debug\24.jar
:user:app:transformClassesWith___ReClass___ForUatNStoreDebug FAILED

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':user:app:transformClassesWith___ReClass___ForUatNStoreDebug'.

E:\AndroidWorkspace\NewZHD\user\app\build\intermediates\transforms\desugar\UatNStore\debug\25 does not exist.

####问题定位######
分析Replugin源码问题定位到com.qihoo360.replugin.gradle.plugin.inner.Util中

 /**
     * 压缩 dirPath 到 zipFilePath
     */
    def static zipDir(String dirPath, String zipFilePath) {
        new AntBuilder().zip(destfile: zipFilePath, basedir: dirPath)
    }

    /**
     * 解压 zipFilePath 到 目录 dirPath
     */
    def private static boolean unzip(String zipFilePath, String dirPath) {
        // 若这个Zip包是空内容的(如引入了Bugly就会出现),则直接忽略
        if (isZipEmpty(zipFilePath)) {
            println ">>> Zip file is empty! Ignore";
            return false;
        }

        new AntBuilder().unzip(src: zipFilePath, dest: dirPath, overwrite: 'true')
        return true;
    }

如果Zip内容是空的,那么直接忽略跳过,但是当repackage(zipDir)的时候,传入的dirPath是不存在的,引发的错误

####解决方案######
将上处修改为:

def static zipDir(String dirPath, String zipFilePath) {
        File file = new File(dirPath);
        if(file.exists()){
            new AntBuilder().zip(destfile: zipFilePath, basedir: dirPath)
        }else {
            println ">>> dirPath is not exist! Ignore!";
        }
    }

并在com.qihoo360.replugin.gradle.plugin.inner.ReClassTransform中的copyJar方法修改为:


    /**
     * 拷贝 Jar
     */
    def copyJar(TransformOutputProvider output, JarInput input) {
        File jar = input.file
        String jarPath = map.get(jar.absolutePath);
        if (jarPath != null) {
            jar = new File(jarPath)
        }

        String destName = input.name
        def hexName = DigestUtils.md5Hex(jar.absolutePath)
        if (destName.endsWith('.jar')) {
            destName = destName.substring(0, destName.length() - 4)
        }
        File dest = output.getContentLocation(destName + '_' + hexName, input.contentTypes, input.scopes, Format.JAR)
        if (jar.exists()) {
            FileUtils.copyFile(jar, dest)
        }else {
            println ">>> jar file is not exist! Ignore!";
        }

/*
        def path = jar.absolutePath
        if (path in CommonData.includeJars) {
            println ">>> 拷贝Jar ${path} 到 ${dest.absolutePath}"
        }
*/
    }

添加jar是否存在判断,如果存在才拷贝

@robining robining changed the title repackage 过程中文件夹路径找不到 repackage 过程中文件夹路径找不到...\debug\25 does not exist(解决方案) May 18, 2018
@sdgSnow
Copy link

sdgSnow commented Aug 1, 2018

请问下我们不是只是添加依赖么,怎么去修改源码呢,如果修改,应该怎么找到位置呢,求大神指教

@robining
Copy link
Author

robining commented Aug 1, 2018

@sdgSnow 我当时是fork出来自己再发布一个aar改的哈,最好还是等待官方改吧~

@Aplombs
Copy link

Aplombs commented Aug 1, 2018

@robining 方便把你修改过的AAR发出来参考一下吗 邮箱 [email protected] 非常感谢

@robining
Copy link
Author

robining commented Aug 1, 2018

@Aplombs com.github.robining:RePlugin:v2.2.5-alpha 改动地方可以看这里的提交记录https://github.com/robining/RePlugin/

@Aplombs
Copy link

Aplombs commented Aug 9, 2018

@robining 这个改完之后怎么用到自己的插件项目上呢?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants