Open shubhamguptadream11 opened 6 days ago
Hey - yep this benchmark was built in just a few min for iOS only. I haven't implemented Android yet, but feel free to implement the same specs on Android to run it :)
@mrousavy I tried creating a Nitro module for Android by following the Nitro docs. I created a bare React Native project and tried adding the Nitro module using the template.
However, I got stuck trying to resolve this issue that occurs during runtime:
(NOBRIDGE) ERROR Warning: Error: Exception in HostFunction: Cannot create an instance of HybridObject "Calculator" - It has not yet been registered in the Nitro Modules HybridObjectRegistry! Suggestions:
- If you use Nitrogen, make sure your `nitro.json` contains `Calculator` on this platform.
- If you use Nitrogen, make sure your library (*Package.java)/app (MainApplication.java) calls `System.loadLibrary("<<androidCxxLibName>>")` somewhere on app-startup.
- If you use Nitrogen, make sure your cpp-adapter.cpp calls `margelo::nitro::<<cxxNamespace>>::initialize(vm)`.
- If you use Nitrogen, inspect the generated `<<androidCxxLibName>>OnLoad.cpp` file.
- If you don't use Nitrogen, make sure you called `HybridObjectRegistry.registerHybridObject(...)`.
at App
at RCTView
at View (http://10.0.2.2:8081/index.bundle//&platform=android&dev=true&lazy=true&minify=false&app=com.myapp&modulesOnly=false&runModule=true:64713:43)
at RCTView
at View (http://10.0.2.2:8081/index.bundle//&platform=android&dev=true&lazy=true&minify=false&app=com.myapp&modulesOnly=false&runModule=true:64713:43)
at AppContainer (http://10.0.2.2:8081/index.bundle//&platform=android&dev=true&lazy=true&minify=false&app=com.myapp&modulesOnly=false&runModule=true:64586:25)
at MyApp(RootComponent) (http://10.0.2.2:8081/index.bundle//&platform=android&dev=true&lazy=true&minify=false&app=com.myapp&modulesOnly=false&runModule=true:117226:28)
(NOBRIDGE) ERROR Warning: TypeError: Cannot read property 'NitroCalculator' of undefined
This error is located at:
in App
in RCTView (created by View)
in View (created by AppContainer)
in RCTView (created by View)
in View (created by AppContainer)
in AppContainer
in MyApp(RootComponent)
(NOBRIDGE) ERROR Warning: TypeError: Cannot read property 'NitroCalculator' of undefined
This error is located at:
in App
in RCTView (created by View)
in View (created by AppContainer)
in RCTView (created by View)
in View (created by AppContainer)
in AppContainer
in MyApp(RootComponent)
Repo link: https://github.com/shubham43245/nitro-module-benchmark
Attaching snapshot for reference:
hmm, maybe the react-native CLI (the default autolinking tool) doesn't pick up your module properly, and NitroCalculatorPackage
is never added?
Might need to add it to your react-native.config.js
, or link via yarn/bun, or monorepo, or explicitly add it to your app's gradle - multiple ways of doing that.
Cool. I tired auto linking my module by creating react-native.config.js
file and adding my module path in it.
Now it was failing during build time.
> Task :nitro-calculator:compileDebugKotlin FAILED
e: file:///Users/shubhamgupta/D11Repo/nitro-package/nitro-module-benchmark/node_modules/nitro-calculator/android/src/main/java/com/margelo/nitro/calculator/HybridCalculator.kt:4:26 Unresolved reference: HybridObject
e: file:///Users/shubhamgupta/D11Repo/nitro-package/nitro-module-benchmark/node_modules/nitro-calculator/android/src/main/java/com/margelo/nitro/calculator/HybridCalculator.kt:5:26 Unresolved reference: HybridObjectRegistry
e: file:///Users/shubhamgupta/D11Repo/nitro-package/nitro-module-benchmark/node_modules/nitro-calculator/android/src/main/java/com/margelo/nitro/calculator/HybridCalculator.kt:9:26 Unresolved reference: HybridObject
It seems that now it was picking module code at least 🤔
This is the react-native.config.js
file I added at root of my project.
module.exports = {
dependencies: {
'NitroCalculator': {
root: './modules/NitroCalculator',
},
},
};
I am trying to benchmark NitroModule on Android but cannot do so using the provided NitroBenchmarks repository.
Steps to Reproduce:
git clone git@github.com:mrousavy/NitroBenchmarks.git
cd NitroBenchmarks
yarn && yarn android
Reproducer App: NitroBenchmarks Repo
Able to run this on iOS simulator
The following error appears on Metro, preventing me from proceeding. Could you please assist in resolving this?
Attaching screenshot for reference: