1

I am working with an Android App written on Java and I need an external java file that imports some Kotlin Classes:

import kotlin.Pair;
import kotlin.Unit;
import kotlin.collections.CollectionsKt;
import kotlin.jvm.functions.Function1;
import kotlin.jvm.functions.Function2;

I just cannot find any information on how to edit my Gradle scripts that the compiler is able to resolve those classes. When trying to run I only get the error org.gradle.api.GradleException: Please initialize at least one Kotlin target in 'app (:app)'

An instance of this class is created in my MainActivity.

My build.gradle for the Module contains the plugin id 'org.jetbrains.kotlin.multiplatform' version '1.5.10' and the dependencies

implementation 'androidx.core:core-ktx:1.5.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib:1.5.10"

I am quite new to Gradle build scripts and I have no idea what I am doing wrong.

EDIT: I am using Gradle 7.0.1

1 Answer 1

3

Add this to your project-level build.gradle

    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

And to the top of your app-level build.gradle file:

    apply plugin: 'kotlin-android'

You may refer to this in case you still face any issues.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.