Skip to content

Commit

Permalink
fix: switch to kotlin
Browse files Browse the repository at this point in the history
  • Loading branch information
Johennes committed Nov 13, 2024
1 parent f569b8f commit 16d48f4
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 95 deletions.
19 changes: 17 additions & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
// Generated by uniffi-bindgen-react-native

buildscript {
// Buildscript is evaluated before everything else so we can't use getExtOrDefault
def kotlin_version = rootProject.ext.has("kotlinVersion") ? rootProject.ext.get("kotlinVersion") : project.properties["DummyLibForAndroid_kotlinVersion"]

repositories {
google()
mavenCentral()
}

dependencies {
classpath "com.android.tools.build:gradle:7.2.1"
// noinspection DifferentKotlinGradleVersion
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

def reactNativeArchitectures() {
def value = rootProject.getProperties().get("reactNativeArchitectures")
return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
}

def isNewArchitectureEnabled() {
return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
}

apply plugin: "com.android.library"
apply plugin: "kotlin-android"

if (isNewArchitectureEnabled()) {
apply plugin: "com.facebook.react"
Expand Down Expand Up @@ -63,6 +74,7 @@ android {
externalNativeBuild {
cmake {
arguments '-DANDROID_STL=c++_shared'
abiFilters (*reactNativeArchitectures())
}
}
ndk {
Expand Down Expand Up @@ -99,8 +111,8 @@ android {
main {
if (isNewArchitectureEnabled()) {
java.srcDirs += [
// This is needed to build Kotlin project with NewArch enabled
"${project.buildDir}/../generated/java"
"generated/java",
"generated/jni"
]
}
}
Expand All @@ -112,11 +124,14 @@ repositories {
google()
}

def kotlin_version = getExtOrDefault("kotlinVersion")

dependencies {
// For < 0.71, this will be from the local maven repo
// For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
//noinspection GradleDynamicVersion
implementation "com.facebook.react:react-native:+"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}

if (isNewArchitectureEnabled()) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Generated by uniffi-bindgen-react-native
package com.unomed.reactnativematrixsdk

import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.module.annotations.ReactModule
import com.facebook.react.turbomodule.core.interfaces.CallInvokerHolder

@ReactModule(name = ReactNativeMatrixSdkModule.NAME)
class ReactNativeMatrixSdkModule(reactContext: ReactApplicationContext) :
NativeReactNativeMatrixSdkSpec(reactContext) {

override fun getName(): String {
return NAME
}

// Two native methods implemented in cpp-adapter.cpp, and ultimately
// unomed-react-native-matrix-sdk.cpp

external fun nativeInstallRustCrate(runtimePointer: Long, callInvoker: CallInvokerHolder): Boolean
external fun nativeCleanupRustCrate(runtimePointer: Long): Boolean

override fun installRustCrate(): Boolean {
val context = this.reactApplicationContext
return nativeInstallRustCrate(
context.javaScriptContextHolder!!.get(),
context.jsCallInvokerHolder!!
)
}

override fun cleanupRustCrate(): Boolean {
return nativeCleanupRustCrate(
this.reactApplicationContext.javaScriptContextHolder!!.get()
)
}

companion object {
const val NAME = "ReactNativeMatrixSdk"

init {
System.loadLibrary("unomed-react-native-matrix-sdk")
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Generated by uniffi-bindgen-react-native
package com.unomed.reactnativematrixsdk

import com.facebook.react.TurboReactPackage
import com.facebook.react.bridge.NativeModule
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.module.model.ReactModuleInfo
import com.facebook.react.module.model.ReactModuleInfoProvider
import java.util.HashMap

class ReactNativeMatrixSdkPackage : TurboReactPackage() {
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
return if (name == ReactNativeMatrixSdkModule.NAME) {
ReactNativeMatrixSdkModule(reactContext)
} else {
null
}
}

override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
return ReactModuleInfoProvider {
val moduleInfos: MutableMap<String, ReactModuleInfo> = HashMap()
moduleInfos[ReactNativeMatrixSdkModule.NAME] = ReactModuleInfo(
ReactNativeMatrixSdkModule.NAME,
ReactNativeMatrixSdkModule.NAME,
false, // canOverrideExistingModule
false, // needsEagerInit
false, // isCxxModule
true // isTurboModule
)
moduleInfos
}
}
}
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@
"!**/.*"
],
"scripts": {
"ubrn:android": "yarn ubrn:android:build --and-generate && yarn ubrn:android:fix-build-gradle",
"ubrn:android:fix-build-gradle": "sed 's|generated/source/codegen/java|../generated/java|' android/build.gradle > android/build.gradle.new && mv android/build.gradle.new android/build.gradle",
"ubrn:android": "yarn ubrn:android:build --and-generate",
"ubrn:android:build": "ubrn build android --config ubrn.yaml",
"ubrn:android:build:release": "yarn ubrn:android:build --release",
"ubrn:ios": "yarn ubrn:ios:build --and-generate && (cd example/ios && pod install)",
Expand Down

0 comments on commit 16d48f4

Please sign in to comment.