Skip to content

Commit

Permalink
Gradle/NNSApi: Import ML API including NNStreamer
Browse files Browse the repository at this point in the history
This patch imports Java implementations of ML API. This subproject
also imports native libraries such as NNStreamer, NNStreamer Edge,
and GStreamer to bring the ML API into the Android space

Signed-off-by: Wook Song <[email protected]>
  • Loading branch information
wooksong committed Apr 12, 2024
1 parent e3241b4 commit 1a91e4a
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 68 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
alias(libs.plugins.xyz.simple.git) apply false
alias(libs.plugins.androidApplication) apply false
alias(libs.plugins.androidLibrary) apply false
alias(libs.plugins.jetbrainsKotlinAndroid) apply false
}
2 changes: 1 addition & 1 deletion externals/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,4 @@ tasks {
tasks.named("build") {
dependsOn("copyFromTar")
dependsOn("checkoutGitSubmodules")
}
}
47 changes: 0 additions & 47 deletions nnstreamer-api/Android.mk

This file was deleted.

2 changes: 0 additions & 2 deletions nnstreamer-api/Application.mk

This file was deleted.

83 changes: 69 additions & 14 deletions nnstreamer-api/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,41 +1,96 @@
@file:Suppress("UnstableApiUsage")

import kotlin.io.path.Path
import kotlin.io.path.createDirectories

plugins {
alias(libs.plugins.androidLibrary)
id(libs.plugins.androidLibrary.get().pluginId)
}

val externalDirPath by rootProject.extra { rootDir.path + "/" + properties["dir.externals"] }

android {
val pathExternals = findProperty("externalDirPath").toString()
val relativePathExternals = projectDir.toPath().relativize(Path(pathExternals))
val externalDirPath by rootProject.extra {
project.rootDir.toPath().resolve(properties["dir.externals"].toString())
}
val relativePathExternals = projectDir.toPath().relativize(externalDirPath)

namespace = "org.nnsuite.nnstreamer"
compileSdk = libs.versions.android.compile.sdk.get().toInt()
ndkVersion = "25.2.9519653"

defaultConfig {
minSdk = 21
minSdk = 33 // The maximum API level supported by the NDK v25.2.9519653
externalNativeBuild {
ndkBuild {
abiFilters("armeabi-v7a", "arm64-v8a", "x86", "x86_64")
arguments(
"NDK_PROJECT_PATH=./",
"NDK_APPLICATION_MK=Application.mk",
arguments("NDK_PROJECT_PATH=./",
"NDK_APPLICATION_MK=$externalDirPath/ml-api/java/android/nnstreamer/src/main/jni/Application.mk",
"GSTREAMER_JAVA_SRC_DIR=src/main/java",
"GSTREAMER_ROOT_ANDROID=$relativePathExternals/gst-1.0-android-universal",
"NNSTREAMER_ROOT=$relativePathExternals/nnstreamer",
"ML_API_ROOT=$relativePathExternals/ml-api"
"GSTREAMER_ROOT_ANDROID=$externalDirPath/gst-1.0-android-universal",
"NNSTREAMER_ROOT=$externalDirPath/nnstreamer",
"NNSTREAMER_EDGE_ROOT=$externalDirPath/nnstreamer-edge",
"ML_API_ROOT=$externalDirPath/ml-api"
)
targets("nnstreamer_api")
targets("nnstreamer-native")
}
}
}
buildTypes {
debug {
enableUnitTestCoverage=true
}
release {
isMinifyEnabled = false
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
}
}
externalNativeBuild {
ndkBuild {
path=file("./Android.mk")
path=file("$relativePathExternals/ml-api/java/android/nnstreamer/src/main/jni/Android.mk")
}
}

productFlavors {
}

// To do not show build warning messages
packaging {
jniLibs.keepDebugSymbols.add("*/arm64-v8a/*_skel.so")
}

val genNnsSrc = tasks.register("genNnsSrc", Copy::class) {
val srcDirPath = externalDirPath.resolve("ml-api/java/android/nnstreamer/src/main/java/org/nnsuite/nnstreamer")
val outDirPath = project.projectDir.toPath().resolve("src/main/java/org/nnsuite/nnstreamer").apply {
createDirectories()
}

group = BasePlugin.BUILD_GROUP
description = "Generates NNStreamer Java sources"

from(srcDirPath) {
include("*.java")
}

filter { line: String ->
line.replace("@BUILD_ANDROID@", "")
}

into(outDirPath)

filteringCharset = "UTF-8"
outputs.upToDateWhen { false }
}

sourceSets {
getByName("main") {
java {
srcDirs(genNnsSrc)
}
}
}

tasks {
named("preBuild") {
dependsOn("genNnsSrc")
}
}
}
6 changes: 2 additions & 4 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
@file:Suppress("UnstableApiUsage")

include(":ml_inference_offloading")


pluginManagement {
repositories {
gradlePluginPortal()
Expand Down Expand Up @@ -30,4 +27,5 @@ dependencyResolutionManagement {
rootProject.name = "nnstreamer-android"

include(":externals")
include(":nnstreamer-api")
include(":nnstreamer-api")
include(":ml_inference_offloading")

0 comments on commit 1a91e4a

Please sign in to comment.