如何在我的Gradle模块和“app”模块之间添加多个风格的依赖关系?

huangapple go评论66阅读模式
英文:

How to Add dependency between my gradle module and the "app" module with multiple flavors?

问题

问题:我如何配置Gradle以在多个flavor之间建立testData模块和app模块的依赖关系?

我目前正在进行基于Gradle的Android项目开发,我创建了一个名为testData的模块,它需要依赖于app模块。然而,app模块有多个flavor,我不确定在考虑到不同flavor的情况下设置这种依赖的正确方法。

我尝试使用这种方法,但它不起作用:

implementation project(path: ':app', configuration: 'myFlavor')

这是我收到的错误信息:

Project :testData declares a dependency from configuration 'implementation' to 
configuration 'myFlavor', which is not declared in the descriptor for project :app.

关于在Gradle中实现这种配置的任何指导或建议将不胜感激。谢谢!

英文:

Question: How can I configure Gradle to establish a dependency between my testData module and the app module with multiple flavors?

I'm currently working on a Gradle-based Android project, where I've created a module named testData that needs to depend on the app module. However, the app module has multiple flavors, and I'm unsure about the correct approach to set up this dependency, considering the different flavors.

I tried to use this approach, but it is not working:

implementation project(path: ':app', configuration: 'myFlavor')

Here is the error I am getting

Project :testData declares a dependency from configuration 'implementation' to 
configuration 'myFlavor', which is not declared in the descriptor for project :app.

Any guidance or suggestions on achieving this configuration in Gradle would be greatly appreciated. Thank you!

答案1

得分: 1

The approach you mentioned does not work now with Android. Android has its own ART runtime and a few different processes than the normal JVM build process.

Android developer docs do provide you with something for your situation.

You have two options:

  • 要么为 testData 创建相同数量的构建变种,以便 Gradle 可以为您进行匹配。
  • 或者在 testData 的 build.gradle 脚本中使用 matchingFallbacks,并指定您想要使用 testDataapp 模块的哪个变种。

请参考此链接以获取用法:https://developer.android.com/build/build-variants#resolve_matching_errors

英文:

Approach you mentioned does not work now with android. Android has its now own ART runtime and few different process than normal JVM build process.

Android developer docs do provide you something for your situation.

You have two options

  • Either create same amount of build flavors for testData so that gradle can do the matching for you

  • Use matchingFallbacks in your build.gradle script of testData and mention which variant of app module you want to use testData

Please refer this link for the usage: https://developer.android.com/build/build-variants#resolve_matching_errors

huangapple
  • 本文由 发表于 2023年5月25日 02:13:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/76326375.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定