Android Gradle Implementation vs CompileOnly Performance

后端 未结 1 683
轮回少年
轮回少年 2020-12-08 14:42

The docs mention that implementation provides significant build time improvements over compile/api. What about compileOnly

相关标签:
1条回答
  • 2020-12-08 14:47

    The api configuration should be used for dependencies that are exported to external modules (transitive dependency). Vice-Versa implementation configuration should be used for dependencies that are internal to the component (not transitive dependency).

    implementation vs compileOnly:

    There is no similarity in their job, compileOnly is

    • a configuration inherited from java-plugin
    • required at compile time
    • also not included in the runtime classpath or exposed to dependent projects.

    So compileOnly doesn't replace the implementation configuration job e.g:

    implementation 'com.android.support:appcompat-v7:25.1.0' // can't use compileOnly here
    testCompile 'junit:junit:4.12'
    
    compile "com.google.dagger:dagger:2.8" // can't use here also
    annotationProcessor "com.google.dagger:dagger-compiler:2.8" // can't use here also
    compileOnly 'javax.annotation:jsr250-api:1.0' // we can use compileOnly here because it's required on run time only.
    

    Since your case is a "multi-module", you have to use the api configuration, until you reach the final module it's better to use implementation.

    Following graph describe those configurations:

    Performance?

    I think api requires more memory because gradle will snapshot every class in that transitive module, vice versa implementation is a preferred configuration because (as mentioned above) it's used for its own internal implementations.

    0 讨论(0)
提交回复
热议问题