Started in Gradle plugin 3.0 (Android Studio 3.0), the compile
command has been replaced with api
and implementation
. It is explained here https://blog.mindorks.com/implementation-vs-api-in-gradle-3-0-494c817a6fa
However, for a pure Kotlin module as below, I can't use api
. i.e. the below code will have error when I perform a sync
apply plugin: 'kotlin'
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
api "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
}
The error is
Could not find method api() for arguments [org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.2-4]
on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler. Open File`
I have to use the 'deprecated' compile
instead.
Why isn't api
supported when in a pure kotlin
module?
Open your project in Android Studio and select File > Settings... > Build, Execution, Deployment > Build Tools > Gradle (Android Studio > Preferences... > Build, Execution, Deployment > Build Tools > Gradle on a Mac).
Android Studio uses Gradle, an advanced build toolkit, to automate and manage the build process, while allowing you to define flexible custom build configurations. Each build configuration can define its own set of code and resources, while reusing the parts common to all versions of your app.
The build. gradle (Project: MyApplication) file is in the root folder of the project and its configuration settings apply to every module in the project.
The Android Gradle plugin (AGP) is the official build system for Android applications. It includes support for compiling many different types of sources and linking them together into an application that you can run on a physical Android device or an emulator.
compile
isn't deprecated in Gradle, but only in specific plugins, namely Android and Java Library plugins. The standard Java plugin hasn't made this change. Neither has the Kotlin plugin, yet. It probably will eventually (possibly after the issues described in the Java Library documentation will be solved).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With