expo: [Expo 42] Bare app build failing

Edit Due to a mix of different underlying causes, we have locked this issue. Please read through this comment to find out how you can resolve this issue.


Summary

Android app fails to build on Task :unimodules-react-native-adapter:compileDebugJavaWithJavac

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

bare

What platform(s) does this occur on?

Android

SDK Version (managed workflow only)

No response

Environment

Expo CLI 4.7.2 environment info: System: OS: Windows 10 10.0.19043 Binaries: Node: 14.17.1 - C:\Program Files\nodejs\node.EXE Yarn: 1.22.5 - C:\Program Files (x86)\Yarn\bin\yarn.CMD npm: 6.14.13 - C:\Program Files\nodejs\npm.CMD SDKs: Android SDK: API Levels: 26, 29, 30 Build Tools: 29.0.2, 30.0.3 System Images: android-28 | Google Play Intel x86 Atom, android-30 | Google APIs Intel x86 Atom, android-S | Google Play Intel x86 Atom_64 IDEs: Android Studio: Version 4.2.0.0 AI-202.7660.26.42.7351085 npmPackages: expo: ~42.0.0 => 42.0.0 react: 16.13.1 => 16.13.1 react-dom: 16.13.1 => 16.13.1 react-native: ~0.63.4 => 0.63.4 react-native-web: ~0.13.12 => 0.13.18 Expo Workflow: bare

Reproducible demo or steps to reproduce from a blank project

Initialize a new Expo Bare App Setup typescript (only creating the tsconfig.json and installing the deps when prompted by expo start) Add eslint (config universe/native and the plugin simple-import-sort) Try to yarn android and it shoud fail on the task mentioned above

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 30 (8 by maintainers)

Most upvoted comments

Make sure to clean your cache, not only yarn or npm’s cache but also the gradle cache. To double-check the fix, I created this repository that contains two workflows. It creates a new project on the fly, changes the @unimodules/react-native-adapter version, and tries to build it. You can see the result for Windows, MacOS, and Ubuntu running before and after the released fix.

I still ran into error when trying a similar workflow on a local MacOS machine /.gradlew assembleDebug

node:internal/modules/cjs/loader:930
  throw err;
  ^

Error: Cannot find module 'expo-modules-autolinking'
Require stack:
- /Users/user/.gradle/daemon/6.8/[eval]
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:927:15)
    at Function.Module._load (node:internal/modules/cjs/loader:772:27)
    at Module.require (node:internal/modules/cjs/loader:999:19)
    at require (node:internal/modules/cjs/helpers:93:18)
    at [eval]:1:1
    at Script.runInThisContext (node:vm:129:12)
    at Object.runInThisContext (node:vm:305:38)
    at node:internal/process/execution:81:19
    at [eval]-wrapper:6:22
    at evalScript (node:internal/process/execution:80:60) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '/Users/user/.gradle/daemon/6.8/[eval]' ]
}
> Task :unimodules-react-native-adapter:compileDebugJavaWithJavac FAILED
/Users/user/Workspace/ExpoIssue13475Fix/node_modules/@unimodules/react-native-adapter/android/src/main/java/org/unimodules/adapters/react/ModuleRegistryAdapter.java:26: error: cannot find symbol
   mModuleRegistryProvider = new ReactModuleRegistryProvider(new ExpoModulesPackageList().getPackageList(), null);
                                                                 ^
 symbol:   class ExpoModulesPackageList
 location: class ModuleRegistryAdapter
1 error

FAILURE: Build failed with an exception.

Steps I followed:

1. Run expo init ExpoIssue13475Fix --template expo-template-bare-minimum@42
2. Add "resolutions": { "@unimodules/react-native-adapter": "6.3.2" } to package.json
3. Run yarn install
4. Run ./gradlew assembleDebug at Android folder

yarn why @unimodules/react-native-adapter

=> Found "@unimodules/react-native-adapter@6.3.2"
info Reasons this module exists
   - "expo" depends on it
   - Hoisted from "expo#@unimodules#react-native-adapter"
   - Hoisted from "react-native-unimodules#@unimodules#react-native-adapter"
info Disk size without dependencies: "3.02MB"
info Disk size with unique dependencies: "3.7MB"
info Disk size with transitive dependencies: "9.26MB"
info Number of shared dependencies: 44

Machine info

Macbook Air M1
nodejs v16.4.2. (arm64)
java 1.8 (arm64)
Android SDK 29.0.3

I finally made it work by the following steps, it will help anyone who come across this. Thanks for everyone advice!

1. Set gradle version to 6.9
2. Remove .gradle folder under android
3. Clean && compile again
  1. Upgraded Node to v14.17.3
  2. Upgraded Gradle to 6.9
  3. Removed .gradle folder
  4. Cleared all npm and react native caches
  5. Clean and Rebuild

Unfortunately, its still failing. Getting this below error.

Screenshot 2021-07-08 at 9 45 07 AM

Hey all! I’m sorry for this issue and I can confirm this happens on Windows. I created a patch to fix this, I hope we can roll this out asap. If you absolutely need this to work, including on CI, you can work with patch-package until it is released.

You’ll need to create a file in patches/@unimodules+react-native-adapter+6.3.1.patch, with this content:

diff --git a/node_modules/@unimodules/react-native-adapter/scripts/autolinking.gradle b/node_modules/@unimodules/react-native-adapter/scripts/autolinking.gradle
index aedcef3..1e5903e 100644
--- a/node_modules/@unimodules/react-native-adapter/scripts/autolinking.gradle
+++ b/node_modules/@unimodules/react-native-adapter/scripts/autolinking.gradle
@@ -94,7 +94,7 @@ class ExpoAutolinkingManager {
     String[] args = [
       'node',
       '--eval',
-      'require("expo-modules-autolinking")(process.argv.slice(1))',
+      'require(\'expo-modules-autolinking\')(process.argv.slice(1))',
       '--',
       command,
       '--platform',

Here is a short guide to set that up:

  1. Install patch-package as dev dependency yarn add --dev patch-package
  2. Add the postinstall hook to your package.json "scripts": { "postinstall": "patch-package" }
  3. Create folder patches mkdir patches
  4. Copy over the contents from above into: patches/@unimodules+react-native-adapter+6.3.1.patch
  5. Run yarn to apply the patch

If you commit the patch and changes in your package.json, this is applied in CI, classic build, and on EAS.

Hope this helps!

I knew this was happening. Solved it one hour after updating my unimodules. Tried to make a pull request, but too much burocracy.

at node_modules/@unimodules/react-native-adapter/scripts/autolinking.gradle , at line 97:

'require("expo-modules-autolinking")(process.argv.slice(1))',

switch the quotes like this:

"require('expo-modules-autolinking')(process.argv.slice(1))",

I’ve also made the changes mentioned in this commit about the unimodules implementation, but I don’t know if this is needed for it to build, since I’ve found out the solution above later:

[ios][android] New autolinking implementation in TypeScript (#11593)

I guess it is the undocumented “new way” to implement unimodules?

oh yep I missed that…🙉

Are there any more details on the build failure? I was having an issue specifically with symbol not found ExpoModulesPackageList and it turns out that expo-modules-autolinking requires Node 14. I was on Node 12 and it’s fixed it by updating to 14.

I can confirm that it’s still a problem. Similar configuration as @kalvin807

  • @unimodules/react-native-adapter@6.3.2
  • node v14.17.0
  • Macbookpro M1
  • cleared all the caches

Update: Tried it now on another Mac, cloned the project anew and the build fails with the same error.

Patch has been released! Please use @unimodules/react-native-adapter@6.3.2 (latest). If you want to check your local version:

  • $ yarn why @unimodules/react-native-adapter
  • $ npm list @unimodules/react-native-adapter

It should be installed automatically, but if it doesn’t make sure to regenerate your lockfile.

Make sure to clean your cache, not only yarn or npm’s cache but also the gradle cache. To double-check the fix, I created this repository that contains two workflows. It creates a new project on the fly, changes the @unimodules/react-native-adapter version, and tries to build it. You can see the result for Windows, MacOS, and Ubuntu running before and after the released fix.

I still ran into error when trying a similar workflow on a local MacOS machine

/.gradlew assembleDebug

node:internal/modules/cjs/loader:930
  throw err;
  ^

Error: Cannot find module 'expo-modules-autolinking'
Require stack:
- /Users/user/.gradle/daemon/6.8/[eval]
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:927:15)
    at Function.Module._load (node:internal/modules/cjs/loader:772:27)
    at Module.require (node:internal/modules/cjs/loader:999:19)
    at require (node:internal/modules/cjs/helpers:93:18)
    at [eval]:1:1
    at Script.runInThisContext (node:vm:129:12)
    at Object.runInThisContext (node:vm:305:38)
    at node:internal/process/execution:81:19
    at [eval]-wrapper:6:22
    at evalScript (node:internal/process/execution:80:60) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '/Users/user/.gradle/daemon/6.8/[eval]' ]
}
> Task :unimodules-react-native-adapter:compileDebugJavaWithJavac FAILED
/Users/user/Workspace/ExpoIssue13475Fix/node_modules/@unimodules/react-native-adapter/android/src/main/java/org/unimodules/adapters/react/ModuleRegistryAdapter.java:26: error: cannot find symbol
   mModuleRegistryProvider = new ReactModuleRegistryProvider(new ExpoModulesPackageList().getPackageList(), null);
                                                                 ^
 symbol:   class ExpoModulesPackageList
 location: class ModuleRegistryAdapter
1 error

FAILURE: Build failed with an exception.

Steps I followed:

1. Run expo init ExpoIssue13475Fix --template expo-template-bare-minimum@42
2. Add "resolutions": { "@unimodules/react-native-adapter": "6.3.2" } to package.json
3. Run yarn install
4. Run ./gradlew assembleDebug at Android folder

yarn why @unimodules/react-native-adapter

=> Found "@unimodules/react-native-adapter@6.3.2"
info Reasons this module exists
   - "expo" depends on it
   - Hoisted from "expo#@unimodules#react-native-adapter"
   - Hoisted from "react-native-unimodules#@unimodules#react-native-adapter"
info Disk size without dependencies: "3.02MB"
info Disk size with unique dependencies: "3.7MB"
info Disk size with transitive dependencies: "9.26MB"
info Number of shared dependencies: 44

Machine info

Macbook Air M1
nodejs v16.4.2. (arm64)
java 1.8 (arm64)
Android SDK 29.0.3

I finally made it work by the following steps, it will help anyone who come across this. Thanks for everyone advice!

1. Set gradle version to 6.9
2. Remove .gradle folder under android
3. Clean && compile again

I think something is up with the dependencies in your project here. This error is slightly different from the original one and is not related to the fix we just sent out.

  • The original error is ReferenceError: expo is not defined, which is a result of the missing quotes on Windows.
  • Your error is Error: Cannot find module 'expo-modules-autolinking'. This might be caused by using a slightly older version of some dependency that doesn’t include expo-modules-autolinking.

If you are using SDK 42, and have upgraded from an older version, you can try running expo upgrade again to validate the used dependencies. This might not catch everything, after that I would also double-check the versions manually using this list of dependencies with their versions. Your used dependencies should match the exact versions of that list.

Edit: As someone else pointed out, also make sure to run Node 14 (the current LTS) or higher (using even numbers)

Hope this helps!

Running expo upgrade does nothing, instead, it downgrades react-native-unimodules from 0.14.3 to 0.14.2 The lock file still shows "@unimodules/react-native-adapter" "~6.3.1" even after expo upgrade under react-native-unimodules@~0.14.3 and expo@^42.0.0: And of course the build is failing, you have more info in the log I posted yesterday

My yarn.lock file:

[...]
"@unimodules/react-native-adapter@~6.3.1":
  version "6.3.2"
  resolved "https://registry.yarnpkg.com/@unimodules/react-native-adapter/-/react-native-adapter-6.3.2.tgz#6dd549704d3fc7c729d657beff998f27a34f62a2"
  integrity sha512-jHrlGfIfs2GiPoDS6HttS5VZ4UmRSGiH1wArAJo7msAe0EACt6b9AR+CuxUPpK0d+DXv31iJzJxh9PYBzyA9Ag==
  dependencies:
    expo-modules-autolinking "^0.0.2"
    invariant "^2.2.4"
[...]
expo@^42.0.0:
  version "42.0.0"
  resolved "https://registry.yarnpkg.com/expo/-/expo-42.0.0.tgz#edf55d1bab197aa6e6883b4b593de2bb87f18e14"
  integrity sha512-m1/rPzh/Jgmy2Kx8I2wK7bjhMhwcp6oNJcYr3JqUphYYW4k+UgoKw/O5Dztt/Sy+vYAUH1tFAd+wLcMCmPUJbg==
  dependencies:
    "@babel/runtime" "^7.1.2"
    "@expo/metro-config" "^0.1.70"
    "@expo/vector-icons" "^12.0.4"
    "@unimodules/core" "~7.1.1"
    "@unimodules/react-native-adapter" "~6.3.1"
    babel-preset-expo "~8.4.0"
    cross-spawn "^6.0.5"
    expo-application "~3.2.0"
    expo-asset "~8.3.2"
    expo-constants "~11.0.1"
    expo-error-recovery "~2.2.0"
    expo-file-system "~11.1.3"
    expo-font "~9.2.1"
    expo-keep-awake "~9.2.0"
    fbemitter "^2.1.1"
    invariant "^2.2.2"
    md5-file "^3.2.3"
    pretty-format "^26.4.0"
    react-native-safe-area-context "3.2.0"
    serialize-error "^2.1.0"
    uuid "^3.4.0"
[...]
react-native-unimodules@~0.14.3:
  version "0.14.3"
  resolved "https://registry.yarnpkg.com/react-native-unimodules/-/react-native-unimodules-0.14.3.tgz#b84d050b554a790b9f79aeb534b8a8bbd27fbb2d"
  integrity sha512-FhAqztCacYvQwsx8FAOU+x3eywSFy3Tc9U86YovVWp86vz6066XU1SB/HPbAD+oiBJsB02yRPKxtYQT3CrOqnQ==
  dependencies:
    "@unimodules/core" "~7.1.1"
    "@unimodules/react-native-adapter" "~6.3.1"
    chalk "^2.4.2"
    expo-asset "~8.3.2"
    expo-constants "~11.0.1"
    expo-file-system "~11.1.3"
    expo-image-loader "~2.2.0"
    expo-modules-core "~0.2.0"
    find-up "~5.0.0"
    unimodules-app-loader "~2.2.0"
    unimodules-task-manager-interface "~6.2.0"

Manually changing those to “@unimodules/react-native-adapter” “~6.3.2” does nothing, build still fails on AppCenter CI

Upgrading node from v12 to v14 and applying that patch worked for me, thanks @valascus & @byCedric!