【问题标题】:How do I change the build variant for a library dependency module?如何更改库依赖模块的构建变体?
【发布时间】:2023-03-19 16:43:01
【问题描述】:

我有一个依赖于“核心”模块的“移动”模块,但我不断收到相同的不一致错误:

mobile/build.gradle:

    debug {
        buildConfigField "String", "URL_SEARCH", "\"https://mobile.debug\""
    }
    release {
        buildConfigField "String", "URL_SEARCH", "\"https://mobile.release\""
    }

核心/build.gradle:

    debug {
        buildConfigField "String", "URL_SEARCH", "\"https://core.debug\""
    }

    release {
        buildConfigField "String", "URL_SEARCH", "\"https://core.release\""
    }

每当我将我的变体设置为移动调试 + 核心调试时,我仍然会在我的 core.MyApplication.java 文件中得到相同的输出:'https://core.release':

【问题讨论】:

    标签: java android


    【解决方案1】:

    每当您的模块导入另一个依赖模块时,依赖模块都会使用它的“发布”变体。

    见:BuildConfig.DEBUG always false when building library projects with gradle

    解决方案是使用你的 com.main.module.BuildConfig.DEBUG 变量,而不是你的 com.dependency-module.BuildConfig.DEBUG...因为这个调试总是错误的。

    【讨论】:

      猜你喜欢
      • 2017-09-09
      • 1970-01-01
      • 2014-11-18
      • 2015-01-23
      • 1970-01-01
      • 2014-10-18
      • 2023-02-02
      • 1970-01-01
      相关资源
      最近更新 更多