我有一个Kotlin多平台设置,其中包括JS和Java部分。在common文件夹中,我编写了一些应编译为js的方法。如:
class test {
init {
println("this is completely working")
}
}
现在,当我构建我的项目时,在JS专有文件夹中会生成一个node_modules文件夹,其中包含上面的示例(尽管我希望Kotlin将println
转换为console.log
,但没有)。现在,我想包括此文件及其方法,以供另一个JS文件读取。那怎么办?不幸的是,关于这些多平台主题的文档很多,因此我很难完成最基本的工作。
您需要加载Kotlin / JS编译器生成的脚本。
SharedCode.js和BluetoothSerial.js都是由Kotlin / JS编译器生成的。
<head>
<title>WebView Callback Demo</title>
<script src="js/kotlin.js"></script>
<script src="js/SharedCode.js"></script>
</head>
<body>
<div id="root">
</div>
<script src="js/BluetoothSerialJs.js"></script>
</body>
然后您可以调用这样生成的javascript函数:
PackageName.Module.Function()
com.fivestars.bluetooth.BluetoothSerial.configureChannel()
示例项目在这里:
https://github.com/darran-kelinske-fivestars/cordova-alternative-pattern