简体   繁体   English

自动在gradle上添加模块依赖项

[英]Automaticly add module dependencies on gradle

I've an weird behavior when using modules on gradle with Android Studio... it's kind complicated to explain so i think is better to give an example 当在Android Studio的gradle上使用模块时,我的行为很怪异...解释起来有点复杂,所以我认为最好举个例子

Let say my application has two modules 假设我的应用程序有两个模块

:bar
:foo

foo uses play-services-location so I do import it on its build.gradle. foo使用play-services-location因此我确实将其导入到build.gradle中。 foo compiles fine. foo编译正常。

bar uses foo , so on build.gradle of bar's folder I do: bar使用foo ,所以在bar文件夹的build.gradle上我这样做:
api project(path: ':foo')
bar also uses play-services-location but as bar imports foo i think it should transitivelly import play-services-location however if I don't explicit do bar也使用play-services-location但是作为bar导入foo我认为应该过渡性地导入play-services-location但是如果我不明确的话,
implementation "com.google.android.gms:play-services-location:$location_library_version"
bar doesn't compile 条无法编译

So am I missing something? 那我想念什么吗? Shouldn't it automaticly import all the dependency dependencies... so any transitive dependency be ready and I didn't need to re-import it? 它不应该自动导入所有依赖项依赖项吗...这样任何传递性依赖项都准备好了,而我不需要重新导入它?

You should use 'api' (not 'implemenatation') for 'google-play-location' in 'foo', so it can be depended by 'bar' which uses 'foo'. 您应该对“ foo”中的“ google-play-location”使用“ api”(而不是“ implementatation”),因此它可以由使用“ foo”的“ bar”所依赖。 And if there is no other modules which depends on 'bar', it is better to specify 'implementation foo' in 'bar', not 'api' 而且,如果没有其他依赖于“ bar”的模块,则最好在“ bar”而不是“ api”中指定“ implementation foo”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM