Skip to content

Commit

Permalink
Remove compose because it was searching for a Composer on arm32, whic…
Browse files Browse the repository at this point in the history
…h is not supported
  • Loading branch information
LandryNorris committed Jan 19, 2023
1 parent aa121a7 commit dc4e8c9
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 180 deletions.
5 changes: 1 addition & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
buildscript {
val composeVersion = "1.2.2"
repositories {
gradlePluginPortal()
google()
mavenCentral()
}
dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.20")
classpath("com.android.tools.build:gradle:7.3.1")
classpath("org.jetbrains.compose:compose-gradle-plugin:$composeVersion")
classpath("com.android.tools.build:gradle:7.4.0")
}
}

allprojects {
repositories {
google()
mavenCentral()
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
}
}

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Fri Jun 24 18:00:42 CDT 2022
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
101 changes: 42 additions & 59 deletions sample/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,61 +1,14 @@
import org.jetbrains.compose.compose

plugins {
id("com.android.application")
id("org.jetbrains.compose")
kotlin("multiplatform")
}

tasks {
val prepareAndroidNdkSo by creating {
dependsOn(build)
val debugArm32SoFolder = File(buildDir, "bin/androidNativeArm32/debugShared")
val jniArm32Folder = File(projectDir, "src/androidMain/jniLibs/armeabi-v7a")
val debugArm64SoFolder = File(buildDir, "bin/androidNativeArm64/debugShared")
val jniArm64Folder = File(projectDir, "src/androidMain/jniLibs/arm64-v8a")

val debugX86SoFolder = File(buildDir, "bin/androidNativeX86/debugShared")
val jniX86Folder = File(projectDir, "src/androidMain/jniLibs/x86")
val debugX64SoFolder = File(buildDir, "bin/androidNativeX64/debugShared")
val jniX64Folder = File(projectDir, "src/androidMain/jniLibs/x86_64")

doLast {
copy {
from(debugArm32SoFolder)
into(jniArm32Folder)
include("*.so")
}
copy {
from(debugArm64SoFolder)
into(jniArm64Folder)
include("*.so")
}
copy {
from(debugX86SoFolder)
into(jniX86Folder)
include("*.so")
}
copy {
from(debugX64SoFolder)
into(jniX64Folder)
include("*.so")
}
}
}
}

kotlin {
android()

val androidNdkTargets = listOf(androidNativeArm64(), androidNativeArm32(),
androidNativeX64(), androidNativeX86())

androidNdkTargets.forEach {
it.binaries {
sharedLib()
}
}

sourceSets {
val commonMain by getting
val ndkMain by creating {
Expand All @@ -78,18 +31,9 @@ kotlin {
val androidNativeX86Main by getting {
dependsOn(ndkMain)
}

val androidMain by getting {
dependencies {
implementation("com.google.android.material:material:1.7.0")
implementation("androidx.appcompat:appcompat:1.6.0")
implementation("androidx.activity:activity-compose:1.6.1")
implementation(compose.runtime)
implementation(compose.foundation)
implementation(compose.material)
implementation(compose.materialIconsExtended)
implementation(compose.preview)
implementation(compose.uiTooling)
}
}

Expand All @@ -104,15 +48,15 @@ kotlin {
}

android {
compileSdk = 32
compileSdk = 33
sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
defaultConfig {
minSdk = 21
targetSdk = 32
targetSdk = 33
}

buildFeatures {
compose = true
compose = false
}
}

Expand All @@ -121,3 +65,42 @@ repositories {
google()
mavenLocal()
}


tasks {
val prepareAndroidNdkSo by creating {
dependsOn(build)
val debugArm32SoFolder = File(buildDir, "bin/androidNativeArm32/debugShared")
val jniArm32Folder = File(projectDir, "src/androidMain/jniLibs/armeabi-v7a")
val debugArm64SoFolder = File(buildDir, "bin/androidNativeArm64/debugShared")
val jniArm64Folder = File(projectDir, "src/androidMain/jniLibs/arm64-v8a")

val debugX86SoFolder = File(buildDir, "bin/androidNativeX86/debugShared")
val jniX86Folder = File(projectDir, "src/androidMain/jniLibs/x86")
val debugX64SoFolder = File(buildDir, "bin/androidNativeX64/debugShared")
val jniX64Folder = File(projectDir, "src/androidMain/jniLibs/x86_64")

doLast {
copy {
from(debugArm32SoFolder)
into(jniArm32Folder)
include("*.so")
}
copy {
from(debugArm64SoFolder)
into(jniArm64Folder)
include("*.so")
}
copy {
from(debugX86SoFolder)
into(jniX86Folder)
include("*.so")
}
copy {
from(debugX64SoFolder)
into(jniX64Folder)
include("*.so")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ object JniBridge {
external fun handleShared(sharedClass: SharedClass): String
external fun doubleAll(array: DoubleArray): DoubleArray
external fun callJavaFunction(value: Double)
external fun createDataClass(s: String, i: Int, d: Double, doubles: DoubleArray)
external fun createDataClass(s: String, i: Int, d: Double, doubles: DoubleArray): Any
external fun buttonClicked(ptr: Long)
external fun getText(ptr: Long): String
external fun createRepository(): Long
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@ import android.os.Bundle
import android.widget.Button
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.tooling.preview.Preview
import io.github.landrynorris.jni.sample.DataClass
import io.github.landrynorris.jni.sample.DataHolder
import io.github.landrynorris.jni.sample.SharedClass
import io.github.landrynorris.sample.ui.theme.JniUtilsTheme

class MainActivity: AppCompatActivity() {
private val buttonRepository = ButtonRepository()
Expand Down Expand Up @@ -56,20 +52,7 @@ class MainActivity: AppCompatActivity() {
if(dataClass.s != s) error("String wasn't set correctly")
if(dataClass.i != i) error("Int wasn't set correctly")
if(dataClass.d != d) error("Double wasn't set correctly")
if(dataClass.doubles != doubles) error("Double array wasn't set correctly")
if(!dataClass.doubles.contentEquals(doubles)) error("Double array wasn't set correctly")
}
}
}

@Composable
fun Greeting(name: String) {
Text(text = "Hello $name!")
}

@Preview(showBackground = true)
@Composable
fun DefaultPreview() {
JniUtilsTheme {
Greeting("Android")
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ package io.github.landrynorris.jni.sample

import io.github.landrynorris.jniutils.*
import kotlinx.cinterop.*
import kotlinx.cinterop.nativeHeap.alloc
import platform.android.*
import kotlin.math.sign
import kotlin.reflect.KClass

fun methodWithParameters(env: CPointer<JNIEnvVar>, thiz: jobject, intValue: Int) {
println("Got int from JVM. Value is $intValue")
Expand All @@ -25,17 +22,16 @@ fun callJavaFunction(env: CPointer<JNIEnvVar>, thiz: jobject, value: Double) {
}
}

fun createDataClass(env: CPointer<JNIEnvVar>, thiz: jobject, s: String, i: Int,
fun createDataClass(env: CPointer<JNIEnvVar>, thiz: jobject, s: jstring, i: Int,
d: Double, doubles: jdoubleArray): jobject? {
// We can use ::class because the class is shared between JNI and JVM source set.
// This is helpful for reducing mistakes
val clazz = env.findClass(DataClass::class.qualifiedName?.signature() ?: "")
?: error("Can't find class")
val constructorSignature = Signature(listOf(String, Int, Double, DoubleArray), Void)
val constructorId = env.getMethodId(clazz, "<init>", constructorSignature.toString())
val js = s.toJString(env)!!
return memScoped {
env.newObject(clazz, constructorId!!, js.jvalue(this),
env.newObject(clazz, constructorId!!, s.jvalue(this),
i.jvalue(this), d.jvalue(this), doubles.jvalue(this))
}
}
Expand Down

0 comments on commit dc4e8c9

Please sign in to comment.