KNI Stub (#746)
* Revert "Revert "Kotlin Native Jni Stub""
This reverts commit 46c89534fd.
* Work KNI build script
* Load Kni library as well
* Fix lib name
* Setup Kotlin Compiler
* Setup Kotlin Compiler
* Setup Kotlin Compiler
* Fix kotlin native compiler not available
* Fix
This commit is contained in:
1 parent
46c89534fd
commit
fd99bd2ed1
7 files changed
+114
-10
No files matched your search
@@ -179,6 +179,7 @@ dependencies {
|
||||
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4'
|
||||
implementation 'org.jetbrains.kotlinx:kotlinx-serialization-cbor:1.5.0-RC'
|
||||
implementation 'org.jsoup:jsoup:1.15.3'
|
||||
implementation project(":native")
|
||||
}
|
||||
|
||||
configurations.all {
|
||||
@@ -188,3 +189,11 @@ configurations.all {
|
||||
exclude group: 'org.jetbrains.kotlin', module: 'kotlin-stdlib-jdk7'
|
||||
exclude group: 'org.jetbrains.kotlin', module: 'kotlin-stdlib-jdk8'
|
||||
}
|
||||
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
maven { url "https://jcenter.bintray.com" }
|
||||
maven { url "https://jitpack.io" }
|
||||
maven { url "https://androidx.dev/storage/compose-compiler/repository/" }
|
||||
}
|
||||
@@ -23,6 +23,7 @@ import java.nio.ByteBuffer
|
||||
object Native {
|
||||
fun initialize() {
|
||||
System.loadLibrary("ehviewer")
|
||||
System.loadLibrary("ehviewer_kotlin_native")
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
|
||||
@@ -5,6 +5,14 @@ plugins {
|
||||
id 'com.google.devtools.ksp' version '1.8.0-1.0.9' apply false
|
||||
}
|
||||
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
maven { url "https://jcenter.bintray.com" }
|
||||
maven { url "https://jitpack.io" }
|
||||
maven { url "https://androidx.dev/storage/compose-compiler/repository/" }
|
||||
}
|
||||
|
||||
task clean(type: Delete) {
|
||||
delete rootProject.buildDir
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
/build
|
||||
@@ -0,0 +1,80 @@
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType
|
||||
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) {
|
||||
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"
|
||||
|
||||
sourceSets {
|
||||
getByName("debug").jniLibs.srcDirs("$jniLibDir/Debug")
|
||||
getByName("release").jniLibs.srcDirs("$jniLibDir/Release")
|
||||
}
|
||||
namespace = "moe.tarsin.ehviewer"
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
google()
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package moe.tarsin.ehviewer
|
||||
|
||||
import kotlinx.cinterop.CPointer
|
||||
import kotlinx.cinterop.invoke
|
||||
import kotlinx.cinterop.pointed
|
||||
import platform.android.JNIEnvVar
|
||||
import platform.android.jclass
|
||||
import platform.android.jobject
|
||||
|
||||
@CName("Java_com_hippo_Native_rewriteGif")
|
||||
fun rewriteGif(env: CPointer<JNIEnvVar>, thiz: jclass, buffer: jobject) {
|
||||
val ptr = env.pointed.pointed!!.GetDirectBufferAddress!!.invoke(env, buffer)
|
||||
}
|
||||
+2
-10
@@ -5,16 +5,8 @@ pluginManagement {
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
dependencyResolutionManagement {
|
||||
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
maven { url "https://jcenter.bintray.com" }
|
||||
maven { url "https://jitpack.io" }
|
||||
maven { url "https://androidx.dev/storage/compose-compiler/repository/" }
|
||||
}
|
||||
}
|
||||
|
||||
enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")
|
||||
rootProject.name = "EhViewer"
|
||||
include ':app'
|
||||
include ':native'
|
||||
Reference in new issue
Block a user