For the first time to get my latest articles, please follow my official account:Technical team

The build.gradle file in the new version of Android Studio 3.0 is now available.

Let’s look at the change in Dependencies in Moudle for a new project.

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com. Android. Support: appcompat - v7:26.1.0'
    implementation 'com. Android. Support. The constraint, the constraint - layout: 1.0.2'
    testImplementation 'junit: junit: 4.12'
    androidTestImplementation 'com. Android. Support. Test: runner: 1.0.1'
    androidTestImplementation 'com. Android. Support. Test. Espresso: espresso - core: 3.0.1'
}Copy the code

Now we’re going to see that compile, which we used to add dependencies to, is gone, and now we’re going to implement, so let’s see what that means.

In fact, in the new version of Android Gradle plugin 3.0, compile is marked as obsolete, and the two keywords implementation and API are replaced. So what’s the difference?

The API keyword is actually the same as compile. But why do you want to change the name? There is no relevant information yet. If you know, please leave a message.

Implementation: Dependency compiled with this command, which only provides an interface to the current Moudle. For example, our current project structure is as follows:

The project structure


Dependencies {.... implementation project (path:': libraryC')}Copy the code

So the interface in LibraryC is only available to LibraryA, and our App Moudle does not have access to the interface provided by LibraryC, that is, the dependency is hidden internally and not exposed to the outside world. That’s what the implementation keyword is for.

So why do it? The answer is: 1. Speed up compilation. 2. Hide unnecessary external interfaces.

Why does it speed up compilation? For large projects with multiple Moudle modules, the above picture shows an example. For example, if we change the relevant code of LibraryC interface, this compilation only needs to compile the LibraryA module separately. If we use API or old time compile, Since App Moudle also has access to LibraryC, the App Moudle section also needs to be recompiled. This is, of course, in full editing.

As for the comparison of compilation speed, there is a little brother abroad has done a simple comparison, the effect is still good. Address can click on the original jump to view the past.

So how do we change the dependencies in our existing project? The answer is: change compile to implementation and try to build the project, if it’s successful then congratulations, if it’s not successful then look at the dependencies and change them to API keyword dependencies.

Ok, today will introduce this knowledge point, if you have a harvest to pay attention to us, or give me a like it.