react-native-ble-nitro 1.1.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +87 -20
- package/android/CMakeLists.txt +32 -0
- package/android/build.gradle +140 -0
- package/android/fix-prefab.gradle +51 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/cpp/cpp-adapter.cpp +6 -0
- package/android/src/main/java/com/margelo/nitro/co/zyke/ble/BleNitroBleManager.kt +899 -0
- package/android/src/main/java/com/margelo/nitro/co/zyke/ble/BleNitroPackage.kt +38 -0
- package/ios/BleNitroBleManager.swift +56 -17
- package/ios/BlePeripheralDelegate.swift +36 -8
- package/lib/commonjs/index.d.ts +22 -9
- package/lib/commonjs/index.d.ts.map +1 -1
- package/lib/commonjs/index.js +63 -12
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/specs/NativeBleNitro.nitro.d.ts +14 -5
- package/lib/commonjs/specs/NativeBleNitro.nitro.d.ts.map +1 -1
- package/lib/commonjs/specs/NativeBleNitro.nitro.js +8 -1
- package/lib/commonjs/specs/NativeBleNitro.nitro.js.map +1 -1
- package/lib/index.d.ts +22 -9
- package/lib/index.js +61 -10
- package/lib/specs/NativeBleNitro.nitro.d.ts +14 -5
- package/lib/specs/NativeBleNitro.nitro.js +7 -0
- package/nitrogen/generated/android/BleNitroOnLoad.cpp +6 -6
- package/nitrogen/generated/android/c++/JAndroidScanMode.hpp +65 -0
- package/nitrogen/generated/android/c++/JBLEDevice.hpp +3 -0
- package/nitrogen/generated/android/c++/JFunc_void_bool_std__shared_ptr_ArrayBuffer__std__string.hpp +78 -0
- package/nitrogen/generated/android/c++/JFunc_void_std__optional_BLEDevice__std__optional_std__string_.hpp +86 -0
- package/nitrogen/generated/android/c++/JFunc_void_std__string_std__shared_ptr_ArrayBuffer_.hpp +78 -0
- package/nitrogen/generated/android/c++/JHybridNativeBleNitroSpec.cpp +29 -20
- package/nitrogen/generated/android/c++/JHybridNativeBleNitroSpec.hpp +5 -4
- package/nitrogen/generated/android/c++/JManufacturerData.hpp +3 -0
- package/nitrogen/generated/android/c++/JManufacturerDataEntry.hpp +7 -15
- package/nitrogen/generated/android/c++/JScanFilter.hpp +8 -2
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/co/zyke/ble/AndroidScanMode.kt +23 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/co/zyke/ble/{Func_void_bool_std__vector_double__std__string.kt → Func_void_bool_std__shared_ptr_ArrayBuffer__std__string.kt} +12 -12
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/co/zyke/ble/{Func_void_BLEDevice.kt → Func_void_std__optional_BLEDevice__std__optional_std__string_.kt} +14 -14
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/co/zyke/ble/{Func_void_std__string_std__vector_double_.kt → Func_void_std__string_std__shared_ptr_ArrayBuffer_.kt} +12 -12
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/co/zyke/ble/HybridNativeBleNitroSpec.kt +12 -8
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/co/zyke/ble/ManufacturerDataEntry.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/co/zyke/ble/ScanFilter.kt +4 -1
- package/nitrogen/generated/ios/BleNitro-Swift-Cxx-Bridge.cpp +15 -15
- package/nitrogen/generated/ios/BleNitro-Swift-Cxx-Bridge.hpp +69 -56
- package/nitrogen/generated/ios/BleNitro-Swift-Cxx-Umbrella.hpp +6 -0
- package/nitrogen/generated/ios/c++/HybridNativeBleNitroSpecSwift.hpp +23 -6
- package/nitrogen/generated/ios/swift/AndroidScanMode.swift +48 -0
- package/nitrogen/generated/ios/swift/{Func_void_bool_std__vector_double__std__string.swift → Func_void_bool_std__shared_ptr_ArrayBuffer__std__string.swift} +11 -11
- package/nitrogen/generated/ios/swift/Func_void_std__optional_BLEDevice__std__optional_std__string_.swift +59 -0
- package/nitrogen/generated/ios/swift/{Func_void_std__string_std__vector_double_.swift → Func_void_std__string_std__shared_ptr_ArrayBuffer_.swift} +11 -11
- package/nitrogen/generated/ios/swift/HybridNativeBleNitroSpec.swift +5 -4
- package/nitrogen/generated/ios/swift/HybridNativeBleNitroSpec_cxx.swift +41 -29
- package/nitrogen/generated/ios/swift/ManufacturerDataEntry.swift +5 -17
- package/nitrogen/generated/ios/swift/ScanFilter.swift +13 -2
- package/nitrogen/generated/shared/c++/AndroidScanMode.hpp +64 -0
- package/nitrogen/generated/shared/c++/HybridNativeBleNitroSpec.cpp +1 -0
- package/nitrogen/generated/shared/c++/HybridNativeBleNitroSpec.hpp +10 -6
- package/nitrogen/generated/shared/c++/ManufacturerDataEntry.hpp +8 -7
- package/nitrogen/generated/shared/c++/ScanFilter.hpp +9 -3
- package/package.json +1 -1
- package/plugin/build/index.d.ts +2 -0
- package/plugin/build/index.js +2 -0
- package/plugin/build/withBleNitro.d.ts +5 -1
- package/plugin/build/withBleNitro.js +18 -7
- package/react-native.config.js +10 -2
- package/src/__tests__/index.test.ts +48 -13
- package/src/index.ts +74 -16
- package/src/specs/NativeBleNitro.nitro.ts +17 -5
- package/nitrogen/generated/android/c++/JFunc_void_BLEDevice.hpp +0 -82
- package/nitrogen/generated/android/c++/JFunc_void_bool_std__vector_double__std__string.hpp +0 -86
- package/nitrogen/generated/android/c++/JFunc_void_std__string_std__vector_double_.hpp +0 -86
- package/nitrogen/generated/ios/swift/Func_void_BLEDevice.swift +0 -47
package/README.md
CHANGED
|
@@ -5,13 +5,13 @@
|
|
|
5
5
|
|
|
6
6
|
A high-performance React Native BLE library built on [Nitro Modules](https://nitro.margelo.com/).
|
|
7
7
|
|
|
8
|
-
Originally developed for [Zyke Band](https://zykeband.com) - a fitness and health tracker created by a small team.
|
|
8
|
+
Originally developed for [Zyke Band](https://zykeband.com?utm_source=github&utm_medium=readme&utm_campaign=opensource) - a fitness and health tracker created by a small team.
|
|
9
9
|
|
|
10
10
|
## ✨ Features
|
|
11
11
|
|
|
12
12
|
- 🚀 **High Performance**: Built on Nitro Modules with JSI for zero-overhead native communication
|
|
13
13
|
- 📱 **iOS Support**: Complete iOS implementation with Swift and Core Bluetooth
|
|
14
|
-
- 🤖 **Android Support**:
|
|
14
|
+
- 🤖 **Android Support**: Complete Android implementation with Kotlin and Android BLE APIs
|
|
15
15
|
- 🎯 **Type-Safe**: Full TypeScript support with comprehensive type definitions
|
|
16
16
|
- 🔧 **Expo Ready**: Built-in Expo config plugin for easy setup
|
|
17
17
|
- 🏗️ **New Architecture**: Full support for React Native's new architecture
|
|
@@ -66,12 +66,10 @@ npx pod-install # iOS only
|
|
|
66
66
|
|
|
67
67
|
## 📖 Usage
|
|
68
68
|
|
|
69
|
-
> **📱 Platform Support**: Currently iOS only. Android implementation is in development.
|
|
70
|
-
|
|
71
69
|
### Basic Setup
|
|
72
70
|
|
|
73
71
|
```typescript
|
|
74
|
-
import { BleNitro, BLEState, type BLEDevice } from 'react-native-ble-nitro';
|
|
72
|
+
import { BleNitro, BLEState, AndroidScanMode, type BLEDevice } from 'react-native-ble-nitro';
|
|
75
73
|
|
|
76
74
|
// Get the singleton instance
|
|
77
75
|
const ble = BleNitro.instance();
|
|
@@ -111,9 +109,13 @@ await ble.openSettings();
|
|
|
111
109
|
ble.startScan({
|
|
112
110
|
serviceUUIDs: ['180d'], // Optional: filter by service UUIDs
|
|
113
111
|
rssiThreshold: -80, // Optional: minimum signal strength
|
|
114
|
-
allowDuplicates: false
|
|
112
|
+
allowDuplicates: false, // Optional: allow duplicate discoveries
|
|
113
|
+
androidScanMode: AndroidScanMode.Balanced // Optional: Android scan mode
|
|
115
114
|
}, (device) => {
|
|
116
|
-
console.log('
|
|
115
|
+
console.log('Discovered device:', device);
|
|
116
|
+
}, (error) => {
|
|
117
|
+
// only called on Android
|
|
118
|
+
console.error('Scan error:', error);
|
|
117
119
|
});
|
|
118
120
|
|
|
119
121
|
// Stop scanning
|
|
@@ -148,6 +150,15 @@ await ble.disconnect(deviceId);
|
|
|
148
150
|
|
|
149
151
|
// Check connection status
|
|
150
152
|
const isConnected = ble.isConnected(deviceId);
|
|
153
|
+
|
|
154
|
+
// MTU negotiation (Android only, as iOS manages MTU automatically)
|
|
155
|
+
// iOS returns current MTU size
|
|
156
|
+
const mtu = await ble.requestMTU(deviceId, 256); // Request MTU size
|
|
157
|
+
|
|
158
|
+
// MTU negotiation (Android only)
|
|
159
|
+
// iOS manages MTU automatically, this method returns current MTU size
|
|
160
|
+
const newMTU = ble.requestMTU(deviceId, 247);
|
|
161
|
+
console.log('MTU set to:', newMTU);
|
|
151
162
|
```
|
|
152
163
|
|
|
153
164
|
#### 🔧 Service Discovery
|
|
@@ -177,11 +188,12 @@ const characteristics2 = ble.getCharacteristics(deviceId, '0000180d-0000-1000-80
|
|
|
177
188
|
```typescript
|
|
178
189
|
// Read a characteristic value
|
|
179
190
|
const data = await ble.readCharacteristic(deviceId, serviceUUID, characteristicUUID);
|
|
180
|
-
// Returns:
|
|
191
|
+
// Returns: ArrayBuffer - binary data
|
|
181
192
|
|
|
182
193
|
// Example: Reading battery level
|
|
183
194
|
const batteryData = await ble.readCharacteristic(deviceId, '180f', '2a19');
|
|
184
|
-
const
|
|
195
|
+
const batteryArray = new Uint8Array(batteryData);
|
|
196
|
+
const batteryLevel = batteryArray[0]; // First byte is battery percentage
|
|
185
197
|
console.log('Battery level:', batteryLevel + '%');
|
|
186
198
|
```
|
|
187
199
|
|
|
@@ -189,11 +201,12 @@ console.log('Battery level:', batteryLevel + '%');
|
|
|
189
201
|
|
|
190
202
|
```typescript
|
|
191
203
|
// Write to a characteristic with response
|
|
204
|
+
const data = new Uint8Array([0x01, 0x02, 0x03]);
|
|
192
205
|
await ble.writeCharacteristic(
|
|
193
206
|
deviceId,
|
|
194
207
|
serviceUUID,
|
|
195
208
|
characteristicUUID,
|
|
196
|
-
|
|
209
|
+
data.buffer, // Data as ArrayBuffer
|
|
197
210
|
true // withResponse = true (default)
|
|
198
211
|
);
|
|
199
212
|
|
|
@@ -202,7 +215,7 @@ await ble.writeCharacteristic(
|
|
|
202
215
|
deviceId,
|
|
203
216
|
serviceUUID,
|
|
204
217
|
characteristicUUID,
|
|
205
|
-
|
|
218
|
+
data.buffer,
|
|
206
219
|
false // withResponse = false
|
|
207
220
|
);
|
|
208
221
|
```
|
|
@@ -245,7 +258,8 @@ const subscription = ble.subscribeToCharacteristic(
|
|
|
245
258
|
HEART_RATE_SERVICE,
|
|
246
259
|
HEART_RATE_MEASUREMENT,
|
|
247
260
|
(_, data) => {
|
|
248
|
-
const
|
|
261
|
+
const dataArray = new Uint8Array(data);
|
|
262
|
+
const heartRate = dataArray[1]; // Second byte contains BPM
|
|
249
263
|
console.log('Heart rate:', heartRate, 'BPM');
|
|
250
264
|
}
|
|
251
265
|
);
|
|
@@ -265,7 +279,8 @@ const batteryData = await ble.readCharacteristic(
|
|
|
265
279
|
BATTERY_SERVICE,
|
|
266
280
|
BATTERY_LEVEL_CHARACTERISTIC
|
|
267
281
|
);
|
|
268
|
-
const
|
|
282
|
+
const batteryArray = new Uint8Array(batteryData);
|
|
283
|
+
const batteryPercentage = batteryArray[0];
|
|
269
284
|
console.log('Battery:', batteryPercentage + '%');
|
|
270
285
|
```
|
|
271
286
|
|
|
@@ -276,12 +291,12 @@ const CUSTOM_SERVICE = 'your-custom-service-uuid';
|
|
|
276
291
|
const COMMAND_CHARACTERISTIC = 'your-command-characteristic-uuid';
|
|
277
292
|
|
|
278
293
|
// Send a custom command
|
|
279
|
-
const enableLedCommand = [0x01, 0x1f, 0x01]; // Your protocol
|
|
294
|
+
const enableLedCommand = new Uint8Array([0x01, 0x1f, 0x01]); // Your protocol
|
|
280
295
|
await ble.writeCharacteristic(
|
|
281
296
|
deviceId,
|
|
282
297
|
CUSTOM_SERVICE,
|
|
283
298
|
COMMAND_CHARACTERISTIC,
|
|
284
|
-
enableLedCommand
|
|
299
|
+
enableLedCommand.buffer
|
|
285
300
|
);
|
|
286
301
|
```
|
|
287
302
|
|
|
@@ -331,6 +346,7 @@ interface ScanFilter {
|
|
|
331
346
|
serviceUUIDs?: string[];
|
|
332
347
|
rssiThreshold?: number;
|
|
333
348
|
allowDuplicates?: boolean;
|
|
349
|
+
androidScanMode?: AndroidScanMode;
|
|
334
350
|
}
|
|
335
351
|
|
|
336
352
|
interface Subscription {
|
|
@@ -346,9 +362,19 @@ enum BLEState {
|
|
|
346
362
|
PoweredOn = 'PoweredOn'
|
|
347
363
|
}
|
|
348
364
|
|
|
365
|
+
enum AndroidScanMode {
|
|
366
|
+
LowLatency = 'LowLatency', // Highest power, fastest discovery
|
|
367
|
+
Balanced = 'Balanced', // Balanced power/discovery (default)
|
|
368
|
+
LowPower = 'LowPower', // Lowest power, slower discovery
|
|
369
|
+
Opportunistic = 'Opportunistic', // Only when other apps are scanning
|
|
370
|
+
}
|
|
371
|
+
|
|
349
372
|
// Callback types
|
|
373
|
+
type StateChangeCallback = (state: BLEState) => void;
|
|
374
|
+
type ScanEventCallback = (device: BLEDevice) => void;
|
|
375
|
+
type ScanErrorCallback = (error: string) => void; // Android only
|
|
350
376
|
type DisconnectEventCallback = (deviceId: string, interrupted: boolean, error: string) => void;
|
|
351
|
-
type CharacteristicUpdateCallback = (characteristicId: string, data:
|
|
377
|
+
type CharacteristicUpdateCallback = (characteristicId: string, data: ArrayBuffer) => void;
|
|
352
378
|
```
|
|
353
379
|
|
|
354
380
|
## 🏗️ Architecture
|
|
@@ -365,7 +391,7 @@ Built on [Nitro Modules](https://nitro.margelo.com/) for:
|
|
|
365
391
|
### Platform Implementation
|
|
366
392
|
|
|
367
393
|
- **iOS**: ✅ Complete Swift implementation using Core Bluetooth
|
|
368
|
-
- **Android**:
|
|
394
|
+
- **Android**: ✅ Complete Kotlin implementation using Android BLE APIs
|
|
369
395
|
- **Shared C++**: Common logic and type definitions via Nitro Modules
|
|
370
396
|
|
|
371
397
|
### Compatibility Layer
|
|
@@ -388,6 +414,7 @@ interface BleNitroPluginProps {
|
|
|
388
414
|
neverForLocation?: boolean; // Assert no location derivation [Android 12+]
|
|
389
415
|
modes?: ('peripheral' | 'central')[]; // iOS background modes
|
|
390
416
|
bluetoothAlwaysPermission?: string | false; // iOS permission message
|
|
417
|
+
androidAdvertisingEnabled?: boolean; // Android Peripheral mode (advertising)
|
|
391
418
|
}
|
|
392
419
|
```
|
|
393
420
|
|
|
@@ -405,7 +432,7 @@ Adds these to `Info.plist`:
|
|
|
405
432
|
|
|
406
433
|
### Android Permissions
|
|
407
434
|
|
|
408
|
-
Automatically adds required permissions
|
|
435
|
+
Automatically adds required permissions and also handling neverForLocation and advertise mode.
|
|
409
436
|
|
|
410
437
|
```xml
|
|
411
438
|
<!-- Basic Bluetooth -->
|
|
@@ -413,7 +440,6 @@ Automatically adds required permissions:
|
|
|
413
440
|
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
|
|
414
441
|
|
|
415
442
|
<!-- Location (required for BLE scanning) -->
|
|
416
|
-
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
|
417
443
|
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
|
418
444
|
|
|
419
445
|
<!-- Android 12+ -->
|
|
@@ -425,6 +451,47 @@ Automatically adds required permissions:
|
|
|
425
451
|
<uses-feature android:name="android.hardware.bluetooth_le" android:required="false" />
|
|
426
452
|
```
|
|
427
453
|
|
|
454
|
+
## Android Flow with Permission Handling
|
|
455
|
+
|
|
456
|
+
```ts
|
|
457
|
+
import { PermissionsAndroid, Platform } from 'react-native';
|
|
458
|
+
|
|
459
|
+
const requestPermissionsAndroid = async () => {
|
|
460
|
+
if (Platform.OS !== 'android') {
|
|
461
|
+
return true
|
|
462
|
+
}
|
|
463
|
+
if (Platform.OS === 'android' && PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION) {
|
|
464
|
+
const apiLevel = parseInt(Platform.Version.toString(), 10);
|
|
465
|
+
if (apiLevel < 31) {
|
|
466
|
+
const result = await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION);
|
|
467
|
+
return (
|
|
468
|
+
result === PermissionsAndroid.RESULTS.GRANTED
|
|
469
|
+
);
|
|
470
|
+
}
|
|
471
|
+
if (PermissionsAndroid.PERMISSIONS.BLUETOOTH_SCAN && PermissionsAndroid.PERMISSIONS.BLUETOOTH_CONNECT) {
|
|
472
|
+
const result = await PermissionsAndroid.requestMultiple([
|
|
473
|
+
PermissionsAndroid.PERMISSIONS.BLUETOOTH_SCAN,
|
|
474
|
+
PermissionsAndroid.PERMISSIONS.BLUETOOTH_CONNECT,
|
|
475
|
+
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION
|
|
476
|
+
])
|
|
477
|
+
|
|
478
|
+
return (
|
|
479
|
+
result['android.permission.BLUETOOTH_CONNECT'] === PermissionsAndroid.RESULTS.GRANTED &&
|
|
480
|
+
result['android.permission.BLUETOOTH_SCAN'] === PermissionsAndroid.RESULTS.GRANTED &&
|
|
481
|
+
result['android.permission.ACCESS_FINE_LOCATION'] === PermissionsAndroid.RESULTS.GRANTED
|
|
482
|
+
)
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
logMessage('Request permissions failed');
|
|
486
|
+
throw new Error('Request permissions failed');
|
|
487
|
+
}
|
|
488
|
+
};
|
|
489
|
+
|
|
490
|
+
const hasPermissions = await requestPermissionsAndroid();
|
|
491
|
+
|
|
492
|
+
// Then start scanning or other operations
|
|
493
|
+
```
|
|
494
|
+
|
|
428
495
|
## 🔧 Development
|
|
429
496
|
|
|
430
497
|
### Building the Library
|
|
@@ -481,7 +548,7 @@ MIT License - see [LICENSE](./LICENSE) file.
|
|
|
481
548
|
|
|
482
549
|
## 🙏 Acknowledgments
|
|
483
550
|
|
|
484
|
-
- [Zyke Band](https://zykeband.com) - The fitness tracker project that inspired this library
|
|
551
|
+
- [Zyke Band](https://zykeband.com?utm_source=github&utm_medium=readme&utm_campaign=opensource) - The fitness tracker project that inspired this library
|
|
485
552
|
- [Marc Rousavy](https://github.com/mrousavy) - Creator of Nitro Modules and CEO of Margelo
|
|
486
553
|
- [Nitro Modules](https://nitro.margelo.com/) - High-performance native module framework
|
|
487
554
|
- [Margelo](https://margelo.com/) - Nitro Modules creators
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
project(BleNitro)
|
|
2
|
+
cmake_minimum_required(VERSION 3.9.0)
|
|
3
|
+
|
|
4
|
+
set (PACKAGE_NAME BleNitro)
|
|
5
|
+
set (CMAKE_VERBOSE_MAKEFILE ON)
|
|
6
|
+
set (CMAKE_CXX_STANDARD 20)
|
|
7
|
+
|
|
8
|
+
# Enable Raw Props parsing in react-native (for Nitro Views)
|
|
9
|
+
add_compile_options(-DRN_SERIALIZABLE_STATE=1)
|
|
10
|
+
|
|
11
|
+
# Define C++ library and add all sources
|
|
12
|
+
add_library(${PACKAGE_NAME} SHARED
|
|
13
|
+
src/main/cpp/cpp-adapter.cpp
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
# Add Nitrogen specs :)
|
|
17
|
+
include(${CMAKE_SOURCE_DIR}/../nitrogen/generated/android/BleNitro+autolinking.cmake)
|
|
18
|
+
|
|
19
|
+
# Set up local includes
|
|
20
|
+
include_directories(
|
|
21
|
+
"src/main/cpp"
|
|
22
|
+
"../cpp"
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
find_library(LOG_LIB log)
|
|
26
|
+
|
|
27
|
+
# Link all libraries together
|
|
28
|
+
target_link_libraries(
|
|
29
|
+
${PACKAGE_NAME}
|
|
30
|
+
${LOG_LIB}
|
|
31
|
+
android # <-- Android core
|
|
32
|
+
)
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
buildscript {
|
|
2
|
+
repositories {
|
|
3
|
+
google()
|
|
4
|
+
mavenCentral()
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
dependencies {
|
|
8
|
+
classpath "com.android.tools.build:gradle:8.12.1"
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
def reactNativeArchitectures() {
|
|
13
|
+
def value = rootProject.getProperties().get("reactNativeArchitectures")
|
|
14
|
+
return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
def isNewArchitectureEnabled() {
|
|
18
|
+
return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
apply plugin: "com.android.library"
|
|
22
|
+
apply plugin: 'org.jetbrains.kotlin.android'
|
|
23
|
+
apply from: '../nitrogen/generated/android/BleNitro+autolinking.gradle'
|
|
24
|
+
apply from: "./fix-prefab.gradle"
|
|
25
|
+
|
|
26
|
+
if (isNewArchitectureEnabled()) {
|
|
27
|
+
apply plugin: "com.facebook.react"
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
def getExtOrDefault(name) {
|
|
31
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["BleNitro_" + name]
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
def getExtOrIntegerDefault(name) {
|
|
35
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["BleNitro_" + name]).toInteger()
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
android {
|
|
39
|
+
namespace "com.margelo.nitro.co.zyke.ble"
|
|
40
|
+
|
|
41
|
+
ndkVersion getExtOrDefault("ndkVersion")
|
|
42
|
+
compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
|
|
43
|
+
|
|
44
|
+
defaultConfig {
|
|
45
|
+
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
|
|
46
|
+
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
|
|
47
|
+
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
|
|
48
|
+
|
|
49
|
+
externalNativeBuild {
|
|
50
|
+
cmake {
|
|
51
|
+
cppFlags "-frtti -fexceptions -Wall -Wextra -fstack-protector-all"
|
|
52
|
+
arguments "-DANDROID_STL=c++_shared", "-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON"
|
|
53
|
+
abiFilters (*reactNativeArchitectures())
|
|
54
|
+
|
|
55
|
+
buildTypes {
|
|
56
|
+
debug {
|
|
57
|
+
cppFlags "-O1 -g"
|
|
58
|
+
}
|
|
59
|
+
release {
|
|
60
|
+
cppFlags "-O2"
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
externalNativeBuild {
|
|
68
|
+
cmake {
|
|
69
|
+
path "CMakeLists.txt"
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
packagingOptions {
|
|
74
|
+
excludes = [
|
|
75
|
+
"META-INF",
|
|
76
|
+
"META-INF/**",
|
|
77
|
+
"**/libc++_shared.so",
|
|
78
|
+
"**/libfbjni.so",
|
|
79
|
+
"**/libjsi.so",
|
|
80
|
+
"**/libfolly_json.so",
|
|
81
|
+
"**/libfolly_runtime.so",
|
|
82
|
+
"**/libglog.so",
|
|
83
|
+
"**/libhermes.so",
|
|
84
|
+
"**/libhermes-executor-debug.so",
|
|
85
|
+
"**/libhermes_executor.so",
|
|
86
|
+
"**/libreactnative.so",
|
|
87
|
+
"**/libreactnativejni.so",
|
|
88
|
+
"**/libturbomodulejsijni.so",
|
|
89
|
+
"**/libreact_nativemodule_core.so",
|
|
90
|
+
"**/libjscexecutor.so"
|
|
91
|
+
]
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
buildFeatures {
|
|
95
|
+
buildConfig true
|
|
96
|
+
prefab true
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
buildTypes {
|
|
100
|
+
release {
|
|
101
|
+
minifyEnabled false
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
lintOptions {
|
|
106
|
+
disable "GradleCompatible"
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
compileOptions {
|
|
110
|
+
sourceCompatibility JavaVersion.VERSION_1_8
|
|
111
|
+
targetCompatibility JavaVersion.VERSION_1_8
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
sourceSets {
|
|
115
|
+
main {
|
|
116
|
+
if (isNewArchitectureEnabled()) {
|
|
117
|
+
java.srcDirs += [
|
|
118
|
+
// React Codegen files
|
|
119
|
+
"${project.buildDir}/generated/source/codegen/java"
|
|
120
|
+
]
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
repositories {
|
|
127
|
+
mavenCentral()
|
|
128
|
+
google()
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
dependencies {
|
|
133
|
+
// For < 0.71, this will be from the local maven repo
|
|
134
|
+
// For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
|
|
135
|
+
//noinspection GradleDynamicVersion
|
|
136
|
+
implementation "com.facebook.react:react-native:+"
|
|
137
|
+
|
|
138
|
+
// Add a dependency on NitroModules
|
|
139
|
+
implementation project(":react-native-nitro-modules")
|
|
140
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
tasks.configureEach { task ->
|
|
2
|
+
// Make sure that we generate our prefab publication file only after having built the native library
|
|
3
|
+
// so that not a header publication file, but a full configuration publication will be generated, which
|
|
4
|
+
// will include the .so file
|
|
5
|
+
|
|
6
|
+
def prefabConfigurePattern = ~/^prefab(.+)ConfigurePackage$/
|
|
7
|
+
def matcher = task.name =~ prefabConfigurePattern
|
|
8
|
+
if (matcher.matches()) {
|
|
9
|
+
def variantName = matcher[0][1]
|
|
10
|
+
task.outputs.upToDateWhen { false }
|
|
11
|
+
task.dependsOn("externalNativeBuild${variantName}")
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
afterEvaluate {
|
|
16
|
+
def abis = reactNativeArchitectures()
|
|
17
|
+
rootProject.allprojects.each { proj ->
|
|
18
|
+
if (proj === rootProject) return
|
|
19
|
+
|
|
20
|
+
def dependsOnThisLib = proj.configurations.findAll { it.canBeResolved }.any { config ->
|
|
21
|
+
config.dependencies.any { dep ->
|
|
22
|
+
dep.group == project.group && dep.name == project.name
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (!dependsOnThisLib && proj != project) return
|
|
26
|
+
|
|
27
|
+
if (!proj.plugins.hasPlugin('com.android.application') && !proj.plugins.hasPlugin('com.android.library')) {
|
|
28
|
+
return
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
def variants = proj.android.hasProperty('applicationVariants') ? proj.android.applicationVariants : proj.android.libraryVariants
|
|
32
|
+
// Touch the prefab_config.json files to ensure that in ExternalNativeJsonGenerator.kt we will re-trigger the prefab CLI to
|
|
33
|
+
// generate a libnameConfig.cmake file that will contain our native library (.so).
|
|
34
|
+
// See this condition: https://cs.android.com/android-studio/platform/tools/base/+/mirror-goog-studio-main:build-system/gradle-core/src/main/java/com/android/build/gradle/tasks/ExternalNativeJsonGenerator.kt;l=207-219?q=createPrefabBuildSystemGlue
|
|
35
|
+
variants.all { variant ->
|
|
36
|
+
def variantName = variant.name
|
|
37
|
+
abis.each { abi ->
|
|
38
|
+
def searchDir = new File(proj.projectDir, ".cxx/${variantName}")
|
|
39
|
+
if (!searchDir.exists()) return
|
|
40
|
+
def matches = []
|
|
41
|
+
searchDir.eachDir { randomDir ->
|
|
42
|
+
def prefabFile = new File(randomDir, "${abi}/prefab_config.json")
|
|
43
|
+
if (prefabFile.exists()) matches << prefabFile
|
|
44
|
+
}
|
|
45
|
+
matches.each { prefabConfig ->
|
|
46
|
+
prefabConfig.setLastModified(System.currentTimeMillis())
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|