Skip to content

fix: 🐛 Check if a path(basePath) exists on Android, RN >= 0.80 #117

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tconns
Copy link

@tconns tconns commented Aug 5, 2025

Summary

Because RN >= 0.80 has extracted the example out of the core

Changelog

Test Plan

Because RN >= 0.80 has extracted the example out of the core
Copy link
Contributor

@dougg0k dougg0k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should do a check before, if the previous path are not available, then you use the new path. Otherwise it will be compatible only with the newer version of RN.

@tconns
Copy link
Author

tconns commented Aug 5, 2025

You should do a check before, if the previous path are not available, then you use the new path. Otherwise it will be compatible only with the newer version of RN.

But the check just above was already working with RN versions below 0.80, wasn’t it?

@ildfreelancer
Copy link

@tconns your fix seems wrong

it should be

reactNativeDir = Paths.get(nodeModulesDir.toString(), "react-native/android")
if (!reactNativeDir.toFile().exists()) {
  reactNativeDir = Paths.get(nodeModulesDir.toString(), "react-native/ReactAndroid")
}

@numandev1
Copy link
Owner

i also agree with @ildfreelancer

@numandev1
Copy link
Owner

@dougg0k I sent you an invite on GitHub, can you check?

@dougg0k
Copy link
Contributor

dougg0k commented Aug 6, 2025

Thanks @numandev1 but I am good as collab / contrib only, when I can.

@dougg0k
Copy link
Contributor

dougg0k commented Aug 9, 2025

The current impl are weird, even though the first are being used for the project, a different path is used for the example project.

Then it's checked again for the actual node_modules. It seem to contain duplication in there.

https://github.com/numandev1/react-native-keys/blob/main/android/build.gradle#L85


Perhaps it should be.

// Find node_modules inside the example project
def nodeModulesDir = Paths.get(basePath.toString(), "node_modules")
def reactNativeDir = Paths.get(nodeModulesDir.toString(), "react-native/android")
if (!reactNativeDir.toFile().exists()) {
  reactNativeDir = Paths.get(nodeModulesDir.toString(), "react-native/ReactAndroid")
}
if (nodeModulesDir.toFile().exists() && reactNativeDir.toFile().exists()) {
  found = true
}

Removing


if(!found){
  // Node's module resolution algorithm searches up to the root directory,
  // after which the base path will be null
  while (basePath) {
    nodeModulesDir = Paths.get(basePath.toString(), "node_modules")
    reactNativeDir = Paths.get(nodeModulesDir.toString(), "react-native/android")
    if (nodeModulesDir.toFile().exists() && reactNativeDir.toFile().exists()) {
      found = true
      break;
    }
    basePath = basePath.getParent()
  }
}

Since the example project should have no ties to the project. But it's own android folder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants