DEV Community

Cover image for How to Rebuild Android and iOS Separately in a Flutter Project
Geoffrey Kim
Geoffrey Kim

Posted on • Edited on

17

How to Rebuild Android and iOS Separately in a Flutter Project

In Flutter development, there might be times when you want to rebuild only the Android or iOS part of your project. This guide explains how to do it for each platform, highlighting key differences across operating systems, build options, and common troubleshooting steps.


Rebuilding Android

1. Delete the Android Build Folders

  • Navigate to the root directory of your Flutter project.
  • Delete both the app build folder and Gradle cache using the following commands:
  rm -rf android/app/build
  rm -rf android/.gradle
Enter fullscreen mode Exit fullscreen mode

Note for Windows Users:

The rm -rf commands are for Unix-based systems (Linux/macOS). On Windows, use these commands from Command Prompt:

  rd /s /q android\app\build
  rd /s /q android\.gradle
Enter fullscreen mode Exit fullscreen mode

Deleting the .gradle folder is important as it contains cached build information that might prevent a true clean rebuild.


2. Build Using Flutter Commands

From the root directory, you can rebuild Android using Flutter's build commands with specific build modes:

  • For APK:
  flutter build apk --release  # For production-ready APK
  flutter build apk --debug    # For debugging
  flutter build apk --profile  # For performance profiling
Enter fullscreen mode Exit fullscreen mode
  • For App Bundle:
  flutter build appbundle --release  # For Google Play Store deployment
Enter fullscreen mode Exit fullscreen mode

The differences between build modes:

  • Debug: Includes debugging information and performs slower
  • Profile: Optimized for performance analysis
  • Release: Fully optimized for production with no debugging information

3. Rebuild via Android Studio

  • Open your Flutter project in Android Studio.
  • Go to the Build menu and select Rebuild Project. This option cleans up previous builds and compiles your project afresh.

Rebuilding iOS

1. Delete the iOS Build Folders and Related Files

  • Navigate to the root directory of your Flutter project.
  • Remove the build folder and optionally reset Flutter frameworks:
  rm -rf ios/build
  rm -rf ios/Pods
  rm -rf ios/Flutter/Flutter.framework
  rm -rf ios/Flutter/App.framework
  rm -f ios/Podfile.lock  # Delete if you're having dependency issues
Enter fullscreen mode Exit fullscreen mode

About DerivedData:

Xcode stores build cache in ~/Library/Developer/Xcode/DerivedData. To clear this completely:

rm -rf ~/Library/Developer/Xcode/DerivedData
Enter fullscreen mode Exit fullscreen mode

Important Note for Windows Users:

iOS builds are NOT possible directly on Windows. You must have a Mac or use:

  • A cloud-based Mac service (like MacStadium or MacinCloud)
  • A Mac virtual machine (although this may violate Apple's terms of service)
  • A physical Mac for remote building

Any command related to iOS building will not work on a Windows machine without one of these solutions.


2. Reinstall Dependencies (if needed)

If you deleted the Podfile.lock or Pods directory:

cd ios
pod install
cd ..
Enter fullscreen mode Exit fullscreen mode

3. Build Using Flutter Commands

From the root directory, rebuild iOS using:

flutter build ios --release  # For App Store submission
flutter build ios --debug    # For debugging (default)
flutter build ios --profile  # For performance testing
Enter fullscreen mode Exit fullscreen mode

Note: The --release build will only work on a physical device and requires proper code signing.


4. Rebuild via Xcode

  • Open the ios/Runner.xcworkspace file in Xcode (not the .xcodeproj file).
  • From the top menu, select Product > Clean Build Folder. This action removes previously compiled files and clears DerivedData.
  • Then, choose Product > Build or click the Run button to compile the latest code.

Using flutter clean for Complete Reset

Running:

flutter clean
Enter fullscreen mode Exit fullscreen mode

This command does more than just delete build folders:

  • Removes the build/ directory for both platforms
  • Deletes the .dart_tool/ directory
  • Removes the .packages file
  • Resets all cached Dart dependencies and compiled artifacts

Use this when you want a complete project reset. After running this command, you may need to:

flutter pub get  # Restore Dart dependencies
cd ios && pod install && cd ..  # Restore iOS dependencies (macOS only)
Enter fullscreen mode Exit fullscreen mode

Common Build Issues and Solutions

Android Build Issues

  1. Gradle Version Conflicts

    • Symptom: Error messages about incompatible Gradle versions
    • Solution: Update the Gradle version in android/gradle/wrapper/gradle-wrapper.properties
  2. SDK Version Issues

    • Symptom: "compileSdkVersion not found" errors
    • Solution: Check your android/app/build.gradle file and ensure SDK versions are installed in Android Studio
  3. Memory Issues

    • Symptom: Build fails with "OutOfMemoryError"
    • Solution: Add the following to android/gradle.properties:
     org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m
    

iOS Build Issues

  1. CocoaPods Dependency Problems

    • Symptom: "The dependency X is not used in any concrete target" errors
    • Solution: Delete Podfile.lock, run pod repo update followed by pod install
  2. Signing Certificate Issues

    • Symptom: "Failed to create provisioning profile" errors
    • Solution: In Xcode, go to Runner > Signing & Capabilities and ensure proper team selection
  3. Minimum iOS Version Conflicts

    • Symptom: "X requires a minimum deployment target of iOS X.X"
    • Solution: Update the minimum iOS version in Podfile and in Xcode project settings

By following these steps, you can rebuild the Android or iOS parts of your Flutter project separately. This selective approach can save time, help isolate platform-specific build issues, and ensure your project has a clean build state when troubleshooting problems.

Top comments (0)