Search code examples
react-nativenpmexpobuild.gradlebuild-error

React Native w/ Expo: Strange Error When Using run:android


I am working on a simple app with react native (/expo). When I do something as simple as just the following 4 commands (in order on a Windows 11, Expo 51):

  1. npx create-expo-app Test --template (selected the Blank template; without Typescript)
  2. cd Test
  3. npm install
  4. npx expo run:android

I get the following output and error:

📝  Android package Learn more: https://expo.fyi/android-package

√ What would you like your Android package name to be? ... com.pmaddineedi.Test

√ Created native directory
√ Updated package.json
» android: userInterfaceStyle: Install expo-system-ui in your project to enable this feature.
√ Finished prebuild
› Building app...
Configuration on demand is an incubating feature.

FAILURE: Build failed with an exception.

* What went wrong:
Could not open settings generic class cache for settings file 'C:\Users\pmadd\Mobile Development\Audacity\Test\android\settings.gradle' (C:\Users\pmadd\.gradle\caches\8.6\scripts\9jvl7af6mie02hkplgyjc1nfd).
> BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_' Unsupported class file major version 66

* 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 758ms
Error: C:\Users\pmadd\Mobile Development\Audacity\Test\android\gradlew.bat app:assembleDebug -x lint -x test --configure-on-demand --build-cache -PreactNativeDevServerPort=8081 -PreactNativeArchitectures=x86_64,arm64-v8a exited with non-zero code: 1
Error: C:\Users\pmadd\Mobile Development\Audacity\Test\android\gradlew.bat app:assembleDebug -x lint -x test --configure-on-demand --build-cache -PreactNativeDevServerPort=8081 -PreactNativeArchitectures=x86_64,arm64-v8a exited with non-zero code: 1
    at ChildProcess.completionListener (C:\Users\pmadd\Mobile Development\Audacity\Test\node_modules\@expo\spawn-async\build\spawnAsync.js:42:23)
    at Object.onceWrapper (node:events:634:26)
    at ChildProcess.emit (node:events:519:28)
    at cp.emit (C:\Users\pmadd\Mobile Development\Audacity\Test\node_modules\cross-spawn\lib\enoent.js:34:29)
    at maybeClose (node:internal/child_process:1105:16)
    at ChildProcess._handle.onexit (node:internal/child_process:305:5)
    ...
    at spawnAsync (C:\Users\pmadd\Mobile Development\Audacity\Test\node_modules\@expo\spawn-async\build\spawnAsync.js:7:23)
    at spawnGradleAsync (C:\Users\pmadd\Mobile Development\Audacity\Test\node_modules\@expo\cli\build\src\start\platforms\android\gradle.js:96:48)
    at assembleAsync (C:\Users\pmadd\Mobile Development\Audacity\Test\node_modules\@expo\cli\build\src\start\platforms\android\gradle.js:74:18)
    at runAndroidAsync (C:\Users\pmadd\Mobile Development\Audacity\Test\node_modules\@expo\cli\build\src\run\android\runAndroidAsync.js:45:37)

However, npm start works perfectly well. How do I fix this?

Note that I have seen many solutions online to fix this issue, but none that I saw seem to work.

EDIT

I am using java jdk 20, since it seems like I need 17+ and 22 is too new


Solution

  • Using gradle init with the following input worked:

    Type of Project: Application (2)

    Implementation Language: Kotlin (4)

    Generate multiple subprojects for application: no

    Build Script DSL: Kotlin (1)

    Target Java Version: 20

    Generate build using new APIs and behavior: yes