RouterMappingTransform 未遍历app模块下的mapping

来源:6-6 实战:实现类的拷贝逻辑【实现Transform】

qq_青鸟_17

2024-02-25

适配Gradle 7.x这个分支的代码下,MainActivity里的按钮点击跳转是失效的,我跟踪下去发现最后的问题落在RouterMappingTransform.groovy中,transfrom方法里

        transformInvocation.inputs.each {

            // 把 文件夹 类型的输入,拷贝到目标目录
            it.directoryInputs.each { directoryInput ->
                def destDir = transformInvocation.outputProvider
                                .getContentLocation(
                                        directoryInput.name,
                                        directoryInput.contentTypes,
                                        directoryInput.scopes,
                                        Format.DIRECTORY)
                collector.collect(directoryInput.file)

                com.imooc.router.gradle.FileUtils.copyFolder(directoryInput.file.absolutePath, destDir.absolutePath)
            }

            // 把 JAR 类型的输入,拷贝到目标目录
            it.jarInputs.each { jarInput ->
                def dest = transformInvocation.outputProvider
                              .getContentLocation(
                                      jarInput.name,
                                      jarInput.contentTypes,
                                      jarInput.scopes, Format.JAR)
                collector.collectFromJarFile(jarInput.file)
                com.imooc.router.gradle.FileUtils.copyFile(jarInput.file, dest)
            }
        }

        println("${getName()} all mapping class name = "
                + collector.mappingClassName)

上面的代码中,最后的println 并不会打印app 模块所对应的mapping文件,最终生成的结果里也没有app模块里的activity
虽然定位到了问题,但是不知道该怎么该,请问该怎么改?

写回答

1回答

qq_青鸟_17

提问者

2024-02-25

最后的bug 是在于RouterMappmingCollector.groovy 中,windows系统文件路径是 

'com\imooc\router\mapping'

而我们定义的却是

PACKAGE_NAME = 'com/imooc/router/mapping'

就会造成无法识别

0
0

Android 应用程序构建实战+原理精讲

深度掌握 Gradle 使用,系统性学习 Android 应用构建知识

450 学习 · 116 问题

查看课程