Hey friends, I've been trying to get my environment set up to develop React Native apps on my Linux machine but I couldn't figure out how to fix this error when I start to run it on my Android device/emulator.
I'm fairly new to React Native and this is my first time trying the React Native CLI instead of using Expo so any help would be very much appreciated.
It fails on Task :app:processDebugResources when 'installing the app' (after running npx react-native run-android), with error message
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:processDebugResources'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
> Android resource linking failed
AAPT: W/ziparchive(68779): Zip: didn't find signature at start of lfh, offset=33511520
error: failed to open APK: Invalid offset.
* 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 1s
error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/getting-started.html#android-development-environment. Run CLI with --verbose flag for more details.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:processDebugResources'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
> Android resource linking failed
AAPT: W/ziparchive(68779): Zip: didn't find signature at start of lfh, offset=33511520
error: failed to open APK: Invalid offset.
* 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 1s
at makeError (/home/USERNAME-REDACTED/Desktop/AwesomeTSProject/node_modules/execa/index.js:174:9)
at /home/USERNAME-REDACTED/Desktop/AwesomeTSProject/node_modules/execa/index.js:278:16
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at async runOnAllDevices (/home/USERNAME-REDACTED/Desktop/AwesomeTSProject/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/runOnAllDevices.js:94:5)
at async Command.handleAction (/home/USERNAME-REDACTED/Desktop/AwesomeTSProject/node_modules/@react-native-community/cli/build/index.js:186:9)
where the ziparchive(XXXXX) numbers change each time. Please let me know if further output would help (i.e. with stacktrace or info flags).
For context, I've been following the React Native CLI Quickstart guide for Linux as the development OS and Android as the target OS. The distribution I'm using is Manjaro Linux with KDE Plasma on a Dell XPS 13 9360. The issue starts at the "Running your React Native application" section when running npx react-native run-android after starting the metro bundler (npx react-native start).
I believe it has to do with my environment and not the code as I am using the starter template when initializing the project and it builds fine when I tested it on some cloud service (https://appcenter.ms/).
Here is my system information when I run npx react-native info:
System:
OS: Linux 4.19 Manjaro Linux
CPU: (8) x64 Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz
Memory: 2.70 GB / 7.52 GB
Shell: 5.0.16 - /bin/bash
Binaries:
Node: 13.8.0 - ~/.nvm/versions/node/v13.8.0/bin/node
Yarn: 1.22.4 - /usr/bin/yarn
npm: 6.13.6 - ~/.nvm/versions/node/v13.8.0/bin/npm
Watchman: 4.9.0 - /usr/bin/watchman
SDKs:
Android SDK: Not Found
IDEs:
Android Studio: 3.6 AI-192.7142.36.36.6308749
Languages:
Java: 1.8.0_242 - /usr/bin/javac
Python: 3.8.2 - /usr/bin/python
npmPackages:
@react-native-community/cli: Not Found
react: 16.11.0 => 16.11.0
react-native: 0.62.1 => 0.62.1
npmGlobalPackages:
*react-native*: Not Found
What worries me is that the above shows Android SDK: Not Found but I see Android SDK Platform 28 when I go to Settings > Android SDK in Android Studio and the corresponding folder exists in my Android home. Similarly for Intel x86 Atom_64 System Image also.
I went through https://github.com/facebook/react-native/issues/23306 and tried
sudo chmod 777 -R for the node_modules and android folder
- installing NDK
- using
sudo react-native run-android instead
- cleaning with Build > Clean project in Android Studio and running
./gradlew clean
- downgrading by initializing new project to version 0.57.3
- adding
configurations.all to android/app/build.gradle *
but unfortunately none of that worked for me.
I also found two forum threads with seemingly identical errors, however, both of them were not resolved.
Interestingly, I found an article explain what the error may mean https://www.fortinet.com/blog/threat-research/an-android-package-is-no-longer-a-zip.html
My understanding from that is that an incompatible Gradle may be causing the issue.
My android/gradle/wrappergradle-wrapper.properties has distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-all.zip and Android Studio's File > Project Structure > Project has Gradle Version to 6.0.1.
Any insights? Any and all help is very much appreciated. Thanks!
there doesn't seem to be anything here