我无法在最终的AAR插件文件中插入依赖项

时间:2019-05-31 14:01:34

标签: android gradle plugins dependencies

我正在尝试将一些依赖项jar复制到classes.jar中,然后再将其组装到AAR中。下面的代码是从另一篇文章中复制的,并获取了我想要的文件,但是我无法将其与已在packaged-classes文件夹中创建的文件合并。

我已经尝试使用一些胖的aar插件,但是没有使它们起作用。

这就是我想要做的:

task copyDependencies << {
    android.libraryVariants.all { variant ->
        println "Executing"
        variant.getCompileClasspath().each { fileDependency ->
            def sourcePath = fileDependency.absolutePath
            def destinationPath = project.projectDir.path + "/build/intermediates/packaged-classes/debug"
            println "Copying dependency:"
            println sourcePath

            //The monstrous regex that gets the name of the lib from it’s exploded .aar path
            def dependencyName
            if (sourcePath.contains("classes.jar")) {
                def dependencyNameRegexResult = (sourcePath =~ /.*\/(.*)\.aar\/.*\/jars\/classes\.jar/)
                if (dependencyNameRegexResult.size() > 0) {
                    dependencyName = dependencyNameRegexResult[0][1]
                    println "Exploded AAR found : ${dependencyName}"
                }
            }

            copy {
                from sourcePath
                into destinationPath

                rename {String filename ->
                    if (filename.contains("classes.jar") && dependencyName != null) {
                        dependencyName = "${dependencyName}.jar"
                        println "Renaming dependency file to : ${dependencyName}"
                        return dependencyName
                    }
                    return filename
                }
            }
        }
    }
}

tasks.whenTaskAdded { task ->
    if (task.name == 'assembleDebug') {
        task.dependsOn copyDependencies
    }
}

执行此操作时,文件夹intermediates/packaged-classes在classes.jar内具有我的依赖项.jar,但是在outputs文件夹中只有我的插件.jar文件。

0 个答案:

没有答案