Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scaffold a React Native library: Nitro module #768

Closed
1 of 2 tasks
mensonones opened this issue Feb 15, 2025 · 4 comments · Fixed by #770
Closed
1 of 2 tasks

Scaffold a React Native library: Nitro module #768

mensonones opened this issue Feb 15, 2025 · 4 comments · Fixed by #770
Labels
bug Something isn't working

Comments

@mensonones
Copy link

mensonones commented Feb 15, 2025

Description

After generated project, i followed steps:

Get started with the project:

yarn

Run the example app on iOS:

yarn example ios

Run the example app on Android:

yarn example android

I ran the command:

yarn example android

I got the error:

FAILURE: Build completed with 2 failures.

1: Task failed with an exception.
-----------
* Where:
Build file '/home/jack/PersonalProjects/awesome-library-nitro/android/build.gradle' line: 29

* What went wrong:
A problem occurred evaluating project ':react-native-awesome-library-nitro'.
> Could not read script '/home/jack/PersonalProjects/awesome-library-nitro/nitrogen/generated/android/awesomelibrarynitro+autolinking.gradle' as it does not exist.

the folder nitrogen was not generated

but since I know a little about Nitro, I already knew what I should do and I accessed it: https://nitro.margelo.com/docs/nitrogen#configuration

after running the command in the root of the project

yarn nitro-codegen

the folder nitrogen was generated

and I re-ran the command

yarn example android

I got the error

BUILD FAILED in 2m 2s
error Failed to install the app. Command failed with exit code 1: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
/home/jack/PersonalProjects/awesome-library-nitro/example/node_modules/react-native-nitro-modules/android/src/main/java/com/margelo/nitro/core/HybridObjectRegistry.java:26: warning: [removal] HybridObjectInitializer in com.margelo.nitro.core has been deprecated and marked for removal public static native void registerHybridObjectConstructor(String hybridObjectName, HybridObjectInitializer initializer); ^
1 warning
e: file:///home/jack/PersonalProjects/awesome-library-nitro/android/src/main/java/com/margelo/nitro/awesomelibrarynitro/AwesomeLibraryNitro.kt:3:2 Unresolved reference 'DoNotStrip'. FAILURE: Build failed with an exception. * What went wrong:
Execution failed for task ':react-native-awesome-library-nitro:compileDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction > Compilation error. See log for more details * Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org. BUILD FAILED in 2m 2s.
info Run CLI with --verbose flag for more details.

When I opened the file in question, I saw the code and removed the annotation

Image

I re-ran the command

yarn example android

the project ran without problems

Image

PS: link repository without my change in AwesomeLibraryNitro.kt

Packages

  • create-react-native-library
  • react-native-builder-bob

Selected options

Nitro Module

Link to repro

https://github.com/mensonones/awesome-library-nitro

Environment

npx react-native info
info Fetching system and libraries information...
System:
OS: Linux 6.8 Ubuntu 22.04.5 LTS 22.04.5 LTS (Jammy Jellyfish)
CPU: (16) x64 11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz
Memory: 15.98 GB / 31.13 GB
Shell:
version: 5.1.16
path: /bin/bash
Binaries:
Node:
version: 20.12.2
path: /usr/local/bin/node
Yarn:
version: 3.6.1
path: /usr/local/bin/yarn
npm:
version: 10.5.0
path: /usr/local/bin/npm
Watchman:
version: 4.9.0
path: /usr/bin/watchman
SDKs:
Android SDK: Not Found
IDEs:
Android Studio: Not Found
Languages:
Java:
version: 17.0.14
path: /usr/bin/javac
Ruby: Not Found
npmPackages:
"@react-native-community/cli":
installed: 15.1.3
wanted: ^15.1.3
react:
installed: 18.3.1
wanted: 18.3.1
react-native: Not Found
npmGlobalPackages:
"react-native": Not Found
Android:
hermesEnabled: Not found
newArchEnabled: Not found
iOS:
hermesEnabled: Not found
newArchEnabled: Not found

@mensonones mensonones added the bug Something isn't working label Feb 15, 2025
@atlj
Copy link
Collaborator

atlj commented Feb 18, 2025

Hey @mrousavy have you folks hit this problem before? Looks like removing @DoNotStrip helps. Should we remove that from the template for now?

@mrousavy
Copy link
Contributor

Hey - you need to import @DoNotStrip. Created a PR to fix this here: #770

About the +autolinking.gradle not being found; yes that's expected - you need to run nitrogen first. Maybe nitrogen should run as an extra step after scaffolding the library? Not sure if that's a good idea tbh.

@mensonones
Copy link
Author

I wasn't familiar with that annotation, I just removed it to make it work.

As for the step related to nitrogen, it would be good to clarify this step in the documentation so there are no doubts about what to do.

Thanks for the support 😃

@atlj
Copy link
Collaborator

atlj commented Feb 19, 2025

Maybe nitrogen should run as an extra step after scaffolding the library? Not sure if that's a good idea tbh.

Not a bad one TBH @satya164 any thoughts on this?

github-merge-queue bot pushed a commit that referenced this issue Feb 19, 2025
<!-- Please provide enough information so that others can review your
pull request. -->
<!-- Keep pull requests small and focused on a single change. -->

### Summary

- Fixes #768

<!-- What existing problem does the pull request solve? Can you solve
the issue with a different approach? -->

### Test plan

<!-- List the steps with which we can test this change. Provide
screenshots if this changes anything visual. -->
@atlj atlj closed this as completed in #770 Feb 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants