diff --git a/app/build.gradle b/app/build.gradle index af43c9bca..39b323978 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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/" } +} diff --git a/app/src/main/java/com/hippo/Native.kt b/app/src/main/java/com/hippo/Native.kt index ce192a270..ea8f70f7f 100644 --- a/app/src/main/java/com/hippo/Native.kt +++ b/app/src/main/java/com/hippo/Native.kt @@ -23,6 +23,7 @@ import java.nio.ByteBuffer object Native { fun initialize() { System.loadLibrary("ehviewer") + System.loadLibrary("ehviewer_kotlin_native") } @JvmStatic diff --git a/build.gradle b/build.gradle index e807cb63e..e82e64f17 100644 --- a/build.gradle +++ b/build.gradle @@ -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 } \ No newline at end of file diff --git a/native/.gitignore b/native/.gitignore new file mode 100644 index 000000000..42afabfd2 --- /dev/null +++ b/native/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/native/build.gradle.kts b/native/build.gradle.kts new file mode 100644 index 000000000..a654f0429 --- /dev/null +++ b/native/build.gradle.kts @@ -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() +} diff --git a/native/src/nativeMain/kotlin/moe/tarsin/ehviewer/RewriteGif.kt b/native/src/nativeMain/kotlin/moe/tarsin/ehviewer/RewriteGif.kt new file mode 100644 index 000000000..dfc76278a --- /dev/null +++ b/native/src/nativeMain/kotlin/moe/tarsin/ehviewer/RewriteGif.kt @@ -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, thiz: jclass, buffer: jobject) { + val ptr = env.pointed.pointed!!.GetDirectBufferAddress!!.invoke(env, buffer) +} diff --git a/settings.gradle b/settings.gradle index 170072ce5..c2e275d1d 100644 --- a/settings.gradle +++ b/settings.gradle @@ -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'