What's the difference between implementation and compile in Gradle?

前端 未结 9 1441
北荒
北荒 2020-11-22 03:01

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 comp

9条回答
  •  有刺的猬
    2020-11-22 03:43

    Gradle 3.0 introduced next changes:

    • compile -> api

      api keyword is the same as deprecated compile

    • compile -> implementation

      Is preferable way because has some advantages. implementation expose dependency only for one level up at build time (the dependency is available at runtime). As a result you have a faster build(no need to recompile consumers which are higher then 1 level up)

    • provided -> compileOnly

      This dependency is available only in compile time(the dependency is not available at runtime). This dependency can not be transitive and be .aar. It can be used with compile time annotation processor and allows you to reduce a final output file

    • compile -> annotationProcessor

      Very similar to compileOnly but also guarantees that transitive dependency are not visible for consumer

    • apk -> runtimeOnly

      Dependency is not available in compile time but available at runtime.

    [POM dependency type]

提交回复
热议问题