diff --git a/codegen/lib/templates/java/class.erb b/codegen/lib/templates/java/class.erb index fa491ff2560..a10c6008ecb 100644 --- a/codegen/lib/templates/java/class.erb +++ b/codegen/lib/templates/java/class.erb @@ -96,32 +96,10 @@ public final class <%= entity.name %> { throw new InvalidParameterException(); } - <%= entity.name %>PhantomReference.register(this, nativeHandle); + GenericPhantomReference.register(someObject, someHandle, handle -> { + nativeDelete(nativeHandle); + }); } <%- end -%> } -<% unless entity.methods.select{ |x| x.name == "Delete" }.empty? -%> -class <%= entity.name %>PhantomReference extends java.lang.ref.PhantomReference<<%= entity.name %>> { - private static java.util.Set<<%= entity.name %>PhantomReference> references = new HashSet<<%= entity.name %>PhantomReference>(); - private static java.lang.ref.ReferenceQueue<<%= entity.name %>> queue = new java.lang.ref.ReferenceQueue<<%= entity.name %>>(); - private long nativeHandle; - - private <%= entity.name %>PhantomReference(<%= entity.name %> referent, long nativeHandle) { - super(referent, queue); - this.nativeHandle = nativeHandle; - } - - static void register(<%= entity.name %> referent, long nativeHandle) { - references.add(new <%= entity.name %>PhantomReference(referent, nativeHandle)); - } - - public static void doDeletes() { - <%= entity.name %>PhantomReference ref = (<%= entity.name %>PhantomReference) queue.poll(); - for (; ref != null; ref = (<%= entity.name %>PhantomReference) queue.poll()) { - <%= entity.name %>.nativeDelete(ref.nativeHandle); - references.remove(ref); - } - } -} -<% end -%> diff --git a/kotlin/gradle/libs.versions.toml b/kotlin/gradle/libs.versions.toml index e6e4289dd86..3d233c16d10 100644 --- a/kotlin/gradle/libs.versions.toml +++ b/kotlin/gradle/libs.versions.toml @@ -9,6 +9,10 @@ kotlin = "1.8.21" agp = "8.0.0" wire = "4.5.6" +androidx-test-runner = "1.5.2" + [libraries] wire-runtime = { module = "com.squareup.wire:wire-runtime", version.ref = "wire" } wire-compiler = { module = "com.squareup.wire:wire-compiler", version.ref = "wire" } + +androidx-test-runner = { module = "androidx.test:runner", version.ref = "androidx-test-runner" } diff --git a/kotlin/wallet-core-kotlin/build.gradle.kts b/kotlin/wallet-core-kotlin/build.gradle.kts index 63d879ca7c3..22782599f26 100644 --- a/kotlin/wallet-core-kotlin/build.gradle.kts +++ b/kotlin/wallet-core-kotlin/build.gradle.kts @@ -58,7 +58,7 @@ kotlin { } } - getByName("commonTest") { + val commonTest by getting { dependencies { implementation(kotlin("test")) } @@ -85,6 +85,13 @@ kotlin { implementation(npm(name = "webpack", version = "5.89.0")) } } + + getByName("androidInstrumentedTest") { + dependsOn(commonTest) + dependencies { + implementation(libs.androidx.test.runner) + } + } } nativeTargets.forEach { nativeTarget -> @@ -119,6 +126,8 @@ android { arguments += listOf("-DCMAKE_BUILD_TYPE=Release", "-DKOTLIN=True", "-DTW_UNITY_BUILD=ON") } } + + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" } buildFeatures { @@ -132,12 +141,6 @@ android { viewBinding = false } - androidComponents { - beforeVariants { - it.enable = it.name == "release" - } - } - externalNativeBuild { cmake { version = libs.versions.android.cmake.get() diff --git a/kotlin/wallet-core-kotlin/src/androidInstrumentedTest/kotlin/com/trustwallet/core/LibLoader.kt b/kotlin/wallet-core-kotlin/src/androidInstrumentedTest/kotlin/com/trustwallet/core/LibLoader.kt new file mode 100644 index 00000000000..e37b1e33897 --- /dev/null +++ b/kotlin/wallet-core-kotlin/src/androidInstrumentedTest/kotlin/com/trustwallet/core/LibLoader.kt @@ -0,0 +1,7 @@ +package com.trustwallet.core + +actual object LibLoader { + actual fun loadLibrary() { + System.loadLibrary("TrustWalletCore") + } +} diff --git a/kotlin/wallet-core-kotlin/src/androidUnitTest/kotlin/com/trustwallet/core/LibLoader.kt b/kotlin/wallet-core-kotlin/src/androidUnitTest/kotlin/com/trustwallet/core/LibLoader.kt index 1d4f9311712..e37b1e33897 100644 --- a/kotlin/wallet-core-kotlin/src/androidUnitTest/kotlin/com/trustwallet/core/LibLoader.kt +++ b/kotlin/wallet-core-kotlin/src/androidUnitTest/kotlin/com/trustwallet/core/LibLoader.kt @@ -2,6 +2,6 @@ package com.trustwallet.core actual object LibLoader { actual fun loadLibrary() { - throw NotImplementedError() + System.loadLibrary("TrustWalletCore") } } diff --git a/kotlin/wallet-core-kotlin/src/jvmMain/kotlin/com/trustwallet/core/WalletCoreLibLoader.kt b/kotlin/wallet-core-kotlin/src/commonAndroidJvmMain/kotlin/com/trustwallet/core/WalletCoreLibLoader.kt similarity index 100% rename from kotlin/wallet-core-kotlin/src/jvmMain/kotlin/com/trustwallet/core/WalletCoreLibLoader.kt rename to kotlin/wallet-core-kotlin/src/commonAndroidJvmMain/kotlin/com/trustwallet/core/WalletCoreLibLoader.kt