Single flavor module based on multi flavor library in Gradle

前端 未结 4 1681
北海茫月
北海茫月 2021-01-17 15:07

I\'m working on a multi-flavor app. (gradle files below)

It uses a library called tracker that follow the same flavors internal

相关标签:
4条回答
  • 2021-01-17 15:50

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

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

    0 讨论(0)
  • 2021-01-17 15:51

    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.

    0 讨论(0)
  • 2021-01-17 15:52

    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"
        }
    }
    
    0 讨论(0)
  • 2021-01-17 15:56

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

    missingDimensionStrategy "internal"
    
    0 讨论(0)
提交回复
热议问题