android - 依赖配置

标签 android configuration dependencies

我知道如果我创建一个使用产品 flavor 的库,那么当我在应用程序中使用该库时,我可以在 gradle 中执行此操作:

dependencies {
    flavor1Compile(path: '{path}', configuration: 'flavor1Config')
    flavor2Compile(path: '{path}', configuration: 'flavor2Config')
}

我也知道我可以做到:

dependencies {
    debugCompile(path: '{path}', configuration: 'debugConfig')
    releaseCompile(path: '{path}', configuration: 'releaseConfig')
}

我想做的基本上是这样的:

dependencies {
    flavor1DebugCompile(path: '{path}', configuration: 'flavor1DebugConfig')
    flavor1ReleaseCompile(path: '{path}', configuration: 'flavor1ReleaseConfig')
    flavor2DebugCompile(path: '{path}', configuration: 'flavor2DebugConfig')
    flavor2ReleaseCompile(path: '{path}', configuration: 'flavor2ReleaseConfig')
}

但是这段代码产生了这个:

Error:(30, 0) Gradle DSL method not found: 'flavor1DebugCompile()' Possible causes:

  • The project 'android' may be using a version of Gradle that does not contain the method. Open Gradle wrapper file
  • The build file may be missing a Gradle plugin. Apply Gradle plugin
  • 有办法吗?

    最佳答案

    an open bug on the Android issue tracker支持这一点。

    截至目前,您可以通过为每个要使用的组合声明这样的配置来完成此操作:

    configurations {
      flavor1DebugCompile
    } 
    
    dependencies {
      flavor1DebugCompile(path: '{path}', configuration: 'flavor1DebugConfig')
    }
    

    关于android - 依赖配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36729260/

    相关文章:

    python - 使用 aumbry 支持加密和非加密配置

    grails - 无法将 spring-security-ldap 2.0.1 解析为 Grails 2.4.4

    android - 使用 Chrome 自定义选项卡进行 SSO 登录

    python - 属性错误 : 'Settings' object has no attribute 'ROOT_URLCONF' on Heroku

    mysql - ERROR 2013 (HY000) : Lost connection to MySQL server at 'reading initial communication packet' , 系统错误:54

    javascript - npm install 找不到新版本

    java - 将 Maven 用于具有外部依赖项的客户端-服务器项目

    android - 在 fragment 中设置新布局

    android - 如何使音量摇杆影响当前未播放的流?

    Android EditText 或可能的 OnClickEvent 问题