zoukankan      html  css  js  c++  java
  • Gradle3.0新指令api、provided、implementation等对比

    Android Studio3.0正式版已经出来了,相比2.x的版本,Gradle版本也升级为了3.x,编译速度提高了不少。
    在gadle3.0之后,默认的依赖由之前的compile更改为implementation

    • 对比表

      Android Studio 2.XAndroid Studio 3.X
      apk runtimeOnly
      provided compileOnly
      compile api
      没有对应 implementation
      debugCompile debugImplementation
      releaseCompile releaseImplementation
      androidTestCompile androidTestImplementation
    • api (compile)

      • 依赖向上传递
      • 若A api B, B api C,C module对A module可见
    • implementation (新指令: 具备依赖可见性)

      • 依赖不向上传递

      • 若A implementation B, B implementation C,C module对A module不可见

      • 若A implementation B, B api C,C module对A module可见

      • 功能同api,区别仅仅是增加了依赖可见性

    • compileOnly(provided)

      • 只在编译时有效,不会参与打包
      • 若A implementation C,打包后apk(A + C);而A compileOnly C,打包后apk(A);该指令实质:A module假装依赖了C module通过欺骗编译器编译时检测以避免java.lang.ClassNotFoundException编译报错
      • 使用情形
        • A implementation C,B implementation C,打包时A module生成aar(A + C),B module生成aar(B + C)
        • 若改成A implementation C,B compileOnlyC,打包时A module生成aar(A + C),B module生成aar(B)
        • 最终apk包(A + B + C),结果一致
        • 虽然aar(B)不真实依赖C module,但B module确实用到了C module的api。没有运行时错误的原因:aar(A + C)与aar(B)合并生成apk,B module运行时找到并调用aar(A + C)中的C module
    • runtimeOnly(apk)

      只在生成apk的时候参与打包,编译时不会参与,很少用。

    • debugImplementation(debugCompile)

      debugImplementation 只在debug模式的编译和最终的debug apk打包时有效。

    • releaseImplementation(releaseCompile)

      releaseImplementation 仅仅针对release 模式的编译和最终的release apk打包。

    • androidTestImplementation(androidTestCompile)

      androidTestImplementation 只在单元测试代码的编译以及最终打包测试apk时有效。



    作者:Dsiner
    链接:https://www.jianshu.com/p/83ddb81e73f9
    来源:简书
    著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
  • 相关阅读:
    [SDOI2016]排列计数
    Broken robot
    环路运输
    naptime
    Accumulation Degree
    选课
    没有上司的舞会
    金字塔
    Polygon
    石子合并
  • 原文地址:https://www.cnblogs.com/Free-Thinker/p/11855946.html
Copyright © 2011-2022 走看看