Flutter升级至1.2后真机启动报致命异常的解决方法
Hey there, sorry to hear you're hitting this crash after upgrading to Flutter 1.2. The error points to a missing FlutterApplication class in your APK's Dex path, which usually stems from misaligned Android configuration post-upgrade. Let's walk through the fixes one by one:
1. Verify AndroidManifest.xml Configuration
First, check your app's Android manifest to ensure the application class is correctly set. Open android/app/src/main/AndroidManifest.xml and look at the root <application> tag:
If it’s set to
android:name="io.flutter.app.FlutterApplication", try temporarily replacing it with the Android MultiDex application class to rule out Dex-related issues:<application android:name="android.support.multidex.MultiDexApplication" <!-- keep your other existing attributes --> ...>
If you have a custom Application class, make sure it extends MultiDexApplication instead of the default Application.
2. Enable MultiDex in Gradle
Flutter upgrades can sometimes push your app's method count beyond Android's 64k Dex limit, triggering this error. Enable MultiDex support in your app's build config:
Open android/app/build.gradle and update these sections:
android { defaultConfig { // Add this line to enable MultiDex multiDexEnabled true // ... your existing config (minSdkVersion, targetSdkVersion, etc.) } } dependencies { // Add the MultiDex dependency implementation 'com.android.support:multidex:1.0.3' }
3. Clean and Rebuild Thoroughly
You’ve already run basic clean commands, but let’s do a deep clean of cached build artifacts to eliminate any leftover conflicts:
- Run
flutter cleanagain - Manually delete the
android/.gradleandandroid/app/builddirectories - Run
flutter pub getto refresh dependencies - Finally, deploy to your device with
flutter run
4. Validate Flutter SDK and Android Tooling
Run flutter doctor in your terminal to check for misconfigured Android dependencies. Look out for warnings about:
- Outdated Android SDK components
- Mismatched Gradle plugin versions
- Missing build tools
Follow the prompts from flutter doctor to fix any flagged issues (e.g., updating SDK components or Gradle).
5. Uninstall and Reinstall the App
Old app remnants on your device can sometimes cause conflicts. Uninstall the existing version completely, clear any leftover app cache, then deploy the newly built APK with flutter run.
These steps should resolve the ClassNotFoundException by ensuring the Flutter application class is properly included in your Dex files and all dependencies are aligned with Flutter 1.2.
内容的提问来源于stack exchange,提问作者oryan

