Flutter集成Google Sign-In遇Android端Unable to merge dex构建错误求助
Hey there! Let's tackle this dex merge issue you're facing with Flutter and Firebase Authentication on Android—totally get why this is frustrating, especially since everything works smoothly on iOS. Here are some straightforward, beginner-friendly fixes you can try without diving too deep into Gradle configurations:
1. Update Your Dependencies to the Latest Stable Versions
Your google_sign_in: 0.3.1 version is quite outdated, and old dependency versions often clash with newer Flutter or Firebase SDKs. Head over to your pubspec.yaml file and update the dependency to the latest stable release (e.g., google_sign_in: ^5.4.0). After making the change, run:
flutter pub get
2. Enable Multidex for Your Android Project
A common cause of this dex merge error is hitting Android's 65k method count limit. Enabling multidex is a simple fix:
- Open
app/build.gradle, find thedefaultConfigblock, and add:multiDexEnabled true - In the same file's
dependenciessection, add this line:implementation 'androidx.multidex:multidex:2.0.1'
Save the file and try running your app again with flutter run.
3. Clean and Rebuild Your Project
Cached build files can sometimes cause weird conflicts. Clear them out with these commands:
flutter clean cd android && ./gradlew clean cd .. && flutter run
4. Check for Duplicate Dependencies (If All Else Fails)
Occasionally, indirect dependencies can introduce duplicate Android libraries. You can run this command to view your full dependency tree and spot duplicates:
flutter pub deps
Look for any repeated Android-related libraries and adjust your dependencies accordingly, but this is a last-resort step—most of the time, the first three fixes will resolve the issue.
If you still run into trouble, double-check that the Google Services classpath in your root build.gradle is using the latest stable version (e.g., classpath 'com.google.gms:google-services:4.3.10').
内容的提问来源于stack exchange,提问作者Serge B.

