简体   繁体   English

Gradle:将各种Jars添加为依赖项

[英]Gradle: Adding variant Jars as Dependencies

I have 5 productFlavors , of which each has their own jar dependency that I need to add when building. 我有5个productFlavors ,其中每个都有自己的jar依赖项,在构建时需要添加它们。 Everywhere I've searched, people say to add the following to dependencies: 人们在我搜索过的所有地方都说要在依赖项中添加以下内容:

dependencies {
    //Third party jars
    compile fileTree(include: ['*.jar'], dir: 'libs')
}

However, this seems to execute before each jar is created so it doesn't successfully compile anything until I run the build process for a second time. 但是,这似乎是在创建每个jar之前执行的,因此直到我第二次运行构建过程之前,它都无法成功编译任何内容。 Here is how I build the jars: 这是我制作罐子的方法:

android.applicationVariants.all { variant ->
        /** Lets build our thrift tasks for each productFlavor **/

        //Find pre-existing buildThrift task or create new one
        def String taskName = "buildThrift${variant.productFlavors[0].name}"
        def Task buildThrift = tasks.findByName(taskName)
        if (!buildThrift) {
            buildThrift = task "$taskName"(type: Exec) {
                workingDir rootDir
                commandLine './thrift-gen.sh'
            }
        }
        variant.javaCompile.dependsOn(buildThrift)
    }

What am I missing? 我想念什么? Or is my idea here not even possible to get working? 还是我的想法在这里甚至无法实现?

If I understand correctly you are creating jar files programmatically and want to add the same in build.gradle on runtime. 如果我理解正确,那么您正在以编程方式创建jar文件,并希望在运行时将它们添加到build.gradle中。 If this is the case, it seems it is not possible, as when the gradle project is build, it compiles all the dependencies. 如果是这种情况,似乎是不可能的,因为在构建gradle项目时,它将编译所有依赖项。

As an alternative, you need to create the jars separately and then add them to your gradle project. 或者,您需要分别创建jar,然后将其添加到gradle项目中。

Hope this help you. 希望这对您有所帮助。

Thanks Anurag 谢谢阿努拉格

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM