Single flavor module based on multi flavor library in Gradle

被刻印的时光 ゝ 提交于 2019-12-01 15:37:25

My gradle version is 4.4.

In doc, Android developer and Android Plugin DSL Reference show that, should add follow code.

missingDimensionStrategy 'external'
missingDimensionStrategy 'target'

Android developer link image

Android Plugin DSL Reference image

but it not work for me. Finally I add follow code in feature.gradle.

flavorDimensions 'target'

 productFlavors {
    internal {
        dimension "target"
    }
}

From your question, what I get is that you trying to add the library tracker to your feature module as dependency. In your feature.gradle try the following:

dependencies {
    implementation project(':tracker')
}

With Gradle 3.0, there are two new keywords implementation and api. compile keyword is deprecated. You can use implementation as default. Use api especially when you have a transitive dependencies in your project (Module -> Lib1 -> Lib2), and you need to tell Gradle that the module wants to transitively export that dependency to other modules, so that it's available to them at both runtime and compile time.

Good pictorial explanation:

Here is a good article telling difference between the implementation and api keyword: Implementation Vs Api in Android Gradle plugin 3.0

Official doc explanation:

Here is a brief explanation from the official documentation Use the new dependency configurations:

  • Implementation:

    When your module configures an implementation dependency, it's letting Gradle know that the module does not want to leak the dependency to other modules at compile time. That is, the dependency is available to other modules only at runtime. Using this dependency configuration instead of api or compile can result in significant build time improvements because it reduces the amount of projects that the build system needs to recompile. For example, if an implementation dependency changes its API, Gradle recompiles only that dependency and the modules that directly depend on it. Most app and test modules should use this configuration.

  • api:

    When a module includes an api dependency, it's letting Gradle know that the module wants to transitively export that dependency to other modules, so that it's available to them at both runtime and compile time. This configuration behaves just like compile (which is now deprecated), and you should typically use this only in library modules. That's because, if an api dependency changes its external API, Gradle recompiles all modules that have access to that dependency at compile time. So, having a large number of api dependencies can significantly increase build times. Unless you want to expose a dependency's API to a separate test module, app modules should instead use implementation dependencies.

Hope this helps.


Update

For completeness sake, it seems there is a known issue with with gradle 4.1. Using version 4.3 helps. Thanks to Damien.

Try to add this in app build.gradle defaultConfig block:

missingDimensionStrategy "internal"

Ok thanks to @ramin-eftekhari I managed to make it work

https://github.com/luxsypher/gradle-flavor-dependency

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