Remove KNI support
Not funny, reland it when we really need Kotlin Native
This commit is contained in:
1 parent
d30379251d
commit
9774bd858f
15 files changed
+1
-228
No files matched your search
@@ -195,7 +195,6 @@ dependencies {
|
|||||||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4")
|
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4")
|
||||||
implementation("org.jetbrains.kotlinx:kotlinx-serialization-cbor:1.5.0-RC")
|
implementation("org.jetbrains.kotlinx:kotlinx-serialization-cbor:1.5.0-RC")
|
||||||
implementation("org.jsoup:jsoup:1.15.3")
|
implementation("org.jsoup:jsoup:1.15.3")
|
||||||
implementation(project(":native"))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
configurations.all {
|
configurations.all {
|
||||||
|
|||||||
@@ -18,20 +18,12 @@
|
|||||||
package com.hippo
|
package com.hippo
|
||||||
|
|
||||||
import java.io.FileDescriptor
|
import java.io.FileDescriptor
|
||||||
import java.nio.ByteBuffer
|
|
||||||
|
|
||||||
object Native {
|
object Native {
|
||||||
fun initialize() {
|
fun initialize() {
|
||||||
System.loadLibrary("ehviewer")
|
System.loadLibrary("ehviewer")
|
||||||
System.loadLibrary("ehviewer_kotlin_native")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
external fun getFd(fd: FileDescriptor?): Int
|
external fun getFd(fd: FileDescriptor?): Int
|
||||||
|
|
||||||
@JvmStatic
|
|
||||||
external fun mapFd(fd: Int, capability: Long): ByteBuffer?
|
|
||||||
|
|
||||||
@JvmStatic
|
|
||||||
external fun unmapDirectByteBuffer(buffer: ByteBuffer)
|
|
||||||
}
|
}
|
||||||
@@ -21,5 +21,3 @@ org.gradle.caching=true
|
|||||||
android.useAndroidX=true
|
android.useAndroidX=true
|
||||||
android.enableAppCompileTimeRClass=true
|
android.enableAppCompileTimeRClass=true
|
||||||
android.experimental.enableNewResourceShrinker.preciseShrinking=true
|
android.experimental.enableNewResourceShrinker.preciseShrinking=true
|
||||||
kotlin.mpp.androidGradlePluginCompatibility.nowarn=true
|
|
||||||
kotlin.mpp.androidSourceSetLayoutVersion=2
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
/build
|
|
||||||
@@ -1,91 +0,0 @@
|
|||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
|
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType
|
|
||||||
import org.jetbrains.kotlin.gradle.tasks.KotlinNativeLink
|
|
||||||
import org.jetbrains.kotlin.konan.target.KonanTarget.*
|
|
||||||
|
|
||||||
plugins {
|
|
||||||
kotlin("multiplatform")
|
|
||||||
id("com.android.library")
|
|
||||||
}
|
|
||||||
|
|
||||||
val jniLibDir = File(project.buildDir, arrayOf("generated", "jniLibs").joinToString(File.separator))
|
|
||||||
|
|
||||||
val sharedLib_name_prefix = "ehviewer_kotlin_native"
|
|
||||||
|
|
||||||
kotlin {
|
|
||||||
android()
|
|
||||||
|
|
||||||
val nativeConfigure: KotlinNativeTarget.() -> Unit = {
|
|
||||||
binaries {
|
|
||||||
sharedLib(sharedLib_name_prefix) {
|
|
||||||
freeCompilerArgs = mutableListOf("-Xallocator=std")
|
|
||||||
|
|
||||||
linkTask.doLast {
|
|
||||||
copy {
|
|
||||||
from(outputFile)
|
|
||||||
|
|
||||||
val typeName = if (buildType == NativeBuildType.DEBUG) "Debug" else "Release"
|
|
||||||
val abiDirName = when(target.konanTarget) {
|
|
||||||
ANDROID_ARM32 -> "armeabi-v7a"
|
|
||||||
ANDROID_ARM64 -> "arm64-v8a"
|
|
||||||
ANDROID_X86 -> "x86"
|
|
||||||
ANDROID_X64 -> "x86_64"
|
|
||||||
else -> "unknown"
|
|
||||||
}
|
|
||||||
|
|
||||||
into(file("$jniLibDir/$typeName/$abiDirName"))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
afterEvaluate {
|
|
||||||
val preBuild by tasks.getting
|
|
||||||
preBuild.dependsOn(linkTask)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
androidNativeArm32(configure = nativeConfigure)
|
|
||||||
androidNativeArm64(configure = nativeConfigure)
|
|
||||||
androidNativeX86(configure = nativeConfigure)
|
|
||||||
androidNativeX64(configure = nativeConfigure)
|
|
||||||
|
|
||||||
sourceSets {
|
|
||||||
val androidNativeArm32Main by getting
|
|
||||||
val androidNativeArm64Main by getting
|
|
||||||
val androidNativeX86Main by getting
|
|
||||||
val androidNativeX64Main by getting
|
|
||||||
|
|
||||||
val nativeMain by creating {
|
|
||||||
androidNativeArm32Main.dependsOn(this)
|
|
||||||
androidNativeArm64Main.dependsOn(this)
|
|
||||||
androidNativeX86Main.dependsOn(this)
|
|
||||||
androidNativeX64Main.dependsOn(this)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
android {
|
|
||||||
compileSdk = 33
|
|
||||||
buildToolsVersion = "33.0.1"
|
|
||||||
|
|
||||||
defaultConfig {
|
|
||||||
minSdk = 28
|
|
||||||
}
|
|
||||||
|
|
||||||
sourceSets {
|
|
||||||
getByName("debug").jniLibs.srcDirs("$jniLibDir/Debug")
|
|
||||||
getByName("release").jniLibs.srcDirs("$jniLibDir/Release")
|
|
||||||
}
|
|
||||||
namespace = "moe.tarsin.ehviewer"
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.withType(KotlinNativeLink::class.java) {
|
|
||||||
outputs.cacheIf { false }
|
|
||||||
}
|
|
||||||
|
|
||||||
repositories {
|
|
||||||
mavenCentral()
|
|
||||||
google()
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
package moe.tarsin.ehviewer
|
|
||||||
|
|
||||||
import platform.posix.size_t
|
|
||||||
|
|
||||||
private val MAX_ALLOWED_CONVERT_VALUE = size_t.MAX_VALUE.toLong()
|
|
||||||
|
|
||||||
actual fun Long.tosize_t(): size_t {
|
|
||||||
check(this <= MAX_ALLOWED_CONVERT_VALUE)
|
|
||||||
return toUInt()
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package moe.tarsin.ehviewer
|
|
||||||
|
|
||||||
import platform.posix.size_t
|
|
||||||
|
|
||||||
actual fun Long.tosize_t(): size_t {
|
|
||||||
return toULong()
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package moe.tarsin.ehviewer
|
|
||||||
|
|
||||||
import platform.posix.size_t
|
|
||||||
|
|
||||||
actual fun Long.tosize_t(): size_t {
|
|
||||||
return toULong()
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
package moe.tarsin.ehviewer
|
|
||||||
|
|
||||||
import platform.posix.size_t
|
|
||||||
|
|
||||||
private val MAX_ALLOWED_CONVERT_VALUE = size_t.MAX_VALUE.toLong()
|
|
||||||
|
|
||||||
actual fun Long.tosize_t(): size_t {
|
|
||||||
check(this <= MAX_ALLOWED_CONVERT_VALUE)
|
|
||||||
return toUInt()
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
package moe.tarsin.ehviewer
|
|
||||||
|
|
||||||
import kotlinx.cinterop.COpaquePointer
|
|
||||||
import kotlinx.cinterop.CPointer
|
|
||||||
import kotlinx.cinterop.invoke
|
|
||||||
import kotlinx.cinterop.pointed
|
|
||||||
import platform.android.JNIEnvVar
|
|
||||||
import platform.android.JNINativeInterface
|
|
||||||
import platform.android.jobject
|
|
||||||
|
|
||||||
fun CPointer<JNIEnvVar>.getNativeInterface(): JNINativeInterface {
|
|
||||||
return pointed.pointed!!
|
|
||||||
}
|
|
||||||
|
|
||||||
fun CPointer<JNIEnvVar>.getDirectBufferAddress(buffer: jobject): COpaquePointer {
|
|
||||||
return getNativeInterface().GetDirectBufferAddress!!.invoke(this, buffer)!!
|
|
||||||
}
|
|
||||||
|
|
||||||
fun CPointer<JNIEnvVar>.getDirectBufferCapacity(buffer: jobject): Long {
|
|
||||||
return getNativeInterface().GetDirectBufferCapacity!!.invoke(this, buffer)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun CPointer<JNIEnvVar>.newDirectByteBuffer(addr: COpaquePointer, capability: Long): jobject {
|
|
||||||
return getNativeInterface().NewDirectByteBuffer!!.invoke(this, addr, capability)!!
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
package moe.tarsin.ehviewer
|
|
||||||
|
|
||||||
import platform.android.ANDROID_LOG_WARN
|
|
||||||
import platform.android.__android_log_print
|
|
||||||
|
|
||||||
private val KNI_NATIVE_TAG = "KNI"
|
|
||||||
|
|
||||||
fun Warn(message: String) {
|
|
||||||
__android_log_print(ANDROID_LOG_WARN.toInt(), KNI_NATIVE_TAG, "%s", message)
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
package moe.tarsin.ehviewer
|
|
||||||
|
|
||||||
import platform.posix.size_t
|
|
||||||
|
|
||||||
expect fun Long.tosize_t(): size_t
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
package moe.tarsin.ehviewer
|
|
||||||
|
|
||||||
import kotlinx.cinterop.CPointer
|
|
||||||
import platform.android.JNIEnvVar
|
|
||||||
import platform.android.jclass
|
|
||||||
import platform.android.jobject
|
|
||||||
|
|
||||||
@Suppress("UNUSED_PARAMETER")
|
|
||||||
@CName("Java_com_hippo_Native_rewriteGif")
|
|
||||||
fun rewriteGif(env: CPointer<JNIEnvVar>, clazz: jclass, buffer: jobject) {
|
|
||||||
val ptr = env.getDirectBufferAddress(buffer)
|
|
||||||
val size = env.getDirectBufferCapacity(buffer)
|
|
||||||
}
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
package moe.tarsin.ehviewer
|
|
||||||
|
|
||||||
import kotlinx.cinterop.CPointer
|
|
||||||
import kotlinx.cinterop.UnsafeNumber
|
|
||||||
import kotlinx.cinterop.interpretCPointer
|
|
||||||
import kotlinx.cinterop.nativeNullPtr
|
|
||||||
import kotlinx.cinterop.value
|
|
||||||
import platform.android.JNIEnvVar
|
|
||||||
import platform.android.jclass
|
|
||||||
import platform.android.jint
|
|
||||||
import platform.android.jlong
|
|
||||||
import platform.android.jobject
|
|
||||||
import platform.posix.MAP_PRIVATE
|
|
||||||
import platform.posix.PROT_READ
|
|
||||||
import platform.posix.PROT_WRITE
|
|
||||||
import platform.posix.errno
|
|
||||||
import platform.posix.mmap
|
|
||||||
import platform.posix.munmap
|
|
||||||
|
|
||||||
@OptIn(UnsafeNumber::class)
|
|
||||||
@Suppress("UNUSED_PARAMETER")
|
|
||||||
@CName("Java_com_hippo_Native_mapFd")
|
|
||||||
fun mapFd(env: CPointer<JNIEnvVar>, clazz: jclass, fd: jint, capability: jlong): jobject {
|
|
||||||
val result = mmap(null, capability.tosize_t(), PROT_READ or PROT_WRITE, MAP_PRIVATE, fd, 0)
|
|
||||||
result ?: Warn("mmap call with fd:${fd} capability:${capability} failed!, errno:${errno}")
|
|
||||||
return result?.let { env.newDirectByteBuffer(result, capability) } ?: interpretCPointer(nativeNullPtr)!!
|
|
||||||
}
|
|
||||||
|
|
||||||
@Suppress("UNUSED_PARAMETER")
|
|
||||||
@OptIn(UnsafeNumber::class)
|
|
||||||
@CName("Java_com_hippo_Native_unmapDirectByteBuffer")
|
|
||||||
fun unmapFd(env: CPointer<JNIEnvVar>, clazz: jclass, buffer: jobject) {
|
|
||||||
val addr = env.getDirectBufferAddress(buffer)
|
|
||||||
val size = env.getDirectBufferCapacity(buffer)
|
|
||||||
val result = munmap(addr, size.tosize_t())
|
|
||||||
if (result != 0) Warn("munmap call with addr:${addr} size:${size} failed!, errno:${errno}")
|
|
||||||
}
|
|
||||||
+1
-1
@@ -8,4 +8,4 @@ pluginManagement {
|
|||||||
|
|
||||||
enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")
|
enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")
|
||||||
rootProject.name = "EhViewer"
|
rootProject.name = "EhViewer"
|
||||||
include(":app", ":native")
|
include(":app")
|
||||||
Reference in new issue
Block a user