You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

Flutter构建Release版APK无法生成更新版本问题求助

Fixing Flutter Release APK Stuck on Old Version (1.0 instead of 2.0)

Hey there! Let's troubleshoot why your Flutter 2.0 release build is still churning out the 1.0 APK, even though debug mode runs the new version perfectly. Here are the most common fixes to try, starting with the simplest:

  • Update your pubspec.yaml version
    First things first—open your pubspec.yaml file and confirm the version field is set to your 2.0 release (e.g., version: 2.0.0+2). The number after the + is the build number, so make sure that's incremented too. After editing, run flutter pub get to sync the changes.

  • Wipe the build cache completely
    Old build artifacts are often the culprit. Run these commands in your project root to start fresh:

    flutter clean
    flutter pub get
    flutter build apk --release
    

    This deletes all cached build files and forces Flutter to rebuild everything from scratch.

  • Confirm you're grabbing the right APK
    It sounds silly, but double-check the output path! The release APK lives at build/app/outputs/flutter-apk/app-release.apk. Make sure you're not accidentally picking up an old APK from a different folder. Check the file's timestamp to confirm it was just generated.

  • Check for hardcoded versions in Android files
    Sometimes the Android build config overrides the pubspec settings. Open android/app/build.gradle and look for versionCode or versionName—if they're hardcoded (not using flutterVersionCode/flutterVersionName), update them to match your 2.0 version, or remove them so they inherit from pubspec.

  • Invalidate IDE caches
    If you're using Android Studio or VS Code, cached IDE data might be stuck on the old version:

    • For Android Studio: Go to File > Invalidate Caches... and select "Invalidate and Restart".
    • For VS Code: Open the command palette (Ctrl+Shift+P / Cmd+Shift+P), run "Flutter: Clean", then "Flutter: Pub Get", before rebuilding.
  • Verify build flavors (if you use them)
    If your project uses build flavors, you might be building an old flavor by default. Try explicitly specifying your target flavor when building:

    flutter build apk --release --flavor yourFlavorName
    

    Double-check your flavor setup in android/app/build.gradle to ensure the 2.0 code is linked correctly.

If none of these work, double-check that your 2.0 code changes are actually in the branch you're building from (since debug works, this is less likely, but worth confirming!).

内容的提问来源于stack exchange,提问作者nitishk72

火山引擎 最新活动