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

RegisterTransform remove jar #964

Closed
trycatchx opened this issue Nov 5, 2021 · 2 comments
Closed

RegisterTransform remove jar #964

trycatchx opened this issue Nov 5, 2021 · 2 comments

Comments

@trycatchx
Copy link

trycatchx commented Nov 5, 2021

'com.alibaba:arouter-register:1.0.2'

描述:
当把projectA.aar 替换成相对应的 projectA 工程。在不 clean 情况下,以下目录有两个一模一样的 jar (解压后 class 是一样的)

 app/build/intermediates/transforms/com.alibaba.arouter/develop/debug/11.jar
app/build/intermediates/transforms/com.alibaba.arouter/develop/debug/12.jar

猜测:
RegisterTransform 的 transform 没有实现 REMOVED 操作。导致旧的jar 没有移除。详情可以看:
com.android.build.gradle.internal.transforms.ExtractJarsTransform.java

switch (jarInput.getStatus()) {
                     ...
                        case REMOVED:
                            executor.execute(new Callable<Void>() {
                                @Override
                                public Void call() throws Exception {
                                    delete(outJarFolder);
                                    return null;
                                }
                            });
                            break;
                    }
望答复!不胜感激
@trycatchx
Copy link
Author

trycatchx commented Nov 7, 2021

看到了最新代码对这个问题做了处理: #867
主要加入了:

 if (!isIncremental){
            outputProvider.deleteAll()
        }

我用最新代码编译出的插件,目前已经没有这个问题。(最新插件版本是1.0.2没有包含这个merged的代码)

@trycatchx
Copy link
Author

trycatchx commented Nov 7, 2021

目前 RegisterTransform 不做增量,对项目整体的编译速度拖慢非常多,特别是 buildDex 这个task ,由于 每个 jar 都需要跑 ScanUtil.scanJar(src, dest)。

解决以上问题我这边有两个思路:
1、开启 增量更换以下下代码:并剔除 outputProvider.deleteAll()

if (!isIncremental) {
                    //scan jar file to find classes
                    if (ScanUtil.shouldProcessPreDexJar(src.absolutePath)) {
                        ScanUtil.scanJar(src, dest)
                    }
                    FileUtils.copyFile(src, dest)
                } else {
                 switch (jarInput.getStatus()) {
                        case Status.CHANGED:
                        case Status.ADDED:
                            if (ScanUtil.shouldProcessPreDexJar(src.absolutePath)) {
                                ScanUtil.scanJar(src, dest)
                            }
                            FileUtils.copyFile(src, dest, false)
                            break
                        case Status.REMOVED:
                            if (dest.exists()) {
                                dest.delete()
                            }
                            break
                        case Status.NOTCHANGED:
                            FileUtils.copyFile(src, dest, false)
                            break
                    }
                    }
                }

2、不使用transform,在apt 生成 IRouteRoot 实现类的时候,记录到 工程目录的 json 文件。代码运行通过 read json file 找到类的名字,反射调用即可。 (因为通过 transform+asm 实现这一点小功能感觉杀鸡用牛刀 )

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

1 participant