Reviving Stale Flutter App For iOS and Android

2023-09-29
Flutter
Dart
development
iOS
Android
bash

The problem

I have a Flutter app I developed couple years back, PictureVert (source code: https://github.com/hydralien/PictureVert). It had been collecting proverbial dust for a while, so I decided to build ad deploy fresh packages for both iOS and Android.

So I needed to figure out how to update everything and make it work again.

Flutter

  • Install fresh Flutter and set its path in the PATH variable (in e.g. ~/.profile)
  • Run flutter pub outdated and flutter pub upgrade (I had to do those iteratively because one points to another, but once is actually enough)
  • Add new versions of stale packages via flutter pub add packagename anotherpackagename ...
  • Check flutter pub outdated again - it seemed to have different concerns this time around
  • Add what's missing via flutter pub add and flutter pub upgrade
  • Check flutter doctor to see all is well

iOS

Building for iOS got simpler, though requires some pre-steps:

Accept XCode license agreement

sudo xcode-select -s /Applications/Xcode.app/Contents/Developer sudo xcodebuild -runFirstLaunch sudo xcodebuild -license

Prepare dependencies

xcodebuild -downloadPlatform iOS open -a Simulator cd ios; pod install; cd ..

Build and install

flutter build ipa

At the end of teh build, some useful guidance is provided:

Built IPA to /Users/halien/devel/picturevert/build/ios/ipa. To upload to the App Store either: 1. Drag and drop the "build/ios/ipa/.ipa" bundle into the Apple Transporter macOS app https://apps.apple.com/us/app/transporter/id1450874784 2. Run "xcrun altool --upload-app --type ios -f build/ios/ipa/.ipa --apiKey your_api_key --apiIssuer your_issuer_id". See "man altool" for details about how to authenticate with the App Store Connect API key.

I decided to use the "Apple Transporter" way (#1) and it worked surprisingly smooth - the build appeared in the App Store Connect immediately, ready for testing and being plugged to a release, so I just needed to provide an info about teh update and submit it for review.

Android

First, Google Play Store Console required updating the SDK versions, so in android/local.properties I needed to set

flutter.minSdkVersion=24 flutter.targetSdkVersion=33

Then, things with Android were not that smooth - flutter build appbundle started complaining seemingly about one of the dependencies:

* What went wrong: A problem occurred evaluating project ':share_plus'. > No signature of method: build_bkr51e9abrzl3n3k84uhu79f3.android() is applicable for argument types: (build_bkr51e9abrzl3n3k84uhu79f3$_run_closure2) values: [build_bkr51e9abrzl3n3k84uhu79f3$_run_closure2@94bf7f9]

But that's a deception: apparently the problem is incompatibility with old Gradle plugin, but to which version to update was unclear.

So I ended up doing flutter create newproject elsewhere, and then copying the supported versions from it:

  • from android/gradle/wrapper/gradle-wrapper.properties, the distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip
  • from android/build.gradle, the ext.kotlin_version = '1.7.10' and the classpath 'com.android.tools.build:gradle:7.3.0'

After that, flutter build appbundle had finally succeeded.

I also copied sdk: '>=3.1.3 <4.0.0' from pubspec.yaml of a fresh Flutter app, just to be sure.