Skip to content

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

@robining

Description

@robining

问题详细描述 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是否存在判断,如果存在才拷贝

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions