Useful Native Commands for React Native Developers

If you’re a React Native developer (or working with any mobile development framework), you’re probably already familiar with tools like Yarn, Expo, and common Node.js commands.

But when you’re diving into native mobile development, there are a set of commands that can speed up your workflow. Below is a short list of useful iOS and Android commands to help you in your daily mobile app development.


iOS Commands

iOS commands primarily manage the development environment and dependencies for React Native apps on Apple devices. These commands help with tasks such as installing CocoaPods, launching simulators, building projects in Xcode, and troubleshooting issues with your iOS app. They are crucial for testing and debugging on iOS devices and simulators.

xed .

Opens the current directory in Xcode. Useful for quickly accessing project files.

pod install

Installs or updates the CocoaPods dependencies defined in the Podfile. This is essential after adding new libraries or making changes to the iOS project dependencies.

pod update

Updates all the installed CocoaPods to the latest versions allowed by the Podfile. Use this when you need to ensure your dependencies are up-to-date.

pod deintegrate

Removes all traces of CocoaPods from the iOS project. This is useful when you need to completely reset the pod setup, for example, when facing dependency issues.

pod install --repo-update

Installs the CocoaPods dependencies and also updates the local spec repo. Use this if you encounter issues with outdated repositories.

pod lib lint

Lints the CocoaPod library to ensure there are no issues before pushing it to the CocoaPods repo. This is typically used when creating custom pods.

xcrun xctrace list devices

Lists all available simulators and devices connected to your Mac. Handy for checking which devices are available for testing.

xcrun simctl launch "iPhone 15" {packageProject} -FIRAnalyticsDebugEnabled

Launches a specific app on a simulator, with Firebase Analytics debugging enabled (replace {packageProject} with your app’s package name).

xcrun simctl boot "iPhone 15"

Boots a specific iOS simulator (e.g., iPhone 15). Handy for starting simulators when they aren’t already running.

xcrun simctl shutdown "iPhone 15"

Shuts down a specific iOS simulator. This helps save resources when you’re done testing on a particular device.

xcodebuild -workspace {workspace} -scheme {scheme} -configuration Debug

Builds the project in Debug configuration, targeting a specific workspace and scheme. Replace {workspace} and {scheme} with your project’s respective values.

xcrun simctl erase all

Erases all data from iOS simulators, helping to reset the simulator environment. This can fix issues caused by simulator data corruption.


Android Commands

Android commands focus on building, installing, and debugging React Native apps on Android devices and emulators. These commands are useful for tasks like cleaning the build, installing APKs, setting up port forwarding, and managing dependencies through Gradle. They help ensure your app runs smoothly across various Android platforms.

./gradlew clean

Cleans the Android build directory, removing previous builds and temporary files. Useful for fixing build issues and ensuring a fresh build.

./gradlew assembleDebug

Builds the APK in Debug mode. This is typically used when you want to test a non-optimized version of the app on an emulator or device.

./gradlew assembleRelease

Builds the APK in Release mode. Use this when you want to generate a production-ready APK that you can distribute.

./gradlew installDebug

Installs the Debug APK onto the connected device or emulator. This is typically used after building the app with assembleDebug.

./gradlew dependencies

Lists all the dependencies of the Android project, showing their versions and whether they are up-to-date. This is useful for diagnosing dependency issues.

adb install {path-to-apk}

Installs an APK on a connected Android device or emulator.

adb -s emulator-5554 reverse tcp:8081 tcp:8081

Sets up port forwarding between your development machine and the Android emulator, allowing your React Native app to connect to the Metro bundler.

adb devices

Lists all connected devices and emulators. Use this to ensure your device or emulator is recognized.

adb logcat

Displays the log output from a connected Android device or emulator. This is crucial for debugging and viewing app logs in real-time.

adb shell am start -n {package}/{activity}

Launches a specific activity in your app on a connected Android device. Replace {package} with your app’s package name and {activity} with the target activity.

adb uninstall {package}

Uninstalls an app from a connected Android device or emulator. Replace {package} with the app’s package name.

adb shell pm grant {package} android.permission.CAMERA

Grants a specific permission to your app on a connected Android device. Replace {package} with your app’s package name and adjust the permission (e.g., CAMERAACCESS_FINE_LOCATION).

Conclusion

These commands are just a small set of tools that can streamline your mobile development workflow. Whether you’re debugging, installing builds, or launching simulators, mastering these commands can save you time and keep your process running smoothly.

comments