我已经遵循了这answertry 解决这个问题,但没有运气.

该构建在iOS模拟器上100%正常运行,但在Android Emulator上失败,具体如下:

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

我希望有人能就如何解决这个问题提供建议或反馈.

推荐答案

1. Update Stripe

更新pubspec.yaml文件中的Flutter Stripe版本,您只需更改版本号flutter_stripe依赖性即可.基于提供的pubspec.yaml,当前版本#9.4.0.更新最新可用版本:

dependencies:
  ...
  flutter_stripe: ^10.1.0
  ...

这将更新Flutter Stripe包版本10.1.0.更新pubspec.yaml文件后,在您的终端中运行flutter pub get获取更新包的最新版本.

2. Kotlin Update

关于Build.gradle文件中的Kotlin版本更新Gradle依赖项:

在您的Build.gradle文件中,您已将Kotlin版本定义为1.9.20:

ext.kotlin_version = '1.9.20'

该变量用于指定Gradle的Kotlin插件版本,该插件应用了项目.Kotlin插件允许您在Android项目中使用Kotlin代码.

3. Build Gradle update

更新com.android.tools.build:gradle:

com.android.tools.build:Build.gradle中的gradle依赖关系对于使用Gradle构建Android应用程序至关重要.

您已为此依赖项指定了7.4.2版本:

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

该依赖项提供Android Gradle插件,负责编译代码、打包APK、管理Android项目中的依赖项等任务.

您需要更新它gradle版本8.


4. Java Update

Unsupported class file major version 65

原因:wrong java version being used.

还要将Java版本21降级至17.如何?参考这link

需要正确的Java版本,以下是列表:

Java SE 22 = 66,
Java SE 21 = 65,
Java SE 20 = 64,
Java SE 19 = 63,
Java SE 18 = 62,
Java SE 17 = 61,
Java SE 16 = 60, 
Java SE 15 = 59,
Java SE 14 = 58,
Java SE 13 = 57,
Java SE 12 = 56,
Java SE 11 = 55,
Java SE 10 = 54,
Java SE 9 = 53,
Java SE 8 = 52

更新 2 :

解释id "org.jetbrains.kotlin.android" version "1.9.0" apply false

这就是here提到的插件模式

如果您有多项目构建,您可能想要应用插件 扩展到构建中的部分或所有子项目,但不扩展到根项目 或主项目.插件{}块的默认行为是 立即解决并应用插件.但是,您可以使用应用程序 错误语法告诉Gradle不要将插件应用于当前 项目,然后在子项目中使用apply plugin:«plugin id» 阻止或使用子项目构建脚本中的插件{}阻止:其中 gradlePlugins.values()策略大概会迫使它们 立即从根本上解决了.



根据Flutter stripe份文件.他们在5个月前更新了Java版本、gradle版本和Kotlin版本.参考这link

1. Mentioned to use kotlin 1.8 or higher

https://github.com/flutter-stripe/flutter_stripe/blob/7f95fcb83b5434f7bf4b5aa24ea77263d1af55ad/example/android/build.gradle#L2

2. Mentioned to use java 17

https://github.com/flutter-stripe/flutter_stripe/blob/main/example/android/app/build.gradle#L33

3. Mentioned to use gradle 8

https://github.com/flutter-stripe/flutter_stripe/blob/7f95fcb83b5434f7bf4b5aa24ea77263d1af55ad/example/android/gradle/wrapper/gradle-wrapper.properties#L4


更新 3

根据当前Senario,您遵循的答案已经超过2年了,并且已经过时.它使用kotlin版本1.6、gradle构建插件4.1和jdk 7.

Flutter相关问答推荐

如何在应用栏中将列置于中心

类型int不是可迭代动态tmdbapi类型的子类型<>

无效字符(位于字符68处)flutter—update—... europe-west1.firebasedatabase.app/

将图标呈现在Flutter 克牌小工具的角落上

就像Flutter 中的头文件一样?

GridView 渲染项目之间有微小的间隙

自定义类提供程序 Riverpod Flutter 中的可变变量

在 Flutter 中显示有关提供者通知的对话框

Container 的 Flutter 背景图片不会出现

如何从另一个页面访问 Firebase 值?

如何使这种相机叠加在Flutter 中?

Riverpod 在使用冻结副本更新状态时触发重建,即使没有任何更改

在 flutter 中自定义 agora 视频通话 UI

Flutter Firestore 数据库排序最近 24 小时内最喜欢的文档

Flutter - 检测手指何时进入容器

Flutter 平台通道将多数据传递给 windows 功能

阴影效果只出现在一张卡片的左边 在Flutter 中?

如何在没有上下文的情况下使用国际Flutter ?

Flutter audioplayers错误-单击音频按钮时不播放音频

Flutter - 如何调用此函数?