在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):cashapp/zipline开源软件地址(OpenSource Url):https://github.com/cashapp/zipline开源编程语言(OpenSource Language):C 74.9%开源软件介绍(OpenSource Introduction):ZiplineThis library streamlines using Kotlin/JS libraries from Kotlin/JVM and Kotlin/Native programs. It makes it fetching code as easy as fetching data:
Zipline works by embedding the QuickJS JavaScript engine in your Kotlin/JVM or Kotlin/Native program. It's a small and fast JavaScript engine that's well-suited to embedding in applications. (Looking for Duktape Android?) Code ExampleLet's make a trivia game that has fresh questions every day, even if our users don't update their
apps. We define our interface in interface TriviaService : ZiplineService {
fun games(): List<TriviaGame>
fun answer(questionId: String, answer: String): AnswerResult
} Next we implement it in class RealTriviaService : TriviaService {
// ...
} Let's connect the implementation running in Kotlin/JS to the interface running in Kotlin/JVM. In
@JsExport
fun launchZipline() {
val zipline = Zipline.get()
zipline.bind<TriviaService>("triviaService", RealTriviaService())
} Now we can start a development server to serve our JavaScript to any running applications that request it. $ ./gradlew samples:trivia:trivia-js:jsBrowserProductionRun --info --continuous Note that this Gradle won't ever reach 100%. That's expected; we want the development server to stay
on. Also note that the You can see the served application manifest at localhost:8080/manifest.zipline.json. It references all the code modules for the application. In suspend fun launchZipline(dispatcher: CoroutineDispatcher): Zipline {
val manifestUrl = "http://localhost:8080/manifest.zipline.json"
val loader = ZiplineLoader(dispatcher, OkHttpClient())
return loader.loadOrFail("trivia", manifestUrl) {
val moduleName = "./zipline-root-trivia-js.js"
it.quickJs.evaluate(
"require('$moduleName').app.cash.zipline.samples.trivia.launchZipline()",
"launchZiplineJvm.kt"
)
}
} Now we build and run the JVM program to put it all together. Do this in a separate terminal from the development server! $ ./gradlew samples:trivia:trivia-host:shadowJar
java -jar samples/trivia/trivia-host/build/libs/trivia-host-1.0.0-SNAPSHOT-all.jar Interface bridgingZipline makes it easy to share interfaces with Kotlin/JS. Define an interface in Bridged interfaces must extend By default, arguments and return values are pass-by-value. Zipline uses kotlinx.serialization to encode and decode values passed across the boundary. Interface types that extend from Interface functions may be suspending. Internally Zipline implements Zipline also supports FastOne potential bottleneck of embedding JavaScript is waiting for the engine to compile the input source code. Zipline precompiles JavaScript into efficient QuickJS bytecode to eliminate this performance penalty. Another bottleneck is waiting for code to download. Zipline addresses this with support for modular applications. Each input module (Like Kotlin's standard, serialization, and coroutines libraries) is downloaded concurrently. Each downloaded module is cached. Modules can also be embedded with the host application to avoid any downloads if the network is unreachable. If your application module changes more frequently than your libraries, users only download what's changed. If you run into performance problems in the QuickJS runtime, Zipline includes a sampling profiler. You can use this to get a breakdown of how your application spends its CPU time. Developer-FriendlyZipline implements Zipline integrates Kotlin source maps into QuickJS bytecode. If your process crashes, the stacktrace
will print After using a bridged interface it must be closed so the peer object can be garbage collected. This
is difficult to get right, so Zipline borrows ideas from LeakCanary and aggressively detects
when a RequirementsZipline works on Android 4.3+ (API level 18+), Java 8+, and Kotlin/Native. Zipline uses unstable APIs in its implementation and is sensitive to version updates for these components.
We intend to use stable APIs as soon as they are available. We intend to keep Zipline host and runtime releases interoperable so you can upgrade each independently.
License
Duktape-AndroidThis project was previously known as Duktape-Android and packaged the Duktape JavaScript engine for Android. The Duktape history is still present in this repo as are the release tags. Available versions are listed on Maven central. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论