Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android build fails on createReleaseExpoManifest #8374

Closed
sbecker opened this issue May 20, 2020 · 27 comments
Closed

Android build fails on createReleaseExpoManifest #8374

sbecker opened this issue May 20, 2020 · 27 comments

Comments

@sbecker
Copy link

sbecker commented May 20, 2020

🐛 Bug Report

A brand new expo bare-minimum app fails to build for release on Android. It fails during the :app:createReleaseExpoManifest task, because it cannot connect to 127.0.0.1:8081

A workaround is to run react-native start in a separate terminal / process so that the Metro bundler is running. Build will succeed.

Environment

  Expo CLI 3.20.9 environment info:
    System:
      OS: macOS 10.15.4
      Shell: 3.2.57 - /bin/bash
    Binaries:
      Node: 12.16.2 - ~/.nvm/versions/node/v12.16.2/bin/node
      Yarn: 1.22.4 - ~/.nvm/versions/node/v12.16.2/bin/yarn
      npm: 6.14.4 - ~/.nvm/versions/node/v12.16.2/bin/npm
      Watchman: 4.9.0 - /usr/local/bin/watchman
    IDEs:
      Android Studio: 3.6 AI-192.7142.36.36.6392135
      Xcode: 11.4.1/11E503a - /usr/bin/xcodebuild
    npmGlobalPackages:
      expo-cli: 3.20.9

App target: Android

Steps to Reproduce

First, switch to recent node LTS (12.16.2), and install expo CLI and react-native CLI:

nvm use 12.16.2
npm i -g expo-cli
npm i -g react-native-cli

Then run the following commands to create a fresh bare minimum app and attempt to create an android bundle release:

expo init --template bare-minimum ExpoRNDebug
cd ExpoRNDebug
cd android
./gradlew bundleRelease

Expected Behavior

BUILD SUCCESSFUL

Actual Behavior

> Task :app:createReleaseExpoManifest FAILED
events.js:287
      throw er; // Unhandled 'error' event
      ^

Error: connect ECONNREFUSED 127.0.0.1:8081
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1141:16)
Emitted 'error' event on ClientRequest instance at:
    at Socket.socketErrorListener (_http_client.js:426:9)
    at Socket.emit (events.js:310:20)
    at emitErrorNT (internal/streams/destroy.js:92:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
    at processTicksAndRejections (internal/process/task_queues.js:84:21) {
  errno: 'ECONNREFUSED',
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 8081
}
w: Detected multiple Kotlin daemon sessions at build/kotlin/sessions

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:createReleaseExpoManifest'.
> Process 'command 'node'' finished with non-zero exit value 1

* 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

Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/5.6.3/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 2m 15s
430 actionable tasks: 430 executed

Workaround

Run react-native start in a separate terminal / process so that the Metro bundler is running. Build will succeed.

@brentvatne
Copy link
Member

hello! yeah, you need to have metro running when you do a release build. if you run react-native run-android or yarn android it will do this for you.

@dondragon2
Copy link

@brentvatne I am trying to have my builds automated with AppCenter. Currently AppCebter works fine with a regular react native app. But, with Expo bare it fails with the error above. how would we have metro running in this case or what would be a workaround in this case?

@esamelson
Copy link
Contributor

Hey @dondragon2 - we will add a clearer error message here but unfortunately, builds with expo-updates installed do currently require that the metro bundler server is running in another process. The templates from expo init have expo-updates preinstalled because we anticipate most users will want this functionality, but you can remove it if needed.

If you can customize how you start your build and/or have a separate process running in App Center, it shouldn't be a problem, but if not, you may need to uninstall expo-updates to get the build to run.

It's on our roadmap to get builds with expo-updates running without the need for a packager server. But that's unfortunately not the case right now 😞 Sorry for the trouble!

@dondragon2
Copy link

@esamelson Thanks for your input. What is the best way to remove expo-updates? The reason is that after I uninstall the module I notice there is some dependencies required in the android classes. If I remove this the app doesn't launch even those the package manager downloads the js files. How should I go about this?

@creimers
Copy link

I can confirm that appcenter builds work with expo-updates uninstalled.

@dondragon2
Copy link

@creimers do you mind sharing what changes, if any, you had to do in the MainActivity to get this working? Also, did you have to install unimodules?

@creimers
Copy link

@dondragon2 Sure. I followed the uninstall guide 100%. Other than that, I did not do anything.

Additional info: my project in question was bootstrapped with create react native app.

@dondragon2
Copy link

@creimers Thanks for the direction to look. I totally missed that when looking at this issue. I followed the guide and now it is working as expected. Thanks everyone

@Meansereirith
Copy link

Meansereirith commented May 26, 2020

@sbecker I have also encountered this problem. I solve this problem by updating my
expo-update@0.2.0 to expo-updates@0.2.5
expo-updates@0.2.5

@mashuk999
Copy link

Running a react-native start in another terminal fix the issue. Also make sure to run in Administrator, it will resolve most of problems

@shubhamdeol
Copy link

@brentvatne I have installed expo update. When trying to build the app I am getting this error.

 Failed to connect to the packager server. If you did not start this build by running 'react-native run-android', you can start the packager manually by running 'react-native start' in the project directory. (Error: connect ECONNREFUSED 127.0.0.1:8081)

If I run react-native start in another tab and than build the app it successfully builds. why my build is having a dependency on react-native start to create build now. Is this expected?

@mashuk999
Copy link

@brentvatne I have installed expo update. When trying to build the app I am getting this error.

 Failed to connect to the packager server. If you did not start this build by running 'react-native run-android', you can start the packager manually by running 'react-native start' in the project directory. (Error: connect ECONNREFUSED 127.0.0.1:8081)

If I run react-native start in another tab and than build the app it successfully builds. why my build is having a dependency on react-native start to create build now. Is this expected?

Yes. They are working very hard to make expo updates run without this but it will take some more time. Till then this is the only choice

@brentvatne
Copy link
Member

@shubhamdeol - i assume you're following the guide here? https://reactnative.dev/docs/signed-apk-android#generating-the-release-apk

i think that page should be updated to let users know that they need to have the react-native server running :) maybe you could open a PR to clarify that

@auseika
Copy link

auseika commented Jun 9, 2020

Ok, basically, I looks like I can't run a separate process with bundler when using Bitrise.
Any workarounds?

@webdevbyjoss
Copy link

just get rid of expo-updates as per uninstallation instructions here

@SleeplessByte
Copy link

SleeplessByte commented Jun 28, 2020

@shubhamdeol - i assume you're following the guide here? https://reactnative.dev/docs/signed-apk-android#generating-the-release-apk

i think that page should be updated to let users know that they need to have the react-native server running :) maybe you could open a PR to clarify that

yarn android
yarn run v1.21.1
$ react-native run-android

Goes onwards to build the app (for development)

At some point - I am going to assume this is windows related - the node.js (react native) is killed, most likely because a file is being editted by the build process, and when the dev build finishes, the bundler is dead.

Error: EPERM: operation not permitted, lstat 'path\to\android\app\build\generated\assets\react\release\index.android.bundle'
Emitted 'error' event on NodeWatcher instance at:
    at NodeWatcher.<anonymous> (path\to\node_modules\sane\src\node_watcher.js:291:16)
    at FSReqCallback.oncomplete (fs.js:175:21) {
  errno: -4048,
  code: 'EPERM',
  syscall: 'lstat',
  path: 'path\to\\android\\app\\build\\generated\\assets\\react\\release\\index.android.bundle'
}

(The above is what causes the bundler to die -- this issue has been present for longer).

⚠️ this has nothing to do with Admin rights, as in, you can't solve this by running cmd.exe or powershell in administrative mode. ⚠️

You can still "fix" this flow by just running react-native start after your app has started on the device. Kill the app on the devise and start it again.

Now the bundler runs, and you can do gradle bundleRelease.


When gradle bundleRelease kills the bundler (see above), quickly start it again. You usually have about ~1 minute to do this.

@brentvatne
Copy link
Member

this should be fixed in expo-updates@0.2.12, please let me know if the issue persists

@arberkryeziu
Copy link

arberkryeziu commented Jul 27, 2020

@brentvatne since 0.2.12 , I am required to have the "expo" in my dependencies. Otherwise, (on iOS) Im having "Error loading assets JSON from Metro. Ensure you've followed all expo-updates installation steps correctly. **Cannot find module 'expo/tools/hashAssetFiles**"
Is this intentional ?

@helsonxiao
Copy link

This problem is solved in latest version, but if you can't migrate smoothly, try launchctl service on macOS.

@helsonxiao
Copy link

helsonxiao commented Jul 28, 2020

@brentvatne since 0.2.12 , I am required to have the "expo" in my dependencies. Otherwise, (on iOS) Im having "Error loading assets JSON from Metro. Ensure you've followed all expo-updates installation steps correctly. **Cannot find module 'expo/tools/hashAssetFiles**"
Is this intentional ?

So am I... (I'm migrating from 0.2.7 to 0.2.8) Try this service description file on your CI machine.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
    "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.yourproject.packager</string>
    <key>ProgramArguments</key>
    <array>
        <string>bash</string>
        <string>-c</string>
        <string>${YOUR_PROJECT_HOME}/start-ci-packager.sh</string>
    </array>
    <key>RunAtLoad</key>
    <false/>
    <key>KeepAlive</key>
    <dict>
        <key>Crashed</key>
        <true/>
    </dict>
    <key>EnvironmentVariables</key>
    <dict>
        <key>PATH</key>
        <string>/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin</string>
        <key>YOUR_PROJECT_HOME</key>
        <string>/Users/helsonxiao/YourProject</string>
    </dict>
    <key>StandardErrorPath</key>
    <string>/tmp/com.yourproject.packager.err</string>
    <key>StandardOutPath</key>
    <string>/tmp/com.yourproject.packager.out</string>
</dict>
</plist>

start-ci-packager.sh

#!/bin/bash
export RCT_METRO_PORT="${RCT_METRO_PORT:=8081}"
export YOUR_PROJECT_HOME="${YOUR_PROJECT_HOME}"
echo "export RCT_METRO_PORT=${RCT_METRO_PORT}" > "${YOUR_PROJECT_HOME}/node_modules/react-native/scripts/.packager.env"

if [ ! -d "${YOUR_PROJECT_HOME}" ]; then
  echo "YOUR_PROJECT_HOME is required!"
  exit 1
fi

if [ -z "${RCT_NO_LAUNCH_PACKAGER+xxx}" ] ; then
  if nc -w 5 -z localhost ${RCT_METRO_PORT} ; then
    if ! curl -s "http://localhost:${RCT_METRO_PORT}/status" | grep -q "packager-status:running" ; then
      echo "Port ${RCT_METRO_PORT} already in use, packager is either not running or not running correctly"
      exit 2
    fi
  else
    cd ${YOUR_PROJECT_HOME} && npx react-native start || echo "Can't start packager automatically"
  fi
fi

@rodneyrehm
Copy link
Contributor

rodneyrehm commented Jul 29, 2020

same/similar problem here. I have expo-notifications installed. with expo-updates@0.2.11 it the iOS app builds fine, with expo-updates@0.2.12 I get

Error: Error loading assets JSON from Metro. 
Ensure you've followed all expo-updates installation steps correctly. 

src/SomeScreen.tsx: 
/…/ios/src/SomeScreen.tsx: 
Path '../../../assets/images/SomeImage.svg' could not be found for '/…/ios/src/SomeScreen.tsx'
    at /…/node_modules/expo-updates/scripts/createManifest.js:17:11
    at processTicksAndRejections (internal/process/task_queues.js:93:5)

Edit

Problem resolved with expo-updates@0.2.13

@brentvatne
Copy link
Member

brentvatne commented Jul 30, 2020

@arberK - can you help me to reproduce this? it works as expected on my machine. it would be best to do that in a new issue.

@rodneyrehm
Copy link
Contributor

rodneyrehm commented Jul 30, 2020

I've been debugging this with @brentvatne via slack.

I'm loading SVGs

import someSvg from '$assets/images/some.svg'

to pass to <SvgXml xml={someSvg} … />. We have the following in our babel.config.js:

{
  plugins: [
    ['babel-plugin-inline-import', {extensions: ['.svg']} ],
  ]
}

After removing all of the SVG imports the iOS build runs fine.

Edit

Problem resolved with expo-updates@0.2.13

@brentvatne
Copy link
Member

@rodneyrehm - i tried to reproduce this locally in a minimal example and it works for me: https://github.com/brentvatne/svg-example

@andrekovac
Copy link
Contributor

I also faced this issue after updating to expo-updates@0.2.12

Solution: Update to expo-updates@0.2.13 - This should really solve the issue!

@ryanbabbly
Copy link

Still fails on expo-updates@0.2.14 for me

@brentvatne
Copy link
Member

@ryanbabbly - please create a new issue with a mcve

@expo expo locked and limited conversation to collaborators Aug 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests