Skip to content
Winterreisender edited this page Feb 24, 2023 · 2 revisions

Prerequisites

Platform Prerequisites
Windows Developers and end-users must have the WebView2 runtime installed on their system for any version of Windows before Windows 11.
Linux The GTK and WebKit2GTK libraries are required for development and distribution.

See webview#prerequisites for more information.

Using Gradle with Kotlin/JVM and Java

  1. Add GitLab Packages for Gradle
    webviewko is published in GitLab Package Registry, so you need to add webviewko's maven repo by using:
repositories {
    maven("https://gitlab.com/api/v4/projects/38224197/packages/maven")
}
  1. Import webviewko
dependencies {
    implementation("com.github.winterreisender:webviewko:0.2.0")
    implementation("com.github.winterreisender:webviewko-jvm:0.2.0")
}

Using Gradle with Kotlin/Native

These steps is no longer required in 0.6, except Linux.

  1. Add GitLab Packages for Gradle
    webviewko is published in GitlLab Package Registry, so you need to add webviewko's maven repo by using:
repositories {
    maven("https://gitlab.com/api/v4/projects/38224197/packages/maven")
}
  1. Import webviewko
kotlin {
    ...
    sourceSets {
        val nativeMain by getting {
            dependencies {
                implementation("com.github.winterreisender:webviewko-linux:0.2.0-SNAPSHOT")
            }
        }
        val nativeTest by getting
    }
}
  1. Download dll/so/dylib for your OS
    Like other native dynamic link lib, you need to make sure your program (.exe) can find the dynamic libs (.dll, .so, .dylib).
    You can find these files in the webviewko's project or in webview_nativebuild

  2. Link the dynamic lib (For Linux and macOS)
    Add linkerOpts to link the .so or .dylib. Suppose you save these files at native/src/nativeMain/resources/linuxx64/, native/src/nativeMain/resources/mingwx64/ and native/src/nativeMain/resources/macosx64/
    You also need change the rpath for you program to find the .so file by adding -Wl,-rpath=$ORIGIN

kotlin{
    ...
    nativeTarget.apply {
        binaries {
            executable {
                entryPoint = "main"
                if(hostOs == "Linux") 
                    linkerOpts("native/src/nativeMain/resources/linuxx64/libwebview.so","-Wl,-rpath=${'$'}ORIGIN")
                if(hostOs == "Mac OS X") 
                    linkerOpts("native/src/nativeMain/resources/macosx64/libwebview.dylib","-Wl,-rpath=${'$'}ORIGIN")
            }
        }
    }
}
  1. Copy .so/.dll/.dylib to output folder.
    You can either do it manually or using Gradle:
kotlin{
    nativeTarget.apply {
        binaries {
            executable {
                copy {
                    from(rootDir.resolve("native/src/nativeMain/resources/linux"))
                    into(outputDirectory)
                    include("*.dll", "*.dylib", "*.so")
                    duplicatesStrategy= DuplicatesStrategy.WARN
}}}}}

A full example can be found at Winterreisender/webviewkoCLI

Use .jar manually

  1. Download .jar from GitHub Releases
  2. Copy webviewko-0.0.1.jar to your project, suppose it in src/main/libs/webviewjar-0.0.1.jar
  3. If you are using a build system like Gradle, Maven, you need to manually add webviewko as local dependency for your project. In Gradle, you need:
    dependencies {
        implementation(fileTree(mapOf(
            "dir" to "src/main/libs",
            "include" to listOf("*.jar")
        )))
    }

Use GitHub Packages

Please notice that GitHub Maven service doesn’t allow for unauthorized access (see How to allow unauthorised read access to GitHub packages maven repository? ) You can read GitHub docs to Learn more about Maven or Gradle

repositories {
    maven {
        url = uri("https://maven.pkg.github.com/Winterreisender/webviewko")
        credentials {
            username = "YOUR-USERNAME"
            password = "YOUR-GITHUB-TOKEN"
        }
    }
}