The difference between Android Studio 3.x gradle dependency methods (implementation, api, provided, etc.)

Android Studio 3.0 obsolete many of the original instructions and replaced them with new instructions. The purpose is to speed up the compilation and build speed.

the difference

compile & api、implementation

api command

It is completely equivalent to the compile instruction, no difference, you change all compile to api, there is nothing wrong.

implementation instruction

The difference between implementation and api lies in external visibility. The feature of this instruction is that for dependencies compiled with this command, projects that depend on the project will not be able to access any programs in the dependencies compiled with this command, that is, the dependency is hidden internally and not exposed to the outside. .

Simply put, the dependencies using the implementation directive will not be passed. For example, there is a module named mylib, and mylib depends on fastjson:

implementation 'com.alibaba:fastjson:1.2.41'

At this time, the java code in mylib can access fastjson. The other module is app, which depends on mylib:

implementation project(':mylib')

At this time, because mylib uses the implementation command to rely on fastjson, fastjson cannot be referenced in the app. However, if mylib uses api to reference fastjson: api'com.alibaba:fastjson:1.2.41'

The effect is exactly the same as the compile instruction before gradle3.0.0. The app module can also reference fastjson, which is the difference between api and implementation.

provided & compileOnly

provided only provides compilation support, but will not write apk. Use provide to avoid support package version conflicts.

 

 

 

 

 

 

 

 

 

 

Guess you like

Origin blog.csdn.net/MYBOYER/article/details/102580261