Gradle:compileOnly和runtimeOnly

I'd read the documentation but I'm not able to understand how to create a working example to understand better their differences.

enter image description here

而且,我已经创建了一个游乐场项目来检查当我使用一个或另一个项目时会发生什么。

app.gradle

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$rootProject.kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.core:core-ktx:1.2.0'
    compileOnly project(":compileonlylibrary")
    runtimeOnly project(":runtimeonlylibrary")
}

MainActivity.kt

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        FooCompile() // this crash in runtime
        BarRuntime() // this doesn't compiles obviously
    }
}

就是这样,我被困在这里,我无法创建适当的示例来提高对Gradle配置的了解。

有人可以帮我吗?如果需要,我可以提供更多详细信息。

评论