Skip to content

Commit

Permalink
chore: migrate Flutter SDK from v3.7 to v3.19 (#883)
Browse files Browse the repository at this point in the history
* Update pubspec

* Apply dart fix

* Mark struct classes as final

* Fix task_runner.dart

* Fix firebase code

* Update protoc_plugin from v20.0.1 to v21.1.2

* Migrate Flutter's Gradle plugins

https://docs.flutter.dev/release/breaking-changes/flutter-gradle-plugin-apply

* Migrate AppLocalizations

* Fix linter issue: use_build_context_synchronously

* Fix Dart linter issue: deprecated_member_use, dead_code, etc

* Update iOS settings

* Fix PopScope disables back navigation

* Disable new Material 3 theme

* Update Flutter SDK to v3.19.6

* Replace openjdk-11 with openjdk-17

* Fix make flutter/android/test-apk

* Update expected_throughput and expected_accuracy

* Fix Windows build error
  • Loading branch information
anhappdev authored May 23, 2024
1 parent 06aab5b commit 7bd3fe0
Show file tree
Hide file tree
Showing 59 changed files with 655 additions and 633 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
uses: subosito/flutter-action@v2
with:
channel: 'stable'
flutter-version: '3.7.6'
flutter-version: '3.19.6'
- name: Install Protoc
uses: arduino/setup-protoc@v1
with:
Expand All @@ -25,7 +25,7 @@ jobs:
- name: Create ephemeral files
run: |
flutter config --no-analytics &&
dart pub global activate protoc_plugin ^20.0.1 &&
dart pub global activate protoc_plugin ^21.1.2 &&
export PATH="$PATH:$HOME/.pub-cache/bin" &&
make flutter/prepare
- name: Run Flutter tests
Expand Down
2 changes: 1 addition & 1 deletion datasets/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ RUN apt-get update && apt-get upgrade -y && apt-get autoremove -y && \
apt-get install -y --no-install-recommends \
python3 python3-pip libpython3.6-dev python3.6-venv libgl1-mesa-glx libglib2.0 cython3 gcc make curl unzip libc++1-8 \
git locales openssh-client ca-certificates tar gzip parallel \
zip bzip2 gnupg wget python3-six python3-pip libncurses5 openjdk-11-jdk-headless clang-format-10 golang-1.13-go build-essential
zip bzip2 gnupg wget python3-six python3-pip libncurses5 openjdk-17-jdk-headless clang-format-10 golang-1.13-go build-essential

RUN pip3 install pip==21.3.1 setuptools==31.0.1
RUN pip3 install tensorflow-cpu==1.15
Expand Down
2 changes: 1 addition & 1 deletion docs/build-and-run.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ Visual Studio projects generated by Flutter don't have any backend files,
but you can drag and drop files from `cpp` folders to open them in Visual Studio and set breakpoints.

Run `flutter build windows` to build release folder with the app.
The release folder will be located in `flutter/build/windows/runner/Release/`.
The release folder will be located in `flutter/build/windows/x64/runner/Release/`.
To create redistributable copy the following files into the application directory:

```text
Expand Down
6 changes: 3 additions & 3 deletions docs/environment-setup/env-setup-android.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ These steps are required to build native libs only.
gnupg \
make \
python3 python3-pip \
openjdk-11-jdk-headless \
openjdk-17-jdk-headless \
protobuf-compiler
```

Expand Down Expand Up @@ -75,7 +75,7 @@ Flutter requires native libs so you must complete [Setting up Bazel on Ubuntu](#
* Install Flutter:

```bash
mkdir -p ~/tools && cd ~/tools && curl https://storage.googleapis.com/flutter_infra_release/releases/stable/linux/flutter_linux_3.7.6-stable.tar.xz | tar Jxf -
mkdir -p ~/tools && cd ~/tools && curl https://storage.googleapis.com/flutter_infra_release/releases/stable/linux/flutter_linux_3.19.6-stable.tar.xz | tar Jxf -
```

* Add flutter binary folders to path: `export PATH=$PATH:~/tools/flutter/bin:~/.pub-cache/bin`
Expand All @@ -91,7 +91,7 @@ Flutter requires native libs so you must complete [Setting up Bazel on Ubuntu](#
You will need to restart your WSL instance to apply changes.
Run `wsl --shutdown` in Windows, and then reopen WSL.
* Enable protobuf plugin: `dart pub global activate protoc_plugin ^20.0.1`
* Enable protobuf plugin: `dart pub global activate protoc_plugin ^21.1.2`
* Install dependencies via sdkmanager, accept licenses for dependencies:
Expand Down
22 changes: 11 additions & 11 deletions docs/environment-setup/env-setup-ios.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,36 +25,36 @@ Otherwise, you can get errors about missing pods
* Download flutter repo:

```bash
mkdir -p ~/tools && git clone --branch 3.7.6 --depth 1 https://github.com/flutter/flutter.git ~/tools/flutter
mkdir -p ~/tools && git clone --branch 3.19.6 --depth 1 https://github.com/flutter/flutter.git ~/tools/flutter
```

* Add flutter binary folders to path: `export PATH="$PATH:$HOME/tools/flutter/bin:$HOME/.pub-cache/bin"`
If you use zsh: `echo export PATH="\$PATH:\$HOME/tools/flutter/bin:\$HOME/.pub-cache/bin" >>~/.zshrc`
* Enable protobuf plugin: `dart pub global activate protoc_plugin ^20.0.1`
* Enable protobuf plugin: `dart pub global activate protoc_plugin ^21.1.2`
* Go to `ios` directory and install pods: `pod install`

## Tested environment

The app was built and tested successfully in this environment:

```shell
macOS 13.2.1
Xcode 14.2
macOS 14.4.1
Xcode 15.4
$ flutter --version
Flutter 3.7.6 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 12cb4eb7a0 (11 days ago) • 2023-03-01 10:29:26 -0800
Engine • revision ada363ee93
Tools • Dart 2.19.3 • DevTools 2.20.1
Flutter 3.19.6 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 54e66469a9 (4 weeks ago) • 2024-04-17 13:08:03 -0700
Engine • revision c4cd48e186
Tools • Dart 3.3.4 • DevTools 2.31.1
$ bazel --version
bazel 5.3.2
bazel 6.3.2
$ protoc --version
libprotoc 3.21.9
libprotoc 23.2
$ pod --version
1.11.3
1.15.2
$ python3 --version
Python 3.9.16
Expand Down
4 changes: 2 additions & 2 deletions docs/environment-setup/env-setup-windows.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ However, using Chocolatey greatly simplifies installation.
* `choco install -y msys2`
* `choco install -y flutter`
* `choco install -y protoc`
* `dart pub global activate protoc_plugin ^20.0.1`
* `dart pub global activate protoc_plugin ^21.1.2`
* Configure python
* You must have command `python3` in your PATH.
Python installed via Chocolatey provides only `python.exe` file, so you will need to create `python3` yourself.
Expand All @@ -40,7 +40,7 @@ However, using Chocolatey greatly simplifies installation.
* Set python path env, paths must use forward slashes
* Install python dependencies: `python3 -m pip install --user numpy absl-py`
* Add MSYS2 bin folder to PATH: `C:/tools/msys64/usr/bin`
* Enable protobuf plugin: `dart pub global activate protoc_plugin ^20.0.1`
* Enable protobuf plugin: `dart pub global activate protoc_plugin ^21.1.2`
* Add dart pub cache bin folder to PATH: `%LOCALAPPDATA%/Pub/Cache/bin`
* Turn on the developer mode in Windows settings.
* This option should be located in `Update & Security``For developers`.
Expand Down
44 changes: 19 additions & 25 deletions flutter/android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
plugins {
id "com.android.application"
id "kotlin-android"
id "dev.flutter.flutter-gradle-plugin"
id 'com.google.gms.google-services'
id 'com.google.firebase.crashlytics'
}

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
Expand All @@ -6,31 +14,18 @@ if (localPropertiesFile.exists()) {
}
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
throw new GradleException("versionCode not found. Define flutter.versionCode in the local.properties file.")
throw new RuntimeException("versionCode not found. Define flutter.versionCode in the local.properties file.")
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
throw new GradleException("versionName not found. Define flutter.versionName in the local.properties file.")
throw new RuntimeException("versionName not found. Define flutter.versionName in the local.properties file.")
}

apply plugin: 'com.android.application'
// START: FlutterFire Configuration
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'
// END: FlutterFire Configuration
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 33
compileSdkVersion 34

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
Expand All @@ -54,14 +49,14 @@ android {
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

signingConfigs {
release {
keyAlias System.env['SIGNING_KEY_ALIAS']
keyPassword System.env['SIGNING_KEY_PASSWORD']
storeFile System.env['SIGNING_STORE_FILE'] ? file(System.env['SIGNING_STORE_FILE']) : null
storePassword System.env['SIGNING_STORE_PASSWORD']
}
}
signingConfigs {
release {
keyAlias System.env['SIGNING_KEY_ALIAS']
keyPassword System.env['SIGNING_KEY_PASSWORD']
storeFile System.env['SIGNING_STORE_FILE'] ? file(System.env['SIGNING_STORE_FILE']) : null
storePassword System.env['SIGNING_STORE_PASSWORD']
}
}

buildTypes {
release {
Expand Down Expand Up @@ -92,7 +87,6 @@ flutter {
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
Expand Down
19 changes: 1 addition & 18 deletions flutter/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,20 +1,3 @@
buildscript {
ext.kotlin_version = '1.8.22'
repositories {
google()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:7.1.2'
// START: FlutterFire Configuration
classpath 'com.google.gms:google-services:4.3.10'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.8.1'
// END: FlutterFire Configuration
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

allprojects {
repositories {
google()
Expand All @@ -28,6 +11,6 @@ subprojects {
project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
13 changes: 8 additions & 5 deletions flutter/android/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ FROM ubuntu:20.04
# JDK package downloads ~500 MB from slow mirrors, which can take a lot of time,
# so a separate layer for it makes image rebuild faster in case we change any other dependencies.
RUN apt-get update >/dev/null && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
openjdk-11-jdk-headless && \
openjdk-17-jdk-headless && \
rm -rf /var/lib/apt/lists/*
RUN apt-get update >/dev/null && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
build-essential \
Expand All @@ -19,6 +19,7 @@ RUN apt-get update >/dev/null && DEBIAN_FRONTEND=noninteractive apt-get install
make \
protobuf-compiler \
python3 \
python3-dev \
python3-pip && \
rm -rf /var/lib/apt/lists/*

Expand All @@ -40,9 +41,11 @@ RUN yes | sdkmanager --licenses >/dev/null
RUN yes | sdkmanager \
"platform-tools" \
"build-tools;30.0.3" \
"build-tools;34.0.0" \
"platforms;android-29" \
"platforms;android-31" \
"platforms;android-33"
"platforms;android-33" \
"platforms;android-34"
# Install NDK in a separate layer to decrease max layer size.
RUN yes | sdkmanager "ndk;25.2.9519653"
ENV ANDROID_NDK_ROOT=$ANDROID_SDK_ROOT/ndk/25.2.9519653
Expand All @@ -54,18 +57,18 @@ WORKDIR $HOME

ENV PUB_CACHE=$HOME/.cache/.pub-cache
ENV PATH=$PATH:$HOME/flutter/bin:$HOME/flutter/bin/cache/dart-sdk/bin:$PUB_CACHE/bin
RUN git clone --branch "3.7.6" --single-branch --depth 1 https://github.com/flutter/flutter.git $HOME/flutter
RUN git clone --branch "3.19.6" --single-branch --depth 1 https://github.com/flutter/flutter.git $HOME/flutter
RUN git config --global --add safe.directory $HOME/flutter
RUN flutter config --no-analytics && dart --disable-analytics
RUN flutter doctor -v
RUN dart pub global activate protoc_plugin ^20.0.1 && chmod --recursive a=u $PUB_CACHE
RUN dart pub global activate protoc_plugin ^21.1.2 && chmod --recursive a=u $PUB_CACHE

RUN mkdir -p $HOME/.cache/.gradle
ENV GRADLE_USER_HOME=$HOME/.cache/.gradle
ENV ANDROID_SDK_HOME=$HOME/.cache/.android

RUN mkdir $ANDROID_SDK_HOME && \
PASSWD=$(pwgen -s -y 20 1) && keytool -genkey -v -keystore $ANDROID_SDK_HOME/debug.keystore \
PASSWD=$(pwgen -s -y 20 1) && keytool -genkey -v -keyalg RSA -keystore $ANDROID_SDK_HOME/debug.keystore \
-storepass $PASSWD -alias androiddebugkey -keypass $PASSWD -dname "CN=Android Debug,O=Android,C=US"

# Git repo will be mounted at '/image-workdir/project'
Expand Down
2 changes: 1 addition & 1 deletion flutter/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.3-all.zip
32 changes: 24 additions & 8 deletions flutter/android/settings.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
include ':app'
pluginManagement {
def flutterSdkPath = {
def properties = new Properties()
file("local.properties").withInputStream { properties.load(it) }
def flutterSdkPath = properties.getProperty("flutter.sdk")
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
return flutterSdkPath
}()

def localPropertiesFile = new File(rootProject.projectDir, "local.properties")
def properties = new Properties()
includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")

assert localPropertiesFile.exists()
localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) }
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
}

def flutterSdkPath = properties.getProperty("flutter.sdk")
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle"
plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
id "com.android.application" version "7.3.0" apply false
id "org.jetbrains.kotlin.android" version "1.7.10" apply false
id "com.google.gms.google-services" version "4.4.0" apply false
id "com.google.firebase.crashlytics" version "2.9.9" apply false
}

include ":app"
6 changes: 3 additions & 3 deletions flutter/flutter.mk
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ flutter/update-splash-screen:

.PHONY: flutter/l10n
flutter/l10n:
flutter --no-version-check gen-l10n \
--arb-dir=flutter/lib/l10n \
--output-dir=flutter/lib/localizations \
cd flutter && flutter --no-version-check gen-l10n \
--arb-dir=lib/l10n \
--output-dir=lib/localizations \
--template-arb-file=app_en.arb \
--output-localization-file=app_localizations.dart \
--no-synthetic-package
Expand Down
4 changes: 2 additions & 2 deletions flutter/integration_test/expected_throughput.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const Map<String, Map<String, Interval>> _imageClassification = {
_kIphoneOnGitHubAction: Interval(min: 1, max: 12),
},
_kPixelBackend: {
_kPixel6: Interval(min: 800, max: 1200),
_kPixel6: Interval(min: 700, max: 1200),
},
_kQtiBackend: {
_kS22Ultra: Interval(min: 1600, max: 2400),
Expand Down Expand Up @@ -83,7 +83,7 @@ const Map<String, Map<String, Interval>> _objectDetection = {
_kCloudBuildX28: Interval(min: 3.5, max: 8),
_kRyzen5600: Interval(min: 14, max: 22),
_kPixel5: Interval(min: 40, max: 60),
_kPixel6: Interval(min: 200, max: 450),
_kPixel6: Interval(min: 100, max: 450),
_kIphoneOnGitHubAction: Interval(min: 0.5, max: 4),
_kIphoneOnMacbookM1: Interval(min: 9, max: 16),
},
Expand Down
2 changes: 1 addition & 1 deletion flutter/ios/Flutter/AppFrameworkInfo.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
<key>CFBundleVersion</key>
<string>1.0</string>
<key>MinimumOSVersion</key>
<string>11.0</string>
<string>12.0</string>
</dict>
</plist>
Loading

0 comments on commit 7bd3fe0

Please sign in to comment.