Search code examples
kotlingradlejavafxmediapipe

How would you use Google MediaPipe for a desktop JavaFX application?


I want to use Google's Mediapipe for a Kotlin JavaFX Desktop application. However, I am encountering a few roadblocks, which brings up a few questions.

  • Since it is advertised as an Andriod library, can you even use it for non-andriod purposes?
  • How would I go about using Mediapipe for a JavaFX Kotlin application?
  • If you are able to use it, what am I doing wrong?

I tried importing it, similar to the documentation. My build.gradle.kts looks similar to the following, but with "myMainClass" replaced with the name of my class. (I am fairly new with gradle and build systems, so it is mostly copy-paste and could be a dumb mistake):

#Imports

plugins {
  java
  application
  kotlin("jvm") version "1.9.0"
  id("com.github.gmazzo.buildconfig") version "3.0.0"
  id("org.openjfx.javafxplugin") version "0.0.13"
}

val mainClass = "myMainClass"

buildConfig {
  buildConfigField ("long", "BUILD_TIME", "${System.currentTimeMillis()}L")
}

repositories {
  mavenCentral()
  google()
  jcenter()
  maven { setUrl("https://plugins.gradle.org/m2/") }
}

javafx {
  version = "19"
  modules = "javafx.controls,javafx.fxml".split(",").toMutableList()
}
application {
  mainClass = "myMainClass"
}

dependencies {
  implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2")
  implementation("org.jetbrains.kotlin:kotlin-stdlib")
  implementation("org.tensorflow:tensorflow-lite:2.5.0")
  implementation("org.tensorflow:tensorflow-lite-gpu:2.5.0")
  implementation("org.tensorflow:tensorflow-lite-support:0.1.0-rc1")
  implementation("com.google.code.gson:gson:2.8.9")
  implementation("com.google.mediapipe:tasks-vision:0.10.7")
}

java {
  withSourcesJar()
  withJavadocJar()
}

configure<JavaPluginConvention> {
  sourceCompatibility = JavaVersion.VERSION_17
  targetCompatibility = JavaVersion.VERSION_17
}

tasks.withType<KotlinCompile> {
  kotlinOptions.jvmTarget = JavaVersion.VERSION_17.toString()
}

It builds sucessfully, but when I try to import Mediapipe, it gives me an 'Unresolved Refrence'


Solution

  • So, to answer my own questions:

    • Yes, some Android libraries can be used for non-android purposes.
    • To go about using a library you would do as SedJ601 suggested and look here, although it doesn't seem to work for MediaPipe specifically
    • And finally, MediaPipe cannot be used for non-android purposes, and it didnt work because I wasn't following the methodology outlined in SedJ601's comment