mrousavy / react-native-mmkv

⚡️ The fastest key/value storage for React Native. ~30x faster than AsyncStorage!
https://mrousavy.com
MIT License
6.07k stars 257 forks source link

React-Native Android build is failing with error - Task :react-native-mmkv:prepareBoost FAILED #617

Closed gangadharuseline closed 9 months ago

gangadharuseline commented 10 months ago

I am trying to run npx react-native run-android The build is failing with the below error, PFA screenshot

Screenshot 2024-01-02 at 1 07 02 AM

Below is the some of the log

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':react-native-mmkv:prepareBoost'.
> Could not read /Users/gangadhar/Documents/Workspaces/Useline/beem-app/node_modules/react-native-mmkv/android/build/downloads/boost_1_76_0.tar.gz.
   > Not in GZIP format

* 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 1m 7s

    at makeError (/Users/gangadhar/Documents/Workspaces/Useline/beem-app/node_modules/execa/index.js:174:9)
    at /Users/gangadhar/Documents/Workspaces/Useline/beem-app/node_modules/execa/index.js:278:16
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async runOnAllDevices (/Users/gangadhar/Documents/Workspaces/Useline/beem-app/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/runOnAllDevices.js:109:5)
    at async Command.handleAction (/Users/gangadhar/Documents/Workspaces/Useline/beem-app/node_modules/@react-native-community/cli/build/index.js:192:9)
info Run CLI with --verbose flag for more details.

Here are Our App's few package.json versions are

"react": "18.0.0",
"react-native": "0.69.12",
"react-native-mmkv": "2.5.1",

Note: IOS app works fine.

Can you please help us here

deepanshu-sharma09 commented 9 months ago

Have you been able to resolve this??

Execution failed for task ':react-native-mmkv:prepareBoost'.
> Could not read /.../App/node_modules/react-native-mmkv/android/build/downloads/boost_1_76_0.tar.gz.
   > Not in GZIP format
Kavahardik commented 9 months ago

Execution failed for task ':react-native-mmkv:prepareBoost'.

Could not read /Users/peer/Documents/V3.1/Dipon/DiponMerchant/node_modules/react-native-mmkv/android/build/downloads/boost_1_76_0.tar.gz. Not in GZIP format

Facing same issue.

builam66 commented 9 months ago

try remove node_modules, reinstall and https://github.com/mrousavy/react-native-vision-camera/issues/1489#issuecomment-1451317732

gangadharuseline commented 9 months ago

@deepanshu-ample @Kavahardik Yes, The issue was fixed to me.

What i did is, Actually I use nvm to manage my node, Earlier I am using the node version => v16.20.2 Now I had installed latest node lts version i.e v20.10.0 After pointing to node version => v20.10.0 - I am not seeing the above prepareBoost issue our app runs successfully

ajay-mandaviya commented 9 months ago

Facing same issue : "react": "18.1.0", "react-native": "0.70.6", "react-native-mmkv": "2.5.1", node version: v20.6.1 `* What went wrong: Execution failed for task ':react-native-mmkv:prepareBoost'.

Could not read /Project-path/node_modules/react-native-mmkv/android/build/downloads/boost_1_76_0.tar.gz. Not in GZIP format` Getting same error in react-native-reanimated

ajay-mandaviya commented 9 months ago

@deepanshu-ample @Kavahardik

Yes, The issue was fixed to me. What i did is, Actually I use nvm to manage my node, Earlier I am using the node version => v16.20.2 Now I had installed latest node lts version i.e v20.10.0 After pointing to node version => v20.10.0 - I am not seeing the above prepareBoost issue our app runs successfully

Updating node version to v20.10.0 run successfully ✅ 🚀

deepanshu-sharma09 commented 9 months ago

For developers using older versions of Realm (https://github.com/realm/realm-js/issues/5136), consider utilizing Node version v18.19.0.

anirudh-antino commented 9 months ago

@gangadharuseline You can download boost_1_76_0.tar.gz file from here https://source.ipfire.org/source-2.x/ In your case you can download it via this link: https://source.ipfire.org/source-2.x/boost_1_76_0.tar.gz

then just copy it to App/node_modules/react-native-mmkv/android/build/downloads/boost_1_76_0.tar.gz and build your app.

Note: you need to do this every time you run yarn or npm. I usually do this since since it downloads this file every time and it is very slow to download.

brianwestphal commented 9 months ago

See similar https://github.com/software-mansion/react-native-reanimated/issues/5542

Raised https://github.com/boostorg/boost/issues/849

vasudhakorva commented 9 months ago

@deepanshu-ample @Kavahardik

Yes, The issue was fixed to me. What i did is, Actually I use nvm to manage my node, Earlier I am using the node version => v16.20.2 Now I had installed latest node lts version i.e v20.10.0 After pointing to node version => v20.10.0 - I am not seeing the above prepareBoost issue our app runs successfully

Updating node version to v20.10.0 run successfully ✅ 🚀

We are facing the same issue . In which file did u add the node version

alexanderhodes commented 9 months ago

The problem that you're facing is related to the general problem in the React Native Community regarding the broken download url from JFrog. The React Native team is already working on a solution for it. You can follow the complete progress in this issue.

A temporary fix that worked on my build have been these steps:

  1. Install patch-package
npm install --save-dev patch-package postinstall-postinstall
  1. Modify build.gradle

You can find this file locally on your machine here: node_modules/react-native-mmkv/android/build.gradle

Change this line:

task downloadBoost(dependsOn: createNativeDepsDirectories, type: Download) {
  def transformedVersion = BOOST_VERSION.replace("_", ".")

  // change this line
  def srcUrl = "https://boostorg.jfrog.io/artifactory/main/release/${transformedVersion}/source/boost_${BOOST_VERSION}.tar.gz"
  // to this
  def srcUrl = "https://archives.boost.io/release/${transformedVersion}/source/boost_${BOOST_VERSION}.tar.gz"
  if (REACT_NATIVE_VERSION < 69) {
    srcUrl = "https://github.com/react-native-community/boost-for-react-native/releases/download/v${transformedVersion}-0/boost_${BOOST_VERSION}.tar.gz"
  }
  src(srcUrl)
  onlyIfNewer(true)
  overwrite(false)
  dest(boost_file)
}
  1. Create patch

You need to run npx patch-package react-native-mmkv to create the patch which will be applied. This will generate a patch file in the patches/ folder in your project.

  1. Add postinstall script to package.json

You need to app the following script into your package.json

"scripts": {
     "postinstall": "patch-package"
}

Afterwards, you can commit all files. This should fix your broken build. These changes will be applied automacially in your CI/ CD pipeline as well. There's no need to change this on every commit or push.

The steps are inspired by this post

retyui commented 9 months ago

patch-package patch

diff --git a/node_modules/react-native-mmkv/android/build.gradle b/node_modules/react-native-mmkv/android/build.gradle
index 13eae76..bc8dc83 100644
--- a/node_modules/react-native-mmkv/android/build.gradle
+++ b/node_modules/react-native-mmkv/android/build.gradle
@@ -204,7 +204,7 @@ task createNativeDepsDirectories {

 task downloadBoost(dependsOn: createNativeDepsDirectories, type: Download) {
   def transformedVersion = BOOST_VERSION.replace("_", ".")
-  def srcUrl = "https://boostorg.jfrog.io/artifactory/main/release/${transformedVersion}/source/boost_${BOOST_VERSION}.tar.gz"
+  def srcUrl = "https://archives.boost.io/release/${transformedVersion}/source/boost_${BOOST_VERSION}.tar.gz"
   if (REACT_NATIVE_VERSION < 69) {
     srcUrl = "https://github.com/react-native-community/boost-for-react-native/releases/download/v${transformedVersion}-0/boost_${BOOST_VERSION}.tar.gz"
   }
mrousavy commented 9 months ago

Instead of creating patches as comments, could you maybe create a PR so I can merge this upstream? Thanks

mrousavy commented 9 months ago

the latest MMKV version (2.11) does not have this issue.