Skip to content

Commit 2dc6a6e

Browse files
committed
feat(android): add nitro modules
1 parent 9969803 commit 2dc6a6e

File tree

5 files changed

+111
-2
lines changed

5 files changed

+111
-2
lines changed

android/CMakeLists.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
project(ReactNativeRive)
2+
cmake_minimum_required(VERSION 3.9.0)
3+
4+
set(PACKAGE_NAME ReactNativeRive)
5+
set(CMAKE_VERBOSE_MAKEFILE ON)
6+
set(CMAKE_CXX_STANDARD 20)
7+
8+
# Define C++ library and add all sources
9+
add_library(${PACKAGE_NAME} SHARED src/main/cpp/cpp-adapter.cpp)
10+
11+
# Add Nitrogen specs :)
12+
include(${CMAKE_SOURCE_DIR}/../nitrogen/generated/android/ReactNativeRive+autolinking.cmake)
13+
14+
# Set up local includes
15+
include_directories("src/main/cpp" "../cpp")
16+
17+
find_library(LOG_LIB log)
18+
19+
# Link all libraries together
20+
target_link_libraries(
21+
${PACKAGE_NAME}
22+
${LOG_LIB}
23+
android # <-- Android core
24+
)

android/build.gradle

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,16 @@ buildscript {
1515
}
1616
}
1717

18+
def reactNativeArchitectures() {
19+
def value = rootProject.getProperties().get("reactNativeArchitectures")
20+
return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
21+
}
22+
1823

1924
apply plugin: "com.android.library"
2025
apply plugin: "kotlin-android"
26+
apply from: '../nitrogen/generated/android/ReactNativeRive+autolinking.gradle'
27+
2128

2229
apply plugin: "com.facebook.react"
2330

@@ -33,12 +40,58 @@ android {
3340
defaultConfig {
3441
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
3542
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
43+
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", "true"
44+
45+
externalNativeBuild {
46+
cmake {
47+
cppFlags "-frtti -fexceptions -Wall -Wextra -fstack-protector-all"
48+
arguments "-DANDROID_STL=c++_shared"
49+
abiFilters (*reactNativeArchitectures())
50+
51+
buildTypes {
52+
debug {
53+
cppFlags "-O1 -g"
54+
}
55+
release {
56+
cppFlags "-O2"
57+
}
58+
}
59+
}
60+
}
61+
}
62+
63+
externalNativeBuild {
64+
cmake {
65+
path "CMakeLists.txt"
66+
}
3667
}
3768

3869
buildFeatures {
3970
buildConfig true
71+
prefab true
4072
}
4173

74+
packagingOptions {
75+
excludes = [
76+
"META-INF",
77+
"META-INF/**",
78+
"**/libc++_shared.so",
79+
"**/libfbjni.so",
80+
"**/libjsi.so",
81+
"**/libfolly_json.so",
82+
"**/libfolly_runtime.so",
83+
"**/libglog.so",
84+
"**/libhermes.so",
85+
"**/libhermes-executor-debug.so",
86+
"**/libhermes_executor.so",
87+
"**/libreactnative.so",
88+
"**/libreactnativejni.so",
89+
"**/libturbomodulejsijni.so",
90+
"**/libreact_nativemodule_core.so",
91+
"**/libjscexecutor.so"
92+
]
93+
}
94+
4295
buildTypes {
4396
release {
4497
minifyEnabled false
@@ -58,7 +111,8 @@ android {
58111
main {
59112
java.srcDirs += [
60113
"generated/java",
61-
"generated/jni"
114+
"generated/jni",
115+
"${project.buildDir}/generated/source/codegen/java"
62116
]
63117
}
64118
}
@@ -74,6 +128,7 @@ def kotlin_version = getExtOrDefault("kotlinVersion")
74128
dependencies {
75129
implementation "com.facebook.react:react-android"
76130
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
131+
implementation project(":react-native-nitro-modules")
77132
}
78133

79134
react {
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include <jni.h>
2+
#include "ReactNativeRiveOnLoad.hpp"
3+
4+
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void*) {
5+
return margelo::nitro::reactnativerive::initialize(vm);
6+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.margelo.nitro.reactnativerive
2+
3+
class HybridRiveFileFactory : HybridRiveFileFactorySpec() {
4+
override fun add(a: Double, b: Double): Double {
5+
return a + b
6+
}
7+
}
Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,36 @@
11
package com.rive
22

3+
import com.facebook.react.BaseReactPackage
34
import com.facebook.react.ReactPackage
45
import com.facebook.react.bridge.NativeModule
56
import com.facebook.react.bridge.ReactApplicationContext
7+
import com.facebook.react.module.model.ReactModuleInfoProvider
68
import com.facebook.react.uimanager.ViewManager
9+
import com.margelo.nitro.reactnativerive.ReactNativeRiveOnLoad
710
import java.util.ArrayList
811

9-
class RiveViewPackage : ReactPackage {
12+
class RiveViewPackage : BaseReactPackage() {
1013
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
1114
val viewManagers: MutableList<ViewManager<*, *>> = ArrayList()
1215
viewManagers.add(RiveViewManager())
1316
return viewManagers
1417
}
1518

19+
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
20+
return null
21+
}
22+
23+
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
24+
return ReactModuleInfoProvider { HashMap() }
25+
}
26+
1627
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
1728
return emptyList()
1829
}
30+
31+
companion object {
32+
init {
33+
ReactNativeRiveOnLoad.initializeNative()
34+
}
35+
}
1936
}

0 commit comments

Comments
 (0)