Skip to content

Commit 0fed7d7

Browse files
committed
Depend on :weak-node-api
1 parent 4cbe8f2 commit 0fed7d7

File tree

7 files changed

+121
-5
lines changed

7 files changed

+121
-5
lines changed

packages/host/android/build.gradle

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,6 @@ android {
6161
sourceSets {
6262
main {
6363
manifest.srcFile "src/main/AndroidManifestNew.xml"
64-
// Include the weak-node-api native libraries directly
65-
jniLibs.srcDirs += [
66-
"../../weak-node-api/build/Debug/weak-node-api.android.node",
67-
"../../weak-node-api/build/Release/weak-node-api.android.node"
68-
]
6964
}
7065
}
7166
}
@@ -145,6 +140,7 @@ dependencies {
145140
implementation "com.facebook.react:react-android"
146141
implementation "com.facebook.react:hermes-engine"
147142
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
143+
implementation project(':weak-node-api')
148144
}
149145

150146
def commandLinePrefix = OperatingSystem.current().isWindows() ? ["cmd", "/c", "node"] : []

packages/weak-node-api/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@
99

1010
# Copied from node-api-headers by scripts/copy-node-api-headers.ts
1111
/include/
12+
13+
# Android build artifacts
14+
android/.cxx/
15+
android/build/
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// The only reason we're setting up Kotlin (or Java) is for React Native to pick this up during auto-linking
2+
// TODO: Create and issue and suggest a fix to allow libraries to propagate into the output of the `react-native config` without providing a class.
3+
4+
buildscript {
5+
ext.getExtOrDefault = {name ->
6+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['WeakNodeApi_' + name]
7+
}
8+
9+
repositories {
10+
google()
11+
mavenCentral()
12+
}
13+
14+
dependencies {
15+
classpath "com.android.tools.build:gradle:8.7.2"
16+
// noinspection DifferentKotlinGradleVersion
17+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${getExtOrDefault('kotlinVersion')}"
18+
}
19+
}
20+
21+
apply plugin: "com.android.library"
22+
apply plugin: "kotlin-android"
23+
24+
def getExtOrIntegerDefault(name) {
25+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["WeakNodeApi_" + name]).toInteger()
26+
}
27+
28+
def supportsNamespace() {
29+
def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')
30+
def major = parsed[0].toInteger()
31+
def minor = parsed[1].toInteger()
32+
33+
// Namespace support was added in 7.3.0
34+
return (major == 7 && minor >= 3) || major >= 8
35+
}
36+
37+
android {
38+
if (supportsNamespace()) {
39+
namespace "com.callstack.weak_node_api"
40+
41+
sourceSets {
42+
main {
43+
manifest.srcFile "src/main/AndroidManifestNew.xml"
44+
// Include the weak-node-api to enable a dynamic load
45+
jniLibs.srcDirs += [
46+
"../build/Debug/weak-node-api.android.node",
47+
"../build/Release/weak-node-api.android.node"
48+
]
49+
}
50+
}
51+
}
52+
53+
compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
54+
55+
defaultConfig {
56+
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
57+
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
58+
}
59+
60+
buildTypes {
61+
debug {
62+
packagingOptions {
63+
doNotStrip "**/libweak-node-api.so"
64+
}
65+
}
66+
}
67+
68+
}
69+
70+
repositories {
71+
mavenCentral()
72+
google()
73+
}
74+
75+
def kotlin_version = getExtOrDefault("kotlinVersion")
76+
77+
dependencies {
78+
implementation "com.facebook.react:react-android"
79+
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
80+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
WeakNodeApi_kotlinVersion=2.0.21
2+
WeakNodeApi_minSdkVersion=24
3+
WeakNodeApi_targetSdkVersion=34
4+
WeakNodeApi_compileSdkVersion=35
5+
WeakNodeApi_ndkVersion=27.1.12297006
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="com.callstack.weak_node_api">
3+
</manifest>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
2+
</manifest>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.callstack.weak_node_api
2+
3+
import com.facebook.hermes.reactexecutor.HermesExecutor
4+
import com.facebook.react.BaseReactPackage
5+
import com.facebook.react.bridge.NativeModule
6+
import com.facebook.react.bridge.ReactApplicationContext
7+
import com.facebook.react.module.model.ReactModuleInfo
8+
import com.facebook.react.module.model.ReactModuleInfoProvider
9+
import com.facebook.soloader.SoLoader
10+
11+
import java.util.HashMap
12+
13+
// The only purpose of this file and class is for React Native auto-linking to add the Android project to the app
14+
15+
class WeakNodeApiPackage : BaseReactPackage() {
16+
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
17+
return null
18+
}
19+
20+
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
21+
return ReactModuleInfoProvider {
22+
val moduleInfos: MutableMap<String, ReactModuleInfo> = HashMap()
23+
moduleInfos
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)