简体   繁体   English

在build.gradle中编译的选择性模块

[英]Selective module compiling in build.gradle

is there a way to selectively compile modules per flavor? 有没有一种方法可以根据口味有选择地编译模块?

I am trying to reduce build time in development by not compile various modules when running debug flavor. 我试图通过运行debug时不编译各种模块来减少开发中的构建时间。

in Eclipse, I would not put them in the libs folder and instead put them in the addon-libs and compile them only when exporting (via a gradle build script) and in the code have something like this: 在Eclipse中,我不会将它们放在libs文件夹中,而是将它们放在addon-libs并且仅在导出时(通过gradle构建脚本)对其进行编译,并且在代码中具有以下内容:

try {
   if(Class.forName(clazz) {
      doStuffForLib();
   }
} catch (ClassNotFoundException ex) {
   // DO NOTHING
}

my question is, can I do something similar in my build.gradle now and reduce build time some more? 我的问题是,我现在可以在build.gradle中做类似的事情并减少构建时间吗?

ie, I would write something like this 即,我会写这样的东西

buildTypes {
   debug{
   }

   release {
      compile 'some.module:version:1.+'
   }
}

You can achieve it with flavors or buildTypes using. 您可以使用flavors或buildTypes实现它。

dependencies {
    flavor1Compile xxx
    debugCompile xxxx
}

After searching around I found this JIRA ticket that fixed my issue. 搜索后,我发现这张JIRA票修复了我的问题。

You can supply compiles per version and use the provided dependency task for the others while maintaining the code provided for avoiding use of modules that weren't compiled when they aren't present as such 您可以按版本提供编译,并为其他版本使用provided依赖项任务,同时保留提供的代码,以避免使用未提供的未编译模块(如未提供)

public boolean isClassFound(String clazz) {
    try {
        return Class.forName(clazz);
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
    return false
}

And in the build.gradle add: 并在build.gradle添加:

dependencies {
    provided 'some.module:version:1.+'
    releaseCompile 'some.module:version:1.+'
}

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

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