Skip to content

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

Closed

Description

@jhotadhari

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

  • 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

Activity

  1. jhotadhari commented on Apr 18, 2025

    @jhotadhari
    Author

    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

  2. jhotadhari commented on Apr 18, 2025

    @jhotadhari
    Author

    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

  3. AliRezaBeigy commented on Apr 19, 2025

    @AliRezaBeigy

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

  4. jhotadhari commented on Apr 23, 2025

    @jhotadhari
    Author

    @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 #825 (comment)

  5. NiuGuohui commented on Jun 15, 2025

    @NiuGuohui

    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.

  6. stevesze commented on Aug 1, 2025

    @stevesze

    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

  7. NiuGuohui commented on Aug 2, 2025

    @NiuGuohui

    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!

  8. jhotadhari commented on Jun 21, 2026

    @jhotadhari
    Author

    I opened the project after more then a year today and asked claude to solve the error.

    That fixes the issue:

    Summary

    Root cause: React Native's autolinking determines your module's Gradle project by scanning for a class that either implements ReactPackage or extends TurboReactPackage. Your MapsforgeVtmViewPackage only does extends BaseReactPackage, which doesn't match either pattern. So the CLI's npx react-native config returned an incomplete Android config (missing sourceDir), and the Gradle settings script silently dropped :react-native-mapsforge-vtm from settings.gradle — causing Project with path ':react-native-mapsforge-vtm' could not be found in project ':app'. It likely "used to work" because a previously cached autolinking.json was reused; a recent yarn install (your modified yarn.lock) invalidated that cache and forced re-detection, exposing the bug.

    Fix: in android/src/main/java/.../MapsforgeVtmViewPackage.java, added a redundant implements com.facebook.react.ReactPackage to the class declaration (harmless — BaseReactPackage already implements it) so the CLI's regex-based detector can find it.

    Caches: the stale, bad cache was example/android/build/generated/autolinking/autolinking.json — I deleted it (regenerated automatically on next build). You don't need to touch ~/.gradle or node_modules; no dependencies were missing.

    No files outside MapsforgeVtmViewPackage.java were changed. Android Studio sync should now work too, since it uses the same Gradle settings/autolinking path.

    import androidx.annotation.NonNull;
    
    import com.facebook.react.BaseReactPackage;
    + import com.facebook.react.ReactPackage;
    import com.facebook.react.bridge.NativeModule;
    import com.facebook.react.bridge.ReactApplicationContext;
    import com.facebook.react.module.model.ReactModuleInfo;
    import com.facebook.react.module.model.ReactModuleInfoProvider;
    import com.facebook.react.uimanager.ViewManager;
    - public class MapsforgeVtmViewPackage extends BaseReactPackage {
    + // "implements ReactPackage" is redundant (BaseReactPackage already implements it) but required
    + // for the react-native CLI's autolinking regex to detect this as the module's package class.
    + public class MapsforgeVtmViewPackage extends BaseReactPackage implements ReactPackage {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions