Software⏱️ 2 min read📅 2026-05-30

How to Fix: How to pass Gradle --offline flag from npm run dev gradle-offline in React Native run-android

Learn how to fix: How to pass Gradle --offline flag from npm run dev gradle-offline in React Native run-android.

Quick Answer: Try checking your system settings or restarting.

To pass the Gradle --offline flag from npm run dev gradle-offline in React Native run-android, you can modify your custom dev.js script to include the following line:

⚠️ Solution

  • Modify your dev.js script to include the following line:

Updated dev.js Script

const { spawn } = require('child_process'); const os = require('os'); const isGradleOffline = process.argv.includes('gradle-offline'); if (os.type() === 'Linux' || os.type() === 'Darwin') { const command = `ENVFILE=/envs/.env.dev react-native run-android --offline`; spawn(command, { shell: true }); } else if (os.platform() === 'win32') { const command = `ENVFILE=/envs/.env.dev react-native run-android -o`; spawn(command, { shell: true }); } 

🔧 Explanation

The updated script checks the operating system and passes the Gradle --offline flag accordingly. On Linux or macOS, it uses the --offline flag directly. On Windows, it uses the equivalent flag -o. This ensures that the Gradle build process runs in offline mode regardless of the platform.

✨ Example Use Case

To test the updated script, run:

npm run dev gradle-offline

This will build your React Native Android app in offline mode using Gradle.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions