Android studio3.x New Dependency mode (Implementation, API, Compileonly)

Source: Internet
Author: User

78366985?locationnum=6&fps=1

Android Studio3.0 official version has come out, compared to the 2.x version, the compilation speed has improved a lot.
When we use AS3.0 to create a new project, we find that the default dependency is changed from the previous compile to implementation.

Let's take a look at their previous differences:

The first is the 2.x version of the dependency mode:

Take another look at the 3.0:

As you can see in Android studio3.0, compile dependencies have been deprecated, replaced by implementation and API, provided replaced by compile only, APK is replaced by runtime only, The rest of the names will tell.

Let's look at the difference between the implementation and the API:

API: Exactly the same as the 2.x version of compile

Implementation: This module can only be used internally, such as when I use implementation in a libiary to rely on the Gson library, and then my main project relies on Libiary, then my main project cannot access the methods in the Gson library. The advantage of this is that the compilation speed will be faster, it is recommended to use the implementation way to rely on, if you need to provide external access, then use API dependency can be

You are not familiar with the 2.x version dependency can look at the following instructions, in parentheses corresponds to the 3.0 version of the dependency mode.

Compile (API)

This is the most common way in which libraries that rely on this approach will be involved in compiling and packaging.
When we rely on some third-party libraries, You may encounter a com.android.support conflict, because the developer uses a compile-dependent com.android.support package, and the package he relies on is not the same as the version of the Com.android.support package that we rely on locally, so we will report all Com.android.support libraries must use the exact same version specification (mixing versions can leads to runtime crashes this A mistake.

The solution can be seen in this blog: Com.android.support conflict resolution

Provided (Compileonly)

Only valid at compile time, not involved in packaging
You can use this method in your own moudle to avoid conflicts by relying on libraries that are commonly used by users such as Com.android.support,gson.

APK (runtimeonly)

Only when the APK is generated to participate in the package, the compilation will not participate, rarely used.

Testcompile (testimplementation)

Testcompile only works when the unit test code is compiled and eventually packaged to test the APK.

Debugcompile (debugimplementation)

Debugcompile only works when the debug mode is compiled and the final debug apk is packaged

Releasecompile (releaseimplementation)

Release compile only for release mode compilation and final release APK package.

Android studio3.x New Dependency mode (Implementation, API, Compileonly)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.