After updating to Android Studio 3.0 and creating a new project, I noticed that in build.gradle
there is a new way to add new dependencies instead of compile
there is implementation
and instead of testCompile
there is testImplementation
.
Example:
implementation 'com.android.support:appcompat-v7:25.0.0'
testImplementation 'junit:junit:4.12'
instead of
compile 'com.android.support:appcompat-v7:25.0.0'
testCompile 'junit:junit:4.12'
What's the difference between them and what should I be using?
Best Answer
tl;dr
Just replace:
compile
withimplementation
(if you don't need transitivity) orapi
(if you need transitivity)testCompile
withtestImplementation
debugCompile
withdebugImplementation
androidTestCompile
withandroidTestImplementation
compileOnly
is still valid. It was added in 3.0 to replace provided and not compile. (provided
introduced when Gradle didn't have a configuration name for that use-case and named it after Maven's provided scope.)It is one of the breaking changes coming with Android Gradle plugin 3.0 that Google announced at IO17.
The
compile
configuration is now deprecated and should be replaced byimplementation
orapi
From the Gradle documentation:
Note: if you are only using a library in your app module -the common case- you won't notice any difference.
you will only see the difference if you have a complex project with modules depending on each other, or you are creating a library.