Skip to content

Support for Kotlin 1.9 and 2.0 in flutter module template #160922

@reberthkss

Description

@reberthkss

Use case

Hi!

Our Android project is integrated with Flutter trough flutter module; it's a large native codebase project where we are migrating to 100% Flutter.

Context

The native side setup is built with Kotlin 2.0 and AGP 8.2.2 and we are doing well using flutter 3.24.0, which uses Kotlin 1.7.10 and agp 7.3.0, defined from default variable templateKotlinGradlePluginVersion and templateAndroidGradlePluginVersionForModule respectively, variables used to generate the .android folder for every run of flutter pub get or flutter build aar.

Problem

We are bumping our code base Flutter (plugins and third-party libraries) to Kotlin 2.0 and AGP 8.2.2 (like the native project setup), but we are not able to build the aar after upgrading the dynatrace_flutter_plugin. Which is reproducing the following output:

e: file:///Users/xxx/.pub-cache/hosted/pub.dev/dynatrace_flutter_plugin-3.305.2/android/src/main/kotlin/com/dynatrace/android/agent/SettingsApiImpl.kt:32:21 This declaration needs opt-in. Its usage must be marked with '@kotlin.ExperimentalStdlibApi' or '@OptIn(kotlin.ExperimentalStdlibApi::class)'
e: file:///Users/xxxx/.pub-cache/hosted/pub.dev/dynatrace_flutter_plugin-3.305.2/android/src/main/kotlin/com/dynatrace/android/agent/SettingsApiImpl.kt:32:41 This declaration needs opt-in. Its usage must be marked with '@kotlin.ExperimentalStdlibApi' or '@OptIn(kotlin.ExperimentalStdlibApi::class)'
e: file:///Users/xxx/.pub-cache/hosted/pub.dev/dynatrace_flutter_plugin-3.305.2/android/src/main/kotlin/com/dynatrace/android/agent/SettingsApiImpl.kt:32:41 The feature "enum entries" is only available since language version 1.9

This error indicates that the build of aar is using a Kotlin version below than 1.9.0; that is true, because in Flutter 3.27.0 the Kotlin version for templates is 1.8.22.

Steps to reproduce

The error above is reproduced using flutter 3.27.0.

  1. Create module: flutter create -t module sample_module
  2. Add dynatrace plugin: cd sample_module && flutter pub add dynatrace_flutter_plugin
  3. Build aar: flutter build aar
  • Note: The same occur using Flutter versions 3.24.0 and 3.24.3

Our proposals

Following the above scenario, we are requesting some of the following options to solve this problem:

1. Flexibility template options

Extend the functionality of pubspec yaml field module to support the definition of Kotlin, AGP, Gradle and the android.compileOptions.targetCompatibility/sourceCompatibility through YAML. Example:

name: sample_module
description: lorem epsum
version: 1.0.0+1

environment: ....

dependencies: ...

flutter:
   module:
        androidX: true
        androidPackage: br.com.sample_module
        ...
        kotlinVersion: 2.0.0
        agpVersion: 8.2.2
        gradleVresion: 8.2-all
        javaTargetCompatiblity: 17
        javaSourceCompatibility: 17

2. Create a toggle to prevent .android folder recreation

The Android setup has a note warning about the auto generated .android folder. It will be great if exists an toggle to turn off this auto-generation, so we can manually adjust the project and push to our repository.

3. Create a template that's supports kotlin 2.0 and AGP 8.x

Create a new template, adjusting setting up JAVA_17 and removing AndroidManifest.xml package field. Details here

Conclusion

I hope you guys understand our scenario and the steps to reproduce the error. Any doubts, touch me through e-mail: [email protected].

Best Regards,
Reberth Kelvin

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: existing-appsIntegration with existing apps via the add-to-app flowc: new featureNothing broken; request for a new capabilityc: proposalA detailed proposal for a change to Flutterplatform-androidAndroid applications specificallyt: gradle"flutter build" and "flutter run" on Androidteam-androidOwned by Android platform teamtoolAffects the "flutter" command-line tool. See also t: labels.triaged-androidTriaged by Android platform team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions