Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plain Kotlin module in Android Studio 3.0, `api` is not supported?

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?

like image 596
Elye Avatar asked Oct 23 '17 06:10

Elye


People also ask

Where is gradle settings in Android Studio?

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).

Does android studio include gradle?

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.

Where is root build gradle?

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.

What is Android gradle plugin?

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.


1 Answers

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).

like image 173
Alexey Romanov Avatar answered Oct 19 '22 17:10

Alexey Romanov