如何解决 android 元数据为 1.9.0,预期版本为 1.7.1 的 flutter 应用程序构建失败问题?

问题描述 投票:0回答:1

我已经按照这个answer尝试解决这个问题,但没有成功。

构建在 iOS 模拟器上 100% 运行,但在 Android 模拟器上失败,如下所示:

The class is loaded from .gradle/caches/transforms-3/c3f0666cf8984b118654915928619821/transformed/jetified-kotlin-stdlib-1.9.0.jar!/kotlin/Unit.class
e: .pub-cache/hosted/pub.dev/stripe_android-9.6.0+2/android/src/main/kotlin/com/reactnativestripesdk/utils/Mappers.kt: (926, 7): Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.9.0, expected version is 1.7.1.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':stripe_android:compileDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction
   > 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 1m 33s

┌─ Flutter Fix ──────────────────────────────────────────────────────────────────────────────┐
│ [!] Your project requires a newer version of the Kotlin Gradle plugin.                     │
│ Find the latest version on https://kotlinlang.org/docs/releases.html#release-details, then │
│ update /wwwdir/doclink_ios/android/build.gradle:                         │
│ ext.kotlin_version = '<latest-version>'                                                    │
└────────────────────────────────────────────────────────────────────────────────────────────┘
Error: Gradle task assembleDebug failed with exit code 1

build.gradle 文件:

buildscript {
    ext.kotlin_version = '1.9.20'
    repositories {
        google()
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:7.4.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.3.15'
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

tasks.register("clean", Delete) {
    delete rootProject.buildDir
}

pubspec.yaml 文件:

name: doclink
description: A new Flutter project.

# 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 is used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix.
version: 1.0.1

environment:
  sdk: '>=2.18.5 <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`.
dependency_overrides:
  intl: ^0.18.1
  package_info_plus: ^4.0.1
  http: ^1.0.0

dependencies:
  flutter:
    sdk: flutter
  flutter_localizations:
    sdk: flutter


  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^1.0.6

  firebase_core: ^2.4.1
  cloud_firestore: ^4.4.5
  firebase_messaging: ^14.5.0

  #------------  Service, Permission, Video, Image, State Management ------------#
  intl: ^0.17.0
  get: ^4.6.5
  permission_handler: ^10.2.0
  agora_rtc_engine: ^6.2.2
  shared_preferences: ^2.0.17
  image_picker: ^0.8.6+1
  video_thumbnail: ^0.5.3
  webview_flutter: ^4.4.4
  video_player: ^2.6.0
  timezone: ^0.9.1

  #------------  Google map ------------#
  google_maps_flutter: ^2.2.3
  geolocator: ^9.0.2

  #------------  UI ------------#
  intl_phone_number_input: ^0.7.2
  dotted_border: ^2.0.0+3
  table_calendar: ^3.0.8
  syncfusion_flutter_charts: ^20.4.38
  cached_network_image: ^3.2.3
  qr_code_scanner: ^1.0.1
  url_launcher: ^6.1.10
  flutter_rating_bar: ^4.0.1
  shimmer: ^2.0.0
  photo_view: ^0.14.0
  collection: ^1.17.0

  #------------  Notification ------------#
  flutter_local_notifications: ^14.0.0+1
  flutter_app_badger: ^1.5.0
  qr_flutter: ^4.1.0
  open_filex: ^4.3.4
  syncfusion_flutter_pdf: ^20.4.54
  flutter_stripe: ^9.4.0
  razorpay_flutter: ^1.3.5
  flutterwave_standard: ^1.0.8
  toggle_switch: ^2.1.0
  multiselect: ^0.1.0
  firebase_analytics: ^10.7.1
  signature: ^5.4.1
  device_preview: ^1.1.0
  flutter_paystack: ^1.0.7
  flutter_paypal: ^0.2.0
  firebase_auth: ^4.16.0
  

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: ^2.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 packages.
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
  generate: true
  # To add assets to your application, add an assets section, like this:
  assets:
    - assets/
    - assets/icon/
    - assets/image/
    - assets/json/

  # 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: black
      fonts:
        - asset: assets/fonts/Montserrat-Black.ttf
    - family: bold
      fonts:
        - asset: assets/fonts/Montserrat-Bold.ttf
    - family: extraBold
      fonts:
        - asset: assets/fonts/Montserrat-ExtraBold.ttf
    - family: extraLight
      fonts:
        - asset: assets/fonts/Montserrat-ExtraLight.ttf
    - family: light
      fonts:
        - asset: assets/fonts/Montserrat-Light.ttf
    - family: medium
      fonts:
        - asset: assets/fonts/Montserrat-Medium.ttf
    - family: regular
      fonts:
        - asset: assets/fonts/Montserrat-Regular.ttf
    - family: semiBold
      fonts:
        - asset: assets/fonts/Montserrat-SemiBold.ttf
    - family: thin
      fonts:
        - asset: assets/fonts/Montserrat-Thin.ttf



  # For details regarding fonts from package dependencies,
  # see https://flutter.dev/custom-fonts/#from-packages
flutter_intl:
  enabled: true

我希望有人能够就如何解决此问题提供建议或反馈。

android flutter kotlin gradle
1个回答
0
投票

你可以试试

  • 在 android studio 中打开 flutterApp/android 文件夹

Mac 版

  • 奔跑
    ./gradlew cleanBuildCache

在 Windows 上:

  • 奔跑

    gradlew cleanBuildCache

  • 使缓存无效。

让你的 gradle 同步

© www.soinside.com 2019 - 2024. All rights reserved.