GCX-HCI / grandcentrix-LogALot-TransformAPI-sample

Example of using the android TranformAPI for bytecode manipulation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Question

dovodsc opened this issue · comments

Hi, thanks for very useful example!
I've ran into an issue.
When applying transform to a library it fails project build if any free function or variable are imported by the main app from the library.
But it I'll link the app to the output aar file produced by library build (with transform stage) - it builds just fine.
Any ideas how it can be fixed?

Thanks!

upd:
transformInput(inputDirectory, outputDir, pool)
without any transform logic:

   private fun transformInput(
        inputDirectory: DirectoryInput,
        outputDir: File,
        pool: ClassPool
    ) {
        inputDirectory.file.walkTopDown().forEach { originalClassFile ->
            if (originalClassFile.isClassfile()) {
                val classname = originalClassFile.relativeTo(inputDirectory.file).toClassname()
                val clazz = pool.get(classname)
//                transformClass(clazz)
                clazz.writeFile(outputDir.absolutePath)
            }
        }
    }

is not equal to:
inputDirectory.file.copyRecursively(outputDir, true)

upd:
it looks like the issue is if (originalClassFile.isClassfile()) {
it prevent to copy any non 'class' files to the dest directory and it causes issue with Kotlin libraries.
(some 'kotlin_module' magic filename)
So the fix is simple:

if isClass 
    performTransfrom()
    saveToDestDir
else
   saveToDestDir