react-native-builder-bob icon indicating copy to clipboard operation
react-native-builder-bob copied to clipboard

Autolinking task from example app fails, after adding codegen config to example app.

Open jhotadhari opened this issue 9 months ago • 7 comments

Description

Hi,

Android only, I have no idea about iOS

I tried to add a TurboModule to the example app. This TurboModule is only needed for the example app, so I added it to the example app only, not to the library itself. Adding TurboModules and FabricViews to the library worked without problems

For this I added a codegenConfig entry to ./example/package.json, adjusted codegenConfig.name, codegenConfig.android.javaPackageName. And added a ./example/src/NativeExample.ts module. And tried to start the example app, so that codegen can generate some code and I can start to build the module in java/kotlin.

The app didn't start (expected because the java side module didn't implement the methods yet). But the error was with autolinking: Full error:

FAILURE: Build completed with 2 failures.

1: Task failed with an exception.
-----------
* Where:
Build file '/home/jhotadhari/Development/android/test/react-native-mapsforge-vtm-new-arch/example/android/app/build.gradle' line: 54

* What went wrong:
A problem occurred evaluating project ':app'.
> Project with path ':react-native-mapsforge-vtm' could not be found in project ':app'.

* 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.
==============================================================================

2: Task failed with an exception.
-----------
* What went wrong:
A problem occurred configuring project ':app'.
> compileSdkVersion is not specified. Please add it to build.gradle

* 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 11s
error Failed to install the app. Command failed with exit code 1: ./gradlew app:installDebug -PreactNativeDevServerPort=8081 FAILURE: Build completed with 2 failures. 1: Task failed with an exception.
-----------
* Where:
Build file '/home/jhotadhari/Development/android/test/react-native-mapsforge-vtm-new-arch/example/android/app/build.gradle' line: 54 * What went wrong:
A problem occurred evaluating project ':app'.
> Project with path ':react-native-mapsforge-vtm' could not be found in project ':app'. * 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.
============================================================================== 2: Task failed with an exception.
-----------
* What went wrong:
A problem occurred configuring project ':app'.
> compileSdkVersion is not specified. Please add it to build.gradle * 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 11s.

Thats not the problem: The package name is react-native-mapsforge-vtm, and the directory is react-native-mapsforge-vtm-new-arch

That part is super weird:

* Where:
Build file '/home/jhotadhari/Development/android/test/react-native-mapsforge-vtm-new-arch/example/android/app/build.gradle' line: 54 * What went wrong:
A problem occurred evaluating project ':app'.
> Project with path ':react-native-mapsforge-vtm' could not be found in project ':app'.

build.gradle' line: 54 is:

autolinkLibrariesWithApp()

I went back in git history to a state were I know its stable. But the example app won't start anymore. Same error.

I tried to delete some generated code: rm yarn.lock; rm -rf node_modules/; rm -rf example/node_modules; rm -rf android/generated; rm -rf example/android/generated rm -rf example/android/.gradle; rm -rf android/.gradle; rm -rf example/android/.idea; yarn cache clean; yarn install

But still. the example app won't start, and the error is the same.

I navigated to another directory and cloned the project from git. But even there, I get the same error when I try to start the example app. This commit should work: https://github.com/jhotadhari/react-native-mapsforge-vtm-new-arch/tree/bd0cdca7cb43409ecba7922cb00b9b0de83ba498

I tried to install react-native-clean-project in the root and in the example. But it doesn't help.

It seems there is something cached outside of the repository, but I just can't find it.

I had the same issue some days ago. After installing https://www.npmjs.com/package/react-native-hardwarekey-event as a dependency for a library. After searching hours for the source of the error, I started a new project and copied the files over.

  • What kind of caches have to be deleted to start the example app again? from a state where I know it works.
  • Is it actually possible to add TurboModules inside the example app, without adding them to the library itself? (I know that it works with legacy native modules)
  • if yes, how?
  • if not, how to prevent that the example app becomes impossible to start?

Packages

  • [x] create-react-native-library
  • [ ] react-native-builder-bob

Selected options

  "create-react-native-library": {
    "languages": "kotlin-objc",
    "type": "fabric-view",
    "version": "0.49.8"
  },

Link to repro

https://github.com/jhotadhari/react-native-mapsforge-vtm-new-arch

Environment

System:
  OS: Linux 5.15 Ubuntu 22.04.5 LTS 22.04.5 LTS (Jammy Jellyfish)
  CPU: (8) x64 Intel(R) Core(TM) i7-8665U CPU @ 1.90GHz
  Memory: 6.97 GB / 15.28 GB
  Shell:
    version: 5.8.1
    path: /usr/bin/zsh
Binaries:
  Node:
    version: 22.14.0
    path: ~/.nvm/versions/node/v22.14.0/bin/node
  Yarn:
    version: 3.6.1
    path: ~/.nvm/versions/node/v22.14.0/bin/yarn
  npm:
    version: 10.9.2
    path: ~/.nvm/versions/node/v22.14.0/bin/npm
  Watchman:
    version: 20240414.112832.0
    path: /usr/local/bin/watchman
SDKs:
  Android SDK:
    API Levels:
      - "31"
      - "34"
      - "35"
    Build Tools:
      - 30.0.3
      - 34.0.0
      - 35.0.0
      - 36.0.0
    System Images:
      - android-34 | Google APIs Intel x86_64 Atom
      - android-VanillaIceCream | Google Play Intel x86_64 Atom
    Android NDK: Not Found
IDEs:
  Android Studio: AI-243.24978.46.2431.13208083
Languages:
  Java:
    version: 17.0.14
    path: /usr/bin/javac
  Ruby: Not Found
npmPackages:
  "@react-native-community/cli":
    installed: 15.0.1
    wanted: 15.0.1
  react:
    installed: 19.0.0
    wanted: 19.0.0
  react-native:
    installed: 0.78.2
    wanted: 0.78.2
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: false
  newArchEnabled: false
iOS:
  hermesEnabled: Not found
  newArchEnabled: Not found

jhotadhari avatar Apr 17 '25 20:04 jhotadhari

If I try to open the project with android-studio, I get this error:

1: Task failed with an exception.
-----------
* Where:
Build file '/home/jhotadhari/Development/android/test/react-native-mapsforge-vtm-new-arch/android/build.gradle' line: 22

* What went wrong:
A problem occurred evaluating root project 'android'.
> Plugin with id 'com.facebook.react' not found.

Same error, even if I checkout the very first commit

jhotadhari avatar Apr 18 '25 14:04 jhotadhari

I tried to reproduce the error with a new created library. https://github.com/jhotadhari/react-native-demonstrate-linking-error

But I can't reproduce the error?!

... Still I can't get it to work to have a TurboModule inside the example application. But that's another story. The issue described above, I can't reproduce

Maybe probably its not a bug in create-react-native-library, And therefore here is not the right place for this problem, but if someone could point me in a direction that I can manage to start the example app again, I would be really happy

jhotadhari avatar Apr 18 '25 14:04 jhotadhari

@jhotadhari Open the example project in Android Studio, you will see the lib code there too.

AliRezaBeigy avatar Apr 19 '25 21:04 AliRezaBeigy

@jhotadhari Open the example project in Android Studio, you will see the lib code there too.

Hi, thanks for the suggestion. But I can't open it in android-studio as described above https://github.com/callstack/react-native-builder-bob/issues/825#issuecomment-2815513815

jhotadhari avatar Apr 23 '25 19:04 jhotadhari

I also encountered the same problem. When I checked the automatically generated [Android/build/generated/autolinking/autolinking. json] in the example, I found that there is an issue with the dependencies.xxxx.platforms.Android item, as its value does not have any meaningful fields. This situation occurred after the first successful build (at which point the autolink.json was correct), when I tried to clear all the build files and then resynchronize.

After my search, I believe this is a @react-native-community/cli bug. Please refer to this issue.

NiuGuohui avatar Jun 15 '25 14:06 NiuGuohui

Did anyone found a solution to this issue with autolinking? Seems like an issue with 79.2. 76.9. 75.5, etc. Did anyone use react-native.config.js to manually link? This has been an excruciating exercise, too many libraries are dependent on this feature

stevesze avatar Aug 01 '25 17:08 stevesze

I think I've found the problem. The root cause is that in an Android project, even for a pure C++ library, an empty XXXPackage.kt needs to be created at the corresponding package name location, because autolink depends on this file when generating JSON file!

NiuGuohui avatar Aug 02 '25 05:08 NiuGuohui