What does transitive = true in Gradle exactly do (w.r.t. crashlytics)?

百般思念 提交于 2019-11-27 10:37:46

You are using the @aar notation.
It means that you want to download only the aar artifact, and no dependencies.
You can check this part of documentation:
Check the 1.4.1.2. Artifact only notation section:

An artifact only notation creates a module dependency which downloads only the artifact file with the specified extension. Existing module descriptors are ignored.

Using the @aar notation if you want to download the dependencies, you should add transitive=true.

I'd expect that omitting @aar it should work without adding the transitive attribute.

My guess is that the Crashlytics artifact to which you're referring manually specifies dependencies as not transitive (transitive=false) so that you aren't forced to bring those dependencies in by default. That's why you're seeing the opposite behavior. For example some developers may not want to pull in all of Google Play Services or whatever else Crashlytics may use if present.

So, by removing that, Gradle no longer pulls in the dependency, and it fails to build. You can specify that dependency manually if you need to.

That being said - I think the bigger issue at hand is that you shouldn't be referencing the Crashlytics artifact directly - you should be using Fabric, and pulling in Crashlytics as a result: https://dev.twitter.com/fabric/android/integrating

On a more general note: Setting transitive = false on the crashlytics library causes gradle to ignore all libraries required by crashlytics (="transient libraries") and not download and link them.

You would have to either manually add the required libraries to your project or rely on other transient libraries added by other dependencies.

Default for gradle is transitive = true.

Examples and full explanation here: http://www.devsbedevin.com/android-understanding-gradle-dependencies-and-resolving-conflicts/

Sets whether this dependency should be resolved including or excluding its transitive dependencies. The artifacts belonging to this dependency might themselve have dependencies on other artifacts. The latter are called transitive dependencies.

Gradle follows transitive dependencies by default. If you want to turn that off for a particular library, use the transitive flag.

Changing the value of the transitive flag to false prevents the download of transitive dependencies, so you’ll have to add whatever is required yourself. If you only want a module jar, without any additional dependencies, you can specify that as well.

By default, Gradle dependencies are transitive(transitive = true). Transitive dependencies are described more in Maven Repositories. One module may depend on other modules, and Gradle can discover those dependencies-of-dependencies when it resolves the declared dependency against a repository. This is almost always an enormous time-saver, but sometimes it can create problems.

If you depend on version 1 of module A and version 2 of module B, and module A transitively depends on version 3 of module B, you may not want Gradle to resolve that final dependency. The wrong version of a JAR file might make it into your compile or runtime classpath—and most Java developers know what a frustrating experience that can be.

Happily, you can alter transitive dependency resolution through disabling it:

transitive = false 

The source is here

transitive controls transitivity. Gradle normally defaults to transitive, except when it doesn't. There's a bug with transitivity and classifiers, see https://issues.gradle.org/browse/GRADLE-3188.

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