Dependency configurations

我的梦境 提交于 2019-12-24 00:35:26

问题


I know that if I make a library that uses product flavors, then when I use that library in an application, I can do this in a gradle:

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

I also know that I can do this:

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

What I want to do is essentially this:

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

But that code produces this:

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
  • Is there a way to do this?


    回答1:


    There is an open bug on the Android issue tracker to support this.

    As of right now, you can accomplish this by declaring a configuration like so for each combination you want to use:

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


    来源:https://stackoverflow.com/questions/36729260/dependency-configurations

    易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
    该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!