expo: Cannot build Android from Android Studio

Summary

I was trying to build the app from android studio to check the logcat but while syncing to project with Gradle. The operation failed. for these lines:

  • Where: Build file ‘/Users/b0iq/Developer/production/PROJECT/****/node_modules/expo-dev-launcher/android/build.gradle’ line: 178

  • What went wrong: A problem occurred evaluating project ‘:expo-dev-launcher’.

Cannot invoke method multiply() on null object

 static def versionToNumber(major, minor, patch) {
   return patch * 100 + minor * 10000 + major * 1000000
}

Managed or bare workflow? If you have made manual changes inside of the ios/ or android/ directories in your project, the answer is bare!

bare

What platform(s) does this occur on?

Android

Package versions

    "expo": "^45.0.5",
    "expo-blur": "~11.1.0",
    "expo-constants": "~13.1.1",
    "expo-dev-client": "~1.0.0",
    "expo-file-system": "~14.0.0",
    "expo-intent-launcher": "~10.2.0",
    "expo-linear-gradient": "~11.3.0",
    "expo-linking": "~3.1.0",
    "expo-location": "~14.2.2",
    "expo-random": "~12.2.0",
    "expo-sms": "~10.2.0",
    "expo-splash-screen": "~0.15.1",
    "expo-status-bar": "~1.3.0",
    "expo-system-ui": "~1.2.0",
    "expo-updates": "~0.13.2",

Environment

expo-env-info 1.0.3 environment info:
    System:
      OS: macOS 12.4
      Shell: 5.8.1 - /bin/zsh
    Binaries:
      Node: 16.15.0 - ~/.asdf/installs/nodejs/lts/bin/node
      Yarn: 1.22.15 - ~/.asdf/installs/nodejs/lts/.npm/bin/yarn
      npm: 8.11.0 - ~/.asdf/plugins/nodejs/shims/npm
      Watchman: 2022.05.23.00 - /opt/homebrew/bin/watchman
    Managers:
      CocoaPods: 1.11.3 - /Users/b0iq/.asdf/shims/pod
    SDKs:
      iOS SDK:
        Platforms: DriverKit 21.4, iOS 15.5, macOS 12.3, tvOS 15.4, watchOS 8.5
    IDEs:
      Android Studio: 2021.2 AI-212.5712.43.2112.8609683
      Xcode: 13.4/13F17a - /usr/bin/xcodebuild
    npmPackages:
      expo: ^45.0.5 => 45.0.5 
      react: 17.0.2 => 17.0.2 
      react-dom: 17.0.2 => 17.0.2 
      react-native: 0.68.2 => 0.68.2 
      react-native-web: 0.17.7 => 0.17.7 
    npmGlobalPackages:
      eas-cli: 0.53.0
      expo-cli: 5.4.9
    Expo Workflow: bare

Reproducible demo

N/A

Stacktrace (if a crash is involved)

  • Exception is: org.gradle.api.GradleScriptException: A problem occurred evaluating project ‘:expo-dev-launcher’. at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:93) at …

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 24 (5 by maintainers)

Most upvoted comments

@brentvatne @mthomps4 Got it fixed! 🚀

The problem was from JAVA version.

What I did is the following:

  1. I use asdf to control JAVA version
  2. install java plugin for asdf
  3. run asdf install java zulu-11.56.19
  4. run asdf global java zulu-11.56.19
  5. Go to Preferences > Build, Execution, Deployment > Build Tools > Gradle > Gradle JDK
  6. Change it to azul-11

Enjoy!

Surprise! this broke again, nothing to do with my zsh environment installation. Still looking into the issue.

In my case it seems to be a problem on how I installed asdf (via brew) and how I linked brew shell setup file.

After a lot of debugging, I found out that node was not being found inside the gradle script. At first I thought it was purely asdf fault but everything was correctly linked.

Then I remembered I installed asdf via brew by default it gives the command to append the env shell script to .zprofile which executes only for login terminal sessions, which I guess the groovy script is not.

The solution that seems to be working is to move the shell script (I deleted .zprofile file) from ~/.zprofile and place it into ~/.zshrc (which executes for all interactive terminal sessions).

# on ~/.zshrc you should have this
eval "$(/opt/homebrew/bin/brew shellenv)"

It will correctly link asdf and by extension node and other artifacts. At least for now, that seems to be working. Just to be extra careful I also linked nodejs globally.

asdf global nodejs 16.19.0

Executing commands from your terminal will give the correct output, but the shell env you execute within the gradle/groovy code might not have the same shell env.

To the expo team: clearly, a complicated setup but some error handling should be there since directly executing node commands can be tricky depending on asdf, volta, nvm, or w/e crazy setup ppl use out there.

@b0iq I solved it by ‘un-hoisting’ the expo package

Can you run node -e console.log(require('react-native/package.json').version) in your expo folder? (forex inside node_modules/expo)?

If you get an error - which I did - your problem might be same as myself. unhoist the expo package or maybe hoist the react-native package, I have no 100% conclusion on the solution but hope what fixed my issue will fix yours, otherwise this comment is useless and pls ignore it

In a different context, I ran into this recently, and fixed it four times.

Assuming the project root is the current working directory, three times, I fixed it with:

watchman watch-del-all && yarn cache clean && (cd android && ./gradlew --stop) && rm -rf android/build android/.gradle $TMPDIR/react-* $TMPDIR/metro-* $TMPDIR/haste-map-* ~/.npm/_npx ~/.gradle/caches/ && (cd android && ./gradlew clean)

And the final time, I fixed it with: (cd android && ./gradlew --stop)

I think the second command is all that’s required but I want to get back to coding so I haven’t researched further.

I think it has to do with failed in-memory cache invalidation.

Context: I was developing on Ubuntu 20.04 for react-native 0.71.2 using expo-48-beta, node v18.14.0, and openjdk 11.0.18 2023-01-17. I haven’t figured out the minimum steps to reproduce but some combination of npx react-native run-android && npx react-native start and npx expo start before either switching projects or changing the native dependencies and running npx react-native run-android && npx react-native start for the other/modified project seems to trigger this pretty reliably. When the error was triggering, running either (cd android && ./gradlew clean) or (cd android && ./gradlew app:installDebug -PreactNativeDevServerPort=8081) would also trigger the same error. I also got this error both in my own project and in the bare minimum template. Modifying getRNVersion showed that nodeModulesVersion was null even though manually running node -e "console.log(require('react-native/package.json').version);" in both the project directory and in node_modules/expo yielded 0.71.2 as expected. Modifying versionToNumber to return 2 * 100 + 71 * 10000 + 0 * 1000000 resulted in other errors that I didn’t end up researching. I’m also unfamiliar with groovy so take that with a grain of salt.

I think this is related to #18129.

Uninstalling asdf does fix this issue for me 😢

@altarrok How did you un-hoisting it?

➜  expo git:(main) ✗ node -e console.log(require('react-native/package.json').version) 
zsh: bad pattern: console.log(require(react-native/package.json).version)
➜  expo git:(main) ✗ node -e console.log(require("react-native/package.json").version) 
zsh: bad pattern: console.log(require(react-native/package.json).version)
➜  expo git:(main) ✗ node -e console.log(require(\"react-native/package.json\").version) 
zsh: bad pattern: console.log(require("react-native/package.json").version)

but when I ran:

➜  base-app git:(main) ✗ node -e "console.log(require('react-native/package.json').version);"
0.68.2