[英]Import Kotlin class in Java Code - Android studio
I am working with an Android App written on Java and I need an external java file that imports some Kotlin Classes:我正在使用在 Java 上编写的 Android 应用程序,我需要一个外部 java 文件来导入一些 Z5397FBB129:
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.我只是找不到任何关于如何编辑编译器能够解析这些类的 Gradle 脚本的信息。 When trying to run I only get the error
org.gradle.api.GradleException: Please initialize at least one Kotlin target in 'app (:app)'
尝试运行时,我只收到错误
org.gradle.api.GradleException: Please initialize at least one Kotlin target in 'app (:app)'
An instance of this class is created in my MainActivity.这个 class 的一个实例是在我的 MainActivity 中创建的。
My build.gradle
for the Module contains the plugin id 'org.jetbrains.kotlin.multiplatform' version '1.5.10'
and the dependencies我的模块的
build.gradle
包含插件id 'org.jetbrains.kotlin.multiplatform' version '1.5.10'
和依赖项
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.我对 Gradle 构建脚本很陌生,我不知道我做错了什么。
EDIT: I am using Gradle 7.0.1编辑:我正在使用 Gradle 7.0.1
Add this to your project-level build.gradle
将此添加到您的项目级
build.gradle
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
And to the top of your app-level build.gradle
file:在您的应用程序级
build.gradle
文件的顶部:
apply plugin: 'kotlin-android'
You may refer to this in case you still face any issues.如果您仍然遇到任何问题,您可以参考这里。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.