Kotlin 用于基于 Cordova/Ionic 的插件 [英] Kotlin for a Cordova/Ionic based plugin

查看:32
本文介绍了Kotlin 用于基于 Cordova/Ionic 的插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将 Kotlin 用作框架/语言作为 Cordova 插件?

is it possible to use Kotlin as a framework/language as a Cordova plugin?

第一个问题是它没有复制 .kt 文件,因为它会查找 *.java 或 *.xml

first issue is that it's not copying the .kt file, because it looks for *.java or *.xml

如果有人知道如何设置的参考?

if so anyone know a reference on how to setup?

推荐答案

最近我一直在 Cordova 插件中使用 Kotlin,但是当我开始时,我也找不到任何关于如何创建 Cordova 的现有参考资料使用 Kotlin 的插件.

Recently I've been working with Kotlin in Cordova plugins, but when I started out I also couldn't find any existing references as to how to create a Cordova plugin using Kotlin.

所以我创建了一个示例插件,您可以将其用作模板:
https://github.com/dpa99c/cordova-plugin-hello-kotlin

So I've created an example plugin which you can use as a template:
https://github.com/dpa99c/cordova-plugin-hello-kotlin

如您所见,Cordova 插件界面上的 native 部分是 在 Kotlin 中实现.

As you can see, the native part on the Cordova plugin interface is implemented in Kotlin.

由于目前 cordova-android@7 不隐式支持 Kotlin,该插件使用钩子脚本来设置 Cordova 为 Kotlin 创建的原生 Android 项目,并删除 .卸载插件时从平台项目中获取 kt 文件,因为当前 cordova-android@7 仅对 .java 文件执行此操作.

Because currently cordova-android@7 doesn't implicitly support Kotlin, the plugin uses hook scripts to set up the native Android project created by Cordova for Kotlin, and also to remove .kt files from the platform project when the plugin is uninstalled, since currently cordova-android@7 only does this for .java files.

但它有效,您可以使用 测试应用程序项目进行尝试.

But it works and you can try it out with the test app project.

这篇关于Kotlin 用于基于 Cordova/Ionic 的插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆