Friday 28 April 2023

How to keep many Android/Flutter tools up to date

I am using Flutter to develop Android app.

There is a large number of tools needed to get this to work. Each of these tools has a version number you have to specify. I am struggling to find a place that explains what version should be used. Occasionally, the build fails when I update to a newer version of the tool, but who knows what other things are affected that are not an outright build failure.

Can someone help explain how to keep the project up to date with the correct recent versions?

These are the tools/frameworks I am talking about

Gradle

This is very confusing. There is the gradle itself inside flutter and gradle build tools (also referred to as gradle plugin).

Gradle version is defined in gradle-wrapper.properties in android\gradle\wrapper\ folder. I have upgraded this to version 7.5.1.

distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-all.zip

There are more recent versions here: gradle.org/releases/

There is some compatibility info here: docs.gradle.org/compatibility and here: developer.android.com/gradle-plugin but nothing for Flutter specifically.

Going by these documents, seems that Android Studio recommends using gradle version 7.5 (latest patch atm is 7.5.1) with gradle plugin 7.4 (latest patch at the time of writing is 7.4.2 as per developer.android.com/gradle-plugin

Plugin/build tools version is defined in android/gradle.build config file (there is another one in android/app folder):

 dependencies {
        classpath 'com.android.tools.build:gradle:7.4.2'

Flutter has a default gradle build tools version in its configuration file which is referring to version 4 which is very old in 2023. Not sure why is flutter default using such an old version? Perhaps it doesn't matter, but usually you get some benefits from upgrading otherwise why bother?

..\flutter\packages\flutter_tools\gradle\flutter.gradle: classpath 'com.android.tools.build:gradle:4.1.0'

Kotlin

Not sure why both Kotlin and Java are used. But this somehow has to play with Gradle. Through trial an error I have arrived at version 1.8.10 which works with Gradle build tools 7.4.2 and Gradle 7.5.1

This is in android/build.gradle file:

ext.kotlin_version = '1.8.10'

Java

There is a lot of confusion about this, especially with the recent version of Android Studio moving java jre from jre to jbr folder deep in the guts of the Android Studio installation path which caused flutter doctor to freak out and builds to fail.

There is also this (below) in gradle.build file, some documentation refers to version 1.6, I am using 1.8. This document mentions 1.8 a lot, but also version 2 to be used with Gralde 7.4: developer.android.com/java8-support. Not sure if I should upgrade?

compileOptions {
       sourceCompatibility JavaVersion.VERSION_1_8
       targetCompatibility JavaVersion.VERSION_1_8

}

// For Kotlin projects
kotlinOptions {
   jvmTarget = "1.8"
}

There is also java SDK (JDK). Some docs say to use version 11, gradle supports up to version 19.

I am using openjdk version "11.0.16.1" 2022-08-12 LTS. Not sure if there is benefit upgrading to a later version?

In appName_android.iml file there is this, not sure what this means and if it ever needs to be upgraded:

<module type="JAVA_MODULE" version="4">

NDK

This tools is installed and patched through Android Studio.

Flutter refers to it in its config files, I am overriding it in android/app/gradle.build config file and pointing to the latest version installed using Android Studio SDK manager:

android {
    compileSdkVersion 33 //flutter.compileSdkVersion
    ndkVersion '25.2.9519653'

Found this compatibility info from Android Studio: developer.android.com/default-ndk-per-agp This is pointing to NDK version 23.1.7779620 for gradle plugin 7.4.

This is version is also used in this flutter config file: ..\flutter\packages\flutter_tools\gradle\flutter.gradle

Flutter Build Tools

This is supposed to be configured in local properties file, but I ended up adding it to android/app/gradle.build:

def flutterBuildToolsVersion = localProperties.getProperty('flutter.buildToolsVersion')
if (flutterBuildToolsVersion == null) {
    flutterBuildToolsVersion = '33.0.2'
}

Has to do with target version of Android? Some docs refer to version 30.0.3, I am setting it to match the latest version in Android Studio.

AndroidX work runtime ktx

Ran into this one at some point due to a build error. Added it to android/build.gradle dependencies

implementation 'androidx.work:work-runtime-ktx:2.8.1'

Not sure if it even needs updating?

Multidex

Ran into this one due to a build failure after removing x86 from release ndk abiFilters. Adding these options to build.gradle resolved the issue. Not sure what this is about and if we need to update this?

multiDexEnabled = true
implementation("androidx.multidex:multidex:2.0.1")

Any help in how to keep all these up to date and working together would be appreciated. I'd appreciate some guidelines how to keep all this up to date going forward, not just the versions that should be used at the moment...



from How to keep many Android/Flutter tools up to date

No comments:

Post a Comment