npx expo prebuild is not working with both android and ios

129 Views Asked by At

Summary

I'm the newbie about react-native and expo. I'm suffering some problems when I run this command npx expo prebuild.

  • Android: when I run android build with expo run:android, running is failed.
  • iOS: when I run npx expo prebuild, pod install is failed.

There are two problems.

What platform(s) does this occur on?

android, ios

iOS

  • run npx expo prebuild, then pod install failed.
  • I installed @react-native-community/cli-platform-ios with npm install @react-native-community/cli-platform-ios.
[!] Invalid `Podfile` file: cannot load such file -- {project_path}/node_modules/@react-native-community/cli-platform-ios/native_modules.rb

#  from {project_path}/ios/Podfile:2
#  -------------------------------------------
#  require File.join(File.dirname(`node --print "require.resolve('expo/package.json')"`), "scripts/autolinking")
>  require File.join(File.dirname(`node --print "require.resolve('react-native/package.json')"`), "scripts/react_native_pods")
#
#  -------------------------------------------

Android

Running is failed with these error.

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'sample-error-expo'.
> Could not determine the dependencies of null.
   > Could not resolve all task dependencies for configuration ':classpath'.
      > Could not find com.android.tools.build:gradle:.
        Required by:
            project :
      > Could not resolve com.facebook.react:react-native-gradle-plugin.
        Required by:
            project :
         > No matching variant of project :gradle-plugin was found. The consumer was configured to find a library for use during runtime, compatible with Java 8, packaged as a jar, and its dependencies declared externally, as well as attribute 'org.gradle.plugin.api-version' with value '8.3' but:
             - Variant 'apiElements' capability com.facebook.react:react-native-gradle-plugin:unspecified declares a library, packaged as a jar, and its dependencies declared externally:
                 - Incompatible because this component declares a component for use during compile-time, compatible with Java 11 and the consumer needed a component for use during runtime, compatible with Java 8
                 - Other compatible attribute:
                     - Doesn't say anything about org.gradle.plugin.api-version (required '8.3')
             - Variant 'mainSourceElements' capability com.facebook.react:react-native-gradle-plugin:unspecified declares a component, and its dependencies declared externally:
                 - Incompatible because this component declares a component of category 'verification' and the consumer needed a library
                 - Other compatible attributes:
                     - Doesn't say anything about its target Java version (required compatibility with Java 8)
                     - Doesn't say anything about its elements (required them packaged as a jar)
                     - Doesn't say anything about org.gradle.plugin.api-version (required '8.3')
                     - Doesn't say anything about its usage (required runtime)
             - Variant 'runtimeElements' capability com.facebook.react:react-native-gradle-plugin:unspecified declares a library for use during runtime, packaged as a jar, and its dependencies declared externally:
                 - Incompatible because this component declares a component, compatible with Java 11 and the consumer needed a component, compatible with Java 8
                 - Other compatible attribute:
                     - Doesn't say anything about org.gradle.plugin.api-version (required '8.3')
             - Variant 'testResultsElementsForTest' capability com.facebook.react:react-native-gradle-plugin:unspecified:
                 - Incompatible because this component declares a component of category 'verification' and the consumer needed a library
                 - Other compatible attributes:
                     - Doesn't say anything about how its dependencies are found (required its dependencies declared externally)
                     - Doesn't say anything about its target Java version (required compatibility with Java 8)
                     - Doesn't say anything about its elements (required them packaged as a jar)
                     - Doesn't say anything about org.gradle.plugin.api-version (required '8.3')
                     - Doesn't say anything about its usage (required runtime)

* 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 4s
Error: /Users/roseline/projects/sample-error-expo/android/gradlew exited with non-zero code: 1
Error: /Users/roseline/projects/sample-error-expo/android/gradlew exited with non-zero code: 1
    at ChildProcess.completionListener (/Users/roseline/projects/sample-error-expo/node_modules/@expo/spawn-async/build/spawnAsync.js:52:23)
    at Object.onceWrapper (node:events:628:26)
    at ChildProcess.emit (node:events:513:28)
    at maybeClose (node:internal/child_process:1091:16)
    at ChildProcess._handle.onexit (node:internal/child_process:302:5)
    ...
    at Object.spawnAsync [as default] (/Users/roseline/projects/sample-error-expo/node_modules/@expo/spawn-async/build/spawnAsync.js:17:21)
    at spawnGradleAsync (/Users/roseline/projects/sample-error-expo/node_modules/@expo/cli/build/src/start/platforms/android/gradle.js:72:46)
    at Object.assembleAsync (/Users/roseline/projects/sample-error-expo/node_modules/@expo/cli/build/src/start/platforms/android/gradle.js:52:18)
    at runAndroidAsync (/Users/roseline/projects/sample-error-expo/node_modules/@expo/cli/build/src/run/android/runAndroidAsync.js:36:24)
Waiting for the de

My development environment

  • Node.js: 18.17.0
  • Cocoapods: 1.15.2
  • ruby: ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [arm64-darwin22]

If you have more questions about the development environment, feel free to ask.

What platform(s) does this occur on?

No response

SDK Version

50.0.7

Environment

Env in sample project

expo-env-info 1.2.0 environment info:
    System:
      OS: macOS 13.5
      Shell: 5.9 - /bin/zsh
    Binaries:
      Node: 18.10.0 - ~/.nvm/versions/node/v18.10.0/bin/node
      Yarn: 1.22.19 - ~/.nvm/versions/node/v18.10.0/bin/yarn
      npm: 8.19.2 - ~/.nvm/versions/node/v18.10.0/bin/npm
    Managers:
      CocoaPods: 1.15.0 - /opt/homebrew/bin/pod
    SDKs:
      iOS SDK:
        Platforms: DriverKit 23.0, iOS 17.0, macOS 14.0, tvOS 17.0, watchOS 10.0
      Android SDK:
        API Levels: 28, 33, 34
        Build Tools: 30.0.3, 34.0.0
        System Images: android-34 | Google APIs ARM 64 v8a
    IDEs:
      Android Studio: 2022.3 AI-223.8836.35.2231.10811636
      Xcode: 15.0.1/15A507 - /usr/bin/xcodebuild

Env in real project

  expo-env-info 1.2.0 environment info:
    System:
      OS: macOS 13.5
      Shell: 5.9 - /bin/zsh
    Binaries:
      Node: 18.17.0 - ~/.nvm/versions/node/v18.17.0/bin/node
      Yarn: 1.22.19 - ~/.nvm/versions/node/v18.10.0/bin/yarn
      npm: 9.6.7 - ~/.nvm/versions/node/v18.17.0/bin/npm
    Managers:
      CocoaPods: 1.15.0 - /opt/homebrew/bin/pod
    SDKs:
      iOS SDK:
        Platforms: DriverKit 23.0, iOS 17.0, macOS 14.0, tvOS 17.0, watchOS 10.0
      Android SDK:
        API Levels: 28, 33, 34
        Build Tools: 30.0.3, 34.0.0
        System Images: android-34 | Google APIs ARM 64 v8a
    IDEs:
      Android Studio: 2022.3 AI-223.8836.35.2231.10811636
      Xcode: 15.0.1/15A507 - /usr/bin/xcodebuild
    npmGlobalPackages:
      eas-cli: 7.3.0

Minimal reproducible example

This is my github repo for reproducing these errors.

https://github.com/roseline124/sample-error-expo

I searched stack overflows, and asked to chat-gpt4 spending many hours. But, nothing can solve this issue.

for exmaple, npm audit fix is not working, and Installing @react-native-community/cli-platform-ios is not working... I've almost tried all of solutions in internet.

1

There are 1 best solutions below

0
roseline On

I solved it by formatting my computer and resetting my environment.