Как отключить совместимость источника/цели Java 8 в приложении Flutter/AndroidAndroid

Форум для тех, кто программирует под Android
Ответить
Anonymous
 Как отключить совместимость источника/цели Java 8 в приложении Flutter/Android

Сообщение Anonymous »

Я только что создал новое приложение Flutter с помощью flutter createtutorial_flutter_redux_navigation --platforms android --empty. Вот некоторая информация, которая, я думаю, будет полезна для контекста моего вопроса.
flutter Doctor -v:

Код: Выделить всё

[✓] Flutter (Channel stable, 3.24.4, on macOS 15.0.1 24A348 darwin-arm64, locale en-US)
• Flutter version 3.24.4 on channel stable at /Users/axiopisty/apps/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 603104015d (9 days ago), 2024-10-24 08:01:25 -0700
• Engine revision db49896cf2
• Dart version 3.5.4
• DevTools version 2.37.3

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
• Android SDK at /Users/axiopisty/Library/Android/sdk
• Platform android-34, build-tools 34.0.0
• Java binary at: /Users/axiopisty/Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 21.0.3+-79915917-b509.11)
• All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 16.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 16B40
• CocoaPods version 1.15.0

[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2024.2)
• Android Studio at /Users/axiopisty/Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 21.0.3+-79915917-b509.11)

[✓] IntelliJ IDEA Ultimate Edition (version 2024.2.4)
• IntelliJ at /Users/axiopisty/Applications/IntelliJ IDEA Ultimate.app
• Flutter plugin version 82.0.3
• Dart plugin version 242.22855.32

[✓] Connected device (4 available)
• XQ DQ62 (mobile)                • QV7702KBJA            • android-arm64  • Android 14 (API 34)
• macOS (desktop)                 • macos                 • darwin-arm64   • macOS 15.0.1 24A348 darwin-arm64
• Mac Designed for iPad (desktop) • mac-designed-for-ipad • darwin         • macOS 15.0.1 24A348 darwin-arm64
• Chrome (web)                    • chrome                • web-javascript • Google Chrome 130.0.6723.92

[✓] Network resources
• All expected network resources are available.

• No issues found!
gradle-wrapper.properties:

Код: Выделить всё

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

Код: Выделить всё

plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
id "com.android.application" version "8.1.0" apply false
id "org.jetbrains.kotlin.android" version "1.8.22"  apply false
}
gradle.properties:

Код: Выделить всё

org.gradle.jvmargs=-Xmx4G -XX:MaxMetaspaceSize=2G -XX:+HeapDumpOnOutOfMemoryError
android.useAndroidX=true
android.enableJetifier=true
android/build.gradle:

Код: Выделить всё

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
}
android/app/build.gradle:

Код: Выделить всё

plugins {
id "com.android.application"
id "kotlin-android"
// The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
id "dev.flutter.flutter-gradle-plugin"
}

android {

def javaVersion = JavaVersion.VERSION_1_8

namespace = "com.github.axiopisty.tutorial_flutter_redux_navigation"
compileSdk = flutter.compileSdkVersion
ndkVersion = flutter.ndkVersion

compileOptions {
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
}

kotlinOptions {
jvmTarget = javaVersion
}

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId = "com.github.axiopisty.tutorial_flutter_redux_navigation"
// You can update the following values to match your application needs.
// For more information, see: https://flutter.dev/to/review-gradle-config.
minSdk = flutter.minSdkVersion
targetSdk = flutter.targetSdkVersion
versionCode = flutter.versionCode
versionName = flutter.versionName
}

buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig = signingConfigs.debug
}
}
}

flutter {
source = "../.."
}
Когда я собираю и запускаю приложение в отладчике, я вижу это сообщение:

Код: Выделить всё

Running Gradle task 'assembleDebug'...
warning: [options] source value 8 is obsolete and will be removed in a future release
warning: [options] target value 8 is obsolete and will be removed in a future release
warning: [options] To suppress warnings about obsolete options, use -Xlint:-options.
3 warnings
Мне неясно, что именно вызывает отображение этого предупреждения, но я думаю, что это связано с совместимостью источника/цели, настроенной в android/app/build.gradle
code>, который имеет следующие определения:

Код: Выделить всё

android {
...
def javaVersion = JavaVersion.VERSION_1_8
compileOptions {
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
}

kotlinOptions {
jvmTarget = javaVersion
}
...
}
Желая исправить/удалить предупреждения об устаревании, появляющиеся в журналах сборки, я попытался обновить javaVersion с JavaVersion.VERSION_1_8 до любой версии выше 1.8. Но в результате это предупреждение о времени сборки в журналах заменяется ошибкой, которая препятствует запуску приложения. Например, если я обновлю javaVersion до JavaVersion.VERSION_11, я увижу следующее сообщение об ошибке:

Код: Выделить всё

Running Gradle task 'assembleDebug'...

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Could not resolve all files for configuration ':app:androidJdkImage'.
> Failed to transform core-for-system-modules.jar to match attributes {artifactType=_internal_android_jdk_image, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime}.
> Execution failed for JdkImageTransform: /Users/axiopisty/Library/Android/sdk/platforms/android-34/core-for-system-modules.jar.
> Error while executing process /Users/axiopisty/Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/jlink with arguments {--module-path /Users/axiopisty/.gradle/caches/transforms-3/d9e926982c2c139ff9125eb7b6be4144/transformed/output/temp/jmod --add-modules java.base --output /Users/axiopisty/.gradle/caches/transforms-3/d9e926982c2c139ff9125eb7b6be4144/transformed/output/jdkImage --disable-plugin system-modules}

Учитывая эту информацию, я знаю, что могу просто смириться с предупреждением об устаревании в журналах сборки и оставить все в покое (пока). По крайней мере, он строится успешно. Но когда я вижу предупреждения в журналах сборки, мне нравится обращаться к ним, чтобы убедиться, что мое приложение готово к будущим обновлениям/обновлениям.
Мой вопрос: что нужно сделать? что нужно сделать в моем проекте, чтобы отказаться от совместимости источника/цели Java 8, чтобы устранить предупреждения в журнале сборки? В последней версии Android Studio для сборки проекта используется Java 21. Мне не нужен флаг, который можно передать в качестве аргумента сборке для подавления предупреждения.

Подробнее здесь: https://stackoverflow.com/questions/791 ... -applicati
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Android»