Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android build fails with Flutter 2.10.0 because of incompatible Kotlin plug-in #1335

Closed
alod2019 opened this issue Feb 4, 2022 · 18 comments
Closed
Assignees
Labels
bug Something is not working; the issue has reproducible steps and has been reproduced Build Issues related to building apps using Amplify flutter

Comments

@alod2019
Copy link

alod2019 commented Feb 4, 2022

Describe the bug
Android build fails with a bunch of error messages like

The class is loaded from C:/Users/user/.gradle/caches/transforms-3/c81c0f1df64c9c236ff06a99362582a5/transformed/jetified-kotlin-stdlib-1.5.31.jar!/kotlin/jvm/JvmStatic.class
e: C:\flutter-2.10.0\.pub-cache\hosted\pub.dartlang.org\amplify_core-0.3.2\android\src\main\kotlin\com\amazonaws\amplify\amplify_core\exception\ExceptionUtil.kt: (103, 13): Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.5.1, expected version is 1.1.15.

To Reproduce
Just build a project with Amplify 0.3.2

Expected behavior
No build errors

Platform
Amplify Flutter current supports iOS and Android. This issue is reproducible in (check all that apply):
[x] Android
[] iOS

Additional context
The root cause is this Flutter 2.10.0 breaking change

@Jordan-Nelson Jordan-Nelson self-assigned this Feb 4, 2022
@Jordan-Nelson
Copy link
Contributor

Hello @alod2019 - Thanks for opening the issue. I am actively working on a fix.

@Jordan-Nelson Jordan-Nelson added bug Something is not working; the issue has reproducible steps and has been reproduced Build Issues related to building apps using Amplify flutter labels Feb 4, 2022
@joaohenriquesouza80
Copy link

@alod2019 Did you try change in Android/build.gradle ?
From ext.kotlin_version = '1.3.50' to ext.kotlin_version = '1.4.32'

@haverchuck
Copy link
Contributor

@alod2019 Which value did you have for ext.kotlin_version in your app's build gradle?

@Jordan-Nelson
Copy link
Contributor

Jordan-Nelson commented Feb 5, 2022

@alod2019 (or anyone else facing this issue) - see below for a suggested fix, and some context on the issue.

Suggested Fix

If your android/build.gradle file has a kotlin_version lower than 1.5.31, you should be able to resolve this by bumping the kotlin_version to 1.5.31 or higher.

Below is an example of the changes you will need to make:

+ ext.kotlin_version = '1.6.10' // needs to be 1.5.31 or higher for flutter 2.10.0
- ext.kotlin_version = '1.3.50'

For anyone using the amplify_authenticator package, there were changes in flutter 2.10.0 that conflict with this package. We have released 0.1.0-rc.5 to resolve these issues.

Context

As you noted in the issue description, kotlin 1.5.31 or higher is required for Flutter 2.10.0. The flutter docs note the following:

To build a Flutter app for Android, Kotlin 1.5.31 or greater is required.

The amplify_flutter packages specify kotlin 1.3.50. Our team will be discussing bumping the version set in the packages, but after testing with various flutter/kotlin versions, we believe that this isn't the cause of the issue you are seeing, and that you will need to bump this either way if you want to use flutter 2.10.0.

Additionally, we have run our integration test suite with amplify_flutter 0.3.2, flutter 2.10.0, and kotlin_version 1.6.10 in the integration test packages and did not find any issues.

As noted by @joaohenriquesouza80, you may find that kotlin 1.4.32 works as well. I did very minimal smoke testing with this and found that apps using amplify_flutter did build. However, I would highly recommend bumping to 1.5.31 or later, as per the flutter docs.

@Jordan-Nelson Jordan-Nelson pinned this issue Feb 5, 2022
@Jordan-Nelson
Copy link
Contributor

I have pinned this issue since flutter 2.10.0 became stable a few days ago and others may run into this as well.

@willianmascimiano
Copy link

I've did this changes, and works for me. Thanks.

@alod2019
Copy link
Author

alod2019 commented Feb 7, 2022

@alod2019 (or anyone else facing this issue) - see below for a suggested fix, and some context on the issue.

The suggested fix works but only if the app. project was created with Kotlin enabled.
Flutter 2.10 enables Kotlin even if 'flutter create' was called with '-a java' (!?).
Otherwise the build fails and in addition to the suggested fix one should care to add Kotlin dependencies manually.

So I guess that module-level fix(es) would be appreciated anyway.

@Jordan-Nelson
Copy link
Contributor

@alod2019 - Thanks for following up.

If you do not have Kotlin as a dependency, then you are right that this will not work.

I had noticed that flutter create -a java enabled Kotlin as well. It seems to be the case with flutter 2.10.0 and 2.8.1. I have not tested farther back. Do you know roughly when your project was created? If you never took any steps to remove Kotlin as a dependency, then I would assume that the behavior of flutter create -a java use to be different.

@alod2019
Copy link
Author

alod2019 commented Feb 7, 2022

@Jordan-Nelson

Do you know roughly when your project was created?

One year ago. It was created with '-a java' so it never had Kotlin enabled.

@Jordan-Nelson
Copy link
Contributor

@alod2019 Thanks. I tested flutter create -a java with flutter 2.0.x and confirmed that it doesn't add kotlin as a dep. It seems that adding it as a dep even with the -a java option was a change made somewhere between flutter 2.0.x and 2.8.1.

So I guess that module-level fix(es) would be appreciated anyway.

We do plan to make this change. We held off on pushing out a new version with this change because it will be a breaking change for apps that are still using flutter 2.8.1 and have kotlin_version set to 1.3.50 (which was the default as recently as flutter 2.8.1). We'll discuss getting a new version out internally and get back to you as soon as we can.

Thanks for working through this with us.

@Jordan-Nelson
Copy link
Contributor

@alod2019 - We are planning to include the kotlin version bump in amplify_flutter 0.4.x since it will be breaking for those on older versions. We are aiming to have a release-candidate of 0.4.x out in the next day or so. I will update this issue when it is available.

@Jordan-Nelson
Copy link
Contributor

@alod2019 - version 0.4.0-rc.1 of amplify flutter was just released. It includes the kotlin version bump. Would you be willing to try this out and confirm it resolves your issue?

If you use amplify_api, there was one breaking change in this release. The response from graphql mutations is now nullable. You can read more about that here.

@alod2019
Copy link
Author

alod2019 commented Feb 14, 2022

@Jordan-Nelson

Would you be willing to try this out and confirm it resolves your issue?

At a moment I can only confirm that there are no errors caused by amplify 0.4.0-rc.1 dependencies in my build log.
But that unveiled the same issue with other vendors plugins so eventually I was forced to enable Kotlin in my project.
Thanks anyway!

@dorontal
Copy link

Had this too, followed this website that told me to change the version in android/build.gradle to latest (1.6.10) and that fix immediately worked.

@abasu0713
Copy link

abasu0713 commented Feb 25, 2022

Hi guys. I recently upgraded all packages.
This is my pubspec.yaml file.

name: data_dashboard
description: Data visualization dashboard

# The following line prevents the package from being accidentally published to
# pub.dev using `flutter pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev

# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1

environment:
  sdk: ">=2.14.4 <3.0.0"

# Dependencies specify other packages that your package needs in order to work.
# To automatically upgrade your package dependencies to the latest versions
# consider running `flutter pub upgrade --major-versions`. Alternatively,
# dependencies can be manually updated by changing the version numbers below to
# the latest version available on pub.dev. To see which dependencies have newer
# versions available, run `flutter pub outdated`.
dependencies:
  flutter:
    sdk: flutter


  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  amplify_flutter: ^0.3.2
  amplify_auth_cognito: ^0.3.2
  amplify_storage_s3: ^0.3.1
  provider: ^6.0.1
  shared_preferences: ^2.0.8
  amplify_api: ^0.3.1
  aws_lambda_api:
    git:
      url: https://github.com/agilord/aws_client.git
      path: generated/aws_lambda_api
  charts_flutter: ^0.12.0
  path_provider: ^2.0.8
  amplify_authenticator: ^0.1.0-rc.3
  property_change_notifier: ^0.3.0
  google_fonts: ^2.2.0
  simple_speed_dial: ^0.1.3
  

dev_dependencies:
  flutter_test:
    sdk: flutter

  # The "flutter_lints" package below contains a set of recommended lints to
  # encourage good coding practices. The lint set provided by the package is
  # activated in the `analysis_options.yaml` file located at the root of your
  # package. See that file for information about deactivating specific lint
  # rules and activating additional ones.
  flutter_lints: ^1.0.0

# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec

# The following section is specific to Flutter.
flutter:

  # The following line ensures that the Material Icons font is
  # included with your application, so that you can use the icons in
  # the material Icons class.
  uses-material-design: true

#  assets:
#    - path/to/asset

  # An image asset can refer to one or more resolution-specific "variants", see
  # https://flutter.dev/assets-and-images/#resolution-aware.

  # For details regarding adding assets from package dependencies, see
  # https://flutter.dev/assets-and-images/#from-packages

  # To add custom fonts to your application, add a fonts section here,
  # in this "flutter" section. Each entry in this list should have a
  # "family" key with the font family name, and a "fonts" key with a
  # list giving the asset and other descriptors for the font. For
  # example:
  # fonts:
  #   - family: Schyler
  #     fonts:
  #       - asset: fonts/Schyler-Regular.ttf
  #       - asset: fonts/Schyler-Italic.ttf
  #         style: italic
  #   - family: Trajan Pro
  #     fonts:
  #       - asset: fonts/TrajanPro.ttf
  #       - asset: fonts/TrajanPro_Bold.ttf
  #         weight: 700
  #
  # For details regarding fonts from package dependencies,
  # see https://flutter.dev/custom-fonts/#from-packages

And i keep getting this error. My plugin and gradle dependencies seems to be good as shown in the documentation link. I am currently at:

$ ./gradlew --version
------------------------------------------------------------
Gradle 7.0.2
------------------------------------------------------------

Build time:   2021-05-14 12:02:31 UTC
Revision:     1ef1b260d39daacbf9357f9d8594a8a743e2152e

Kotlin:       1.4.31
Groovy:       3.0.7
Ant:          Apache Ant(TM) version 1.10.9 compiled on September 27 2020
JVM:          17.0.2 (Oracle Corporation 17.0.2+8-LTS-86)
OS:           Windows 10 10.0 amd64

[        ] > Task :amplify_flutter:compileDebugAidl NO-SOURCE
[        ] > Task :amplify_flutter:mergeDebugJniLibFolders
[        ] > Task :amplify_flutter:mergeDebugNativeLibs NO-SOURCE
[   +2 ms] > Task :amplify_flutter:stripDebugDebugSymbols NO-SOURCE
[   +1 ms] > Task :amplify_flutter:copyDebugJniLibsProjectAndLocalJars
[ +288 ms] > Task :amplify_api:generateDebugRFile
[+2495 ms] > Task :amplify_core:compileDebugKotlin FAILED
[   +1 ms] Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
[        ] Use '--warning-mode all' to show the individual deprecation warnings.
[        ] See https://docs.gradle.org/7.0.2/userguide/command_line_interface.html#sec:command_line_warnings
[        ] 50 actionable tasks: 50 executed
[        ] e: C:\Users\Arko Basu\AppData\Local\Pub\Cache\hosted\pub.dartlang.org\amplify_core-0.3.2\android\src\main\kotlin\com\amazonaws\amplify\amplify_core\AtomicResult.kt: (26, 1):
Class 'AtomicResult' is not abstract and does not implement abstract member public abstract fun error(p0: String, p1: String?, p2: Any?): Unit defined in
io.flutter.plugin.common.MethodChannel.Result
[   +1 ms] e: C:\Users\Arko Basu\AppData\Local\Pub\Cache\hosted\pub.dartlang.org\amplify_core-0.3.2\android\src\main\kotlin\com\amazonaws\amplify\amplify_core\AtomicResult.kt: (54, 5):
'error' overrides nothing
[        ] e: C:\Users\Arko Basu\AppData\Local\Pub\Cache\hosted\pub.dartlang.org\amplify_core-0.3.2\android\src\main\kotlin\com\amazonaws\amplify\amplify_core\AtomicResult.kt: (66,
26): Type mismatch: inferred type is String? but String was expected
[        ] FAILURE: Build failed with an exception.
[        ] * What went wrong:
[        ] Execution failed for task ':amplify_core:compileDebugKotlin'.
[        ] > Compilation error. See log for more details
[        ] * Try:
[        ] Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
[        ] * Get more help at https://help.gradle.org
[        ] BUILD FAILED in 2m 4s
[ +585 ms] Running Gradle task 'assembleDebug'... (completed in 124.9s)
[   +8 ms] Exception: Gradle task assembleDebug failed with exit code 1
[   +2 ms] "flutter run" took 150,221ms.
[  +10 ms] 
           #0      throwToolExit (package:flutter_tools/src/base/common.dart:10:3)
           #1      RunCommand.runCommand (package:flutter_tools/src/commands/run.dart:688:9)
           <asynchronous suspension>
           #2      FlutterCommand.run.<anonymous closure> (package:flutter_tools/src/runner/flutter_command.dart:1165:27)
           <asynchronous suspension>
           #3      AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
           <asynchronous suspension>
           #4      CommandRunner.runCommand (package:args/command_runner.dart:209:13)
           <asynchronous suspension>
           #5      FlutterCommandRunner.runCommand.<anonymous closure> (package:flutter_tools/src/runner/flutter_command_runner.dart:281:9)
           <asynchronous suspension>
           #6      AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
           <asynchronous suspension>
           #7      FlutterCommandRunner.runCommand (package:flutter_tools/src/runner/flutter_command_runner.dart:229:5)
           <asynchronous suspension>
           #8      run.<anonymous closure>.<anonymous closure> (package:flutter_tools/runner.dart:62:9)
           <asynchronous suspension>
           #9      AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
           <asynchronous suspension>
           #10     main (package:flutter_tools/executable.dart:94:3)
           <asynchronous suspension>
           
           
[ +188 ms] ensureAnalyticsSent: 180ms
[   +4 ms] Running shutdown hooks
[   +1 ms] Shutdown hooks complete
[   +1 ms] exiting with code 1

C:\Users\Arko Basu\workspace\Dephy\data_dashboard>

I have even tried reverting the pubspec.yaml to an old version that worked just fine.. But I can't seem to build. Would really appreciate any help.

Notes of dev environment:

@abdallahshaban557
Copy link
Contributor

@abasu0713 - Hello! Can you please submit another Github issue regarding this, please use our Github issue template. It has been a while since we have talked, I hope your project has been going well!

@abasu0713
Copy link

@abdallahshaban557 Hiya! It's so good to read from you. It is.. Thank you. :)
And yes! I will. I actually might have figured out what the issue is. I will put another hour and if I can't get it running, I will be sure to create a separate ticket. Thanks

@Jordan-Nelson Jordan-Nelson added this to Pending Triage in Issues Triaging via automation Mar 11, 2022
@Jordan-Nelson
Copy link
Contributor

Closing this issue out as it was resolved in 0.4.0. You can see this comment for a work around that doesn't require upgrading to 0.4.0.

Issues Triaging automation moved this from Pending Triage to Closed Mar 11, 2022
@Jordan-Nelson Jordan-Nelson unpinned this issue Mar 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is not working; the issue has reproducible steps and has been reproduced Build Issues related to building apps using Amplify flutter
Projects
No open projects
Development

No branches or pull requests

8 participants