Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/eighty-papayas-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rnef/platform-android': patch
---

fix: React Native gradle plugin path resolution for PNPM
14 changes: 12 additions & 2 deletions packages/platform-android/template/android/settings.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
pluginManagement { includeBuild("../node_modules/@react-native/gradle-plugin") }
pluginManagement {
apply from: "./utils.gradle"
def reactNativePath = resolveNodeModule('react-native', rootDir)
def gradlePluginPath = resolveNodeModule('@react-native/gradle-plugin', reactNativePath)

settings.ext.gradlePluginPath = gradlePluginPath.path
includeBuild(gradlePluginPath.path)
}

plugins { id("com.facebook.react.settings") }
extensions.configure(com.facebook.react.ReactSettingsExtension){ ex -> ex.autolinkLibrariesFromCommand(['npx', 'rnef', 'config', '-p', 'android']) }

rootProject.name = 'HelloWorld'

include ':app'
includeBuild('../node_modules/@react-native/gradle-plugin')
includeBuild(ext.gradlePluginPath)
14 changes: 14 additions & 0 deletions packages/platform-android/template/android/utils.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
ext.resolveNodeModule = { String packageName, File startDir ->
def candidate = new File(startDir, "node_modules/$packageName")

if (candidate.exists()) {
return candidate.canonicalFile
}

def parentDir = startDir.parentFile
if (parentDir == null || startDir.canonicalPath == parentDir.canonicalPath) {
throw new GradleException("Failed to find the package '$packageName'. Ensure you have installed node_modules.")
}

return resolveNodeModule(packageName, parentDir)
}