英文:
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
,并指定您想要使用testData
的app
模块的哪个变种。
请参考此链接以获取用法: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 oftestData
and mention which variant ofapp
module you want to usetestData
Please refer this link for the usage: https://developer.android.com/build/build-variants#resolve_matching_errors
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论