question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

react-native link get a wrong projectConfig (./android/src should be ./android/app/src)

See original GitHub issue

Please provide all the information requested. Issues that do not follow this format are likely to stall.

Description

I was trying to use react-native-link <some package> but it returns an error

Error: ENOENT: no such file or directory, open 'D:\Android\Project\test\android\src\main\java\com\test\MainApplication.java' After I try to debug the problem and I log the projectConfig in registerNativeAndroidModule (from @react-native-community\cli-platform-android\build\link\registerNativeModule.js:36:27)

it shows

{ sourceDir: ‘D:\Android\Project\test\android’, isFlat: true, folder: ‘D:\Android\Project\test’, stringsPath: ‘D:\Android\Project\test\android\src\main\res\values\strings.xml’, manifestPath: ‘D:\Android\Project\test\android\app\src\main\AndroidManifest.xml’, buildGradlePath: ‘D:\Android\Project\test\android\build.gradle’, settingsGradlePath: ‘D:\Android\Project\test\android\settings.gradle’, assetsPath: ‘D:\Android\Project\test\android\src\main\assets’, mainFilePath: ‘D:\Android\Project\test\android\src\main\java\com\test\MainApplication.java’, packageName: ‘com.test’, packageFolder: ‘’, appName: ‘app’ }

which is wrong, those files should be under <root>\android\app\src\… instead of <root>\android\src\…

stack trace

error Linking “react-native-splash-screen” failed. Error: ENOENT: no such file or directory, open ‘D:\Android\Project\test\android\src\main\java\com\test\MainApplication.java’ at Object.openSync (fs.js:443:3) at Object.readFileSync (fs.js:343:35) at applyPatch (D:\Android\Project\test\node_modules@react-native-community\cli-platform-android\build\link\patches\applyPatch.js:42:51) at Object.registerNativeAndroidModule [as register] (D:\Android\Project\test\node_modules@react-native-community\cli-platform-android\build\link\registerNativeModule.js:36:27) at Object.keys.forEach.platform (D:\Android\Project\test\node_modules@react-native-community\cli\build\commands\link\linkDependency.js:63:16) at Array.forEach (<anonymous>) at linkDependency (D:\Android\Project\test\node_modules@react-native-community\cli\build\commands\link\linkDependency.js:36:32) at process._tickCallback (internal/process/next_tick.js:68:7) at Function.Module.runMain (internal/modules/cjs/loader.js:834:11) at startup (internal/bootstrap/node.js:283:19)

React Native version:

System: OS: Windows 10 10.0.18362 CPU: (6) x64 Intel® Core™ i5-8400 CPU @ 2.80GHz Memory: 10.73 GB / 23.95 GB Binaries: Node: 10.16.3 - C:\Environment\Node\node.EXE Yarn: 1.22.4 - D:\Android\Project\test\node_modules.bin\yarn.CMD npm: 6.9.0 - C:\Environment\Node\npm.CMD Watchman: Not Found SDKs: Android SDK: API Levels: 26, 28, 29 Build Tools: 28.0.3, 29.0.2 System Images: android-28 | Google APIs Intel x86 Atom, android-29 | Google APIs Intel x86 Atom Android NDK: Not Found IDEs: Android Studio: Not Found Languages: Python: 3.6.5 - C:\Environment\Anaconda3\python.EXE npmPackages: @react-native-community/cli: Not Found react: ^16.13.1 => 16.13.1 react-native: ^0.62.0 => 0.62.0 npmGlobalPackages: react-native: Not Found

Steps To Reproduce

Provide a detailed list of steps that reproduce the issue.

  1. npx react-native init test
  2. npm i --save react-native-vector-icons
  3. react-native link react-native-vector-icons

Expected Results

the projectConfig should be

{ sourceDir: ‘D:\Android\Project\test\android’, isFlat: true, folder: ‘D:\Android\Project\test’, stringsPath: ‘D:\Android\Project\test\android\app\src\main\res\values\strings.xml’, manifestPath: ‘D:\Android\Project\test\android\app\src\main\AndroidManifest.xml’, buildGradlePath: ‘D:\Android\Project\test\android\build.gradle’, settingsGradlePath: ‘D:\Android\Project\test\android\settings.gradle’, assetsPath: ‘D:\Android\Project\test\android\app\src\main\assets’, mainFilePath: ‘D:\Android\Project\test\android\app\src\main\java\com\test\MainApplication.java’, packageName: ‘com.test’, packageFolder: ‘’, appName: ‘app’ }

Snack, code example, screenshot, or link to a repository:

Quick fix: I solve the problem by manually changing the projectConfig.stringsPath and projectConfig.mainFilePath in registerNativeAndroidModule (from @react-native-community\cli-platform-android\build\link\registerNativeModule.js:36:27) projectConfig.stringsPath = 'D:\\Android\\Project\\test\\android\\app\\src\\main\\res\\values\\strings.xml'; projectConfig.mainFilePath = 'D:\\Android\\Project\\test\\android\\app\\src\\main\\java\\com\\test\\MainApplication.java';

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:4
  • Comments:5

github_iconTop GitHub Comments

6reactions
yoerivdmcommented, Mar 29, 2020

It’s easier to provide a custom config to correct the paths to be used by the CLI.

I fixed it by adding a react-native.config.js file to my project with contents:

module.exports = {
    project: {
        android: {
            stringsPath: "app\\src\\main\\res\\values\\strings.xml",
            mainFilePath: "app\\src\\main\\java\\com\\swingle\\MainApplication.java"
        },
    },
};
0reactions
ghasemikasra39commented, Jun 25, 2021
➜  realnote_app git:(flipper) ✗ npx react-native link react-native-photo-editor
warn Calling react-native link [packageName] is deprecated in favor of autolinking. It will be removed in the next major release.
Autolinking documentation: https://github.com/react-native-community/cli/blob/master/docs/autolinking.md
info iOS module "react-native-photo-editor" is already linked
info Linking "react-native-photo-editor" Android dependency
error Linking "react-native-photo-editor" failed.
Error: ENOENT: no such file or directory, open '/Users/kasra/Documents/realnote_app/android/app/src/main/java/one/realnote/app/MainApplication.java'
    at Object.openSync (node:fs:506:3)
    at Object.readFileSync (node:fs:402:35)
    at applyPatch (/Users/kasra/Documents/realnote_app/node_modules/@react-native-community/cli-platform-android/build/link/patches/applyPatch.js:42:51)
    at Object.registerNativeAndroidModule [as register] (/Users/kasra/Documents/realnote_app/node_modules/@react-native-community/cli-platform-android/build/link/registerNativeModule.js:34:27)
    at /Users/kasra/Documents/realnote_app/node_modules/@react-native-community/cli/build/commands/link/linkDependency.js:63:16
    at Array.forEach (<anonymous>)
    at linkDependency (/Users/kasra/Documents/realnote_app/node_modules/@react-native-community/cli/build/commands/link/linkDependency.js:36:32)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Object.link [as func] (/Users/kasra/Documents/realnote_app/node_modules/@react-native-community/cli/build/commands/link/link.js:110:5)
    at async Command.handleAction (/Users/kasra/Documents/realnote_app/node_modules/@react-native-community/cli/build/index.js:186:9)
info Run CLI with --verbose flag for more details.

Same issue on 0.64.1, I have to manually link this package. I don’t have MainApplication.java, I have MainApplication.kt, and it cannot find it.

I added this , but no success:

  "rnpm": {
    "android": {
      "mainFilePath": "src/main/java/one/realnote/app/MainApplication.kt"
    }
  },
Read more comments on GitHub >

github_iconTop Results From Across the Web

React native link fails with no package found
So the answer to my question was that in my android manifest xml file, there was an incorrect closing brace for one of...
Read more >
react-native-reanimated:downloaddoubleconversion failed ...
I'm giving it the command: react-native run-android --deviceId=MY_DEVICE_ID But it gives this error: * What went wrong: Execution failed for task ...
Read more >
Unable to configure zoom video sdk in react native project
Getting Started Set up a Zoom Video SDK account and Download the Zoom Video SDK for iOS or Android. Install via NPM In...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found