fluttercommunity / plus_plugins

Flutter Community Plus Plugins
BSD 3-Clause "New" or "Revised" License
1.55k stars 938 forks source link

[Bug]: flutter run error from #3142

Open madmanleaf opened 1 month ago

madmanleaf commented 1 month ago

Platform

Android 15

Plugin

package_info_plus

Version

8.0.1

Flutter SDK

3.24.0-0.2.pre

Steps to reproduce

Unless it is not applicable, the error is always reported

Code Sample

import 'dart:ui';
import 'package:get/get.dart';
// import 'package:package_info_plus/package_info_plus.dart';
import '../index.dart';

/// 配置服务
class ConfigService extends GetxService {
  static ConfigService get to => Get.find();
  final Rx<Locale> _locale = PlatformDispatcher.instance.locale.obs;
  Locale get locale => _locale.value;
  // PackageInfo? _platform;
  // String get version => _platform?.version ?? '-';

  // 主题
  final RxBool _isDarkModel = Get.isDarkMode.obs;
  bool get isDarkModel => _isDarkModel.value;

  // 是否首次打开
  bool get isAlreadyOpen => Storage().getBool(Constants.storageAlreadyOpen);

  @override
  void onReady() {
    super.onReady();
    // getPlatform();
    initLocale();
    initTheme();
  }

  // 标记已打开app
  void setAlreadyOpen() {
    Storage().setBool(Constants.storageAlreadyOpen, true);
  }

  // Future<void> getPlatform() async {
  //   _platform = await PackageInfo.fromPlatform();
  // }
  // 切换 theme主题
  Future<void> switchThemeModel() async {
    _isDarkModel.value = !_isDarkModel.value;
    Get.changeTheme(
      _isDarkModel.value == true ? AppTheme.dark : AppTheme.light,
    );
    await Storage().setString(Constants.storageThemeCode,
        _isDarkModel.value == true ? "dark" : "light");
  }

  // 初始 theme主题
  void initTheme() {
    var themeCode = Storage().getString(Constants.storageThemeCode);
    _isDarkModel.value = themeCode == "dark" ? true : false;
    Get.changeTheme(
      themeCode == "dark" ? AppTheme.dark : AppTheme.light,
    );
  }

  // 初始语言
  void initLocale() {
    var langCode = Storage().getString(Constants.storageLanguageCode);
    if (langCode.isEmpty) return;
    var index = Translation.supportedLocales.indexWhere((element) {
      return element.languageCode == langCode;
    });
    if (index < 0) return;
    _locale.value = Translation.supportedLocales[index];
  }

  // 更新语言
  void updateLanguage(Locale newLocale) {
    _locale.value = newLocale;
    Storage().setString(Constants.storageLanguageCode, newLocale.languageCode);
    Get.updateLocale(newLocale);
  }

}

Logs

[        ] FAILURE: Build failed with an exception.
[        ] * What went wrong:
[        ] Execution failed for task ':package_info_plus:compileDebugJavaWithJavac'.
[        ] > Could not resolve all files for configuration ':package_info_plus: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: C:\Users\madma\AppData\Local\Android\Sdk\platforms\android-34\core-for-system-modules.jar.
[        ]          > Error while executing process D:\Program\JetBrains\Android Studio\jbr\bin\jlink.exe with arguments {--module-path C:\Users\madma\.gradle\caches\8.9\transforms\15cf82747c839484d9461063b2aa76df-bec856da-5605-4eea-9f72-2b794a79b08f\transformed\output\temp\jmod --add-modules java.base --output C:\Users\madma\.gradle\caches\8.9\transforms\15cf82747c839484d9461063b2aa76df-bec856da-5605-4eea-9f72-2b794a79b08f\transformed\output\jdkImage --disable-plugin system-modules}
[        ] * Try:
[        ] > Run with --debug option to get more log output.
[        ] > Run with --scan to get full insights.
[        ] > Get more help at https://help.gradle.org.

Flutter Doctor

PS C:\Users\madma> flutter doctor -v
[✓] Flutter (Channel beta, 3.24.0-0.2.pre, on Microsoft Windows [版本 10.0.26120.1330], locale zh-CN)
    • Flutter version 3.24.0-0.2.pre on channel beta at D:\code\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 7c6b7e9ca4 (4 days ago), 2024-07-30 14:26:44 +0700
    • Engine revision 6e4deceb38
    • Dart version 3.5.0 (build 3.5.0-323.2.beta)
    • DevTools version 2.37.2

[✓] Windows Version (Installed version of Windows is version 10 or higher)

[!] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
    • Android SDK at C:\Users\madma\AppData\Local\Android\Sdk
    • Platform android-35, build-tools 35.0.0
    • ANDROID_HOME = C:\Users\madma\AppData\Local\Android\Sdk
    • Java binary at: D:\Program\JetBrains\Android Studio\jbr\bin\java
    • Java version OpenJDK Runtime Environment (build 21.0.3+-12099254-b509.4)
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/to/windows-android-setup for more details.

[✓] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[✓] Visual Studio - develop Windows apps (Visual Studio Enterprise 2022 17.8.0 Preview 1.0)
    • Visual Studio at D:\Program Files\Microsoft Visual Studio\2022\Preview
    • Visual Studio Enterprise 2022 version 17.8.34004.107
    • The current Visual Studio installation is a pre-release version. It may not be supported by Flutter yet.
    • Windows 10 SDK version 10.0.22621.0

[✓] Android Studio (version 2024.1)
    • Android Studio at D:\Program\JetBrains\Android Studio 2
    • 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 17.0.10+0--11609105)

[✓] Android Studio (version 2024.2)
    • Android Studio at D:\Program\JetBrains\Android Studio
    • 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+-12099254-b509.4)

[✓] VS Code, 64-bit edition (version unknown)
    • VS Code at C:\Program Files\Microsoft VS Code Insiders
    • Flutter extension version 3.93.20240702
    ✗ Unable to determine VS Code version.

[✓] Connected device (4 available)
    • sdk gphone64 x86 64 (mobile) • emulator-5554 • android-x64    • Android 15 (API 35) (emulator)
    • Windows (desktop)            • windows       • windows-x64    • Microsoft Windows [版本 10.0.26120.1330]
    • Chrome (web)                 • chrome        • web-javascript • Google Chrome 127.0.6533.89
    • Edge (web)                   • edge          • web-javascript • Microsoft Edge 128.0.2739.5

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

! Doctor found issues in 1 category.

Checklist before submitting a bug

ihancock commented 1 month ago

Facing similar issues with 3.24 It appears the plugin needs the build.gradle and settings.gradle updated to the new flutter way of building. The exact error is: - Execution failed for task ':device_info:verifyReleaseResources'.

A failure occurred while executing com.android.build.gradle.tasks.VerifyLibraryResourcesTask$Action Android resource linking failed ERROR:/Users/ian.hancock/IdeaProjects/SecureFlutter/flutter_app/build/device_info/intermediates/merged_res/release/values/values.xml:194: AAPT: error: resource android:attr/lStar not found.

This indicated it is not compatible with Android platform 31 Ad support.

miquelbeltran commented 1 month ago

I cannot reproduce the issue, the example project builds for me on Flutter 3.24.0.

 flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.24.0, on Ubuntu 24.04 LTS 6.8.0-39-generic, locale en_US.UTF-8)
[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
[✓] Chrome - develop for the web
[✓] Linux toolchain - develop for Linux desktop
[✓] Android Studio (version 2024.1)
[✓] IntelliJ IDEA Ultimate Edition (version 2024.2)
[✓] VS Code (version 1.92.0)
[✓] Connected device (2 available)
[✓] Network resources

Compiled using melos run build:example_android:

  └> melos exec -c 6 --fail-fast -- \
       "flutter build apk --no-pub"
     └> RUNNING

Select a package to run the build:example_android script:

1) * [Default - Press Enter]
2) android_alarm_manager_plus_example
3) android_intent_plus_example
4) battery_plus_example
5) connectivity_plus_example
6) device_info_plus_example
7) network_info_plus_example
8) package_info_plus_example
9) sensors_plus_example
10) share_plus_example

✔ Enter your choice 8
$ melos exec
  └> flutter build apk --no-pub
     └> RUNNING (in 1 packages)

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
package_info_plus_example:

Running Gradle task 'assembleRelease'...                        
Checking the license for package Android SDK Build-Tools 34 in /home/miquel/Android/Sdk/licenses
License for package Android SDK Build-Tools 34 accepted.
Preparing "Install Android SDK Build-Tools 34 v.34.0.0".
"Install Android SDK Build-Tools 34 v.34.0.0" ready.
Installing Android SDK Build-Tools 34 in /home/miquel/Android/Sdk/build-tools/34.0.0
"Install Android SDK Build-Tools 34 v.34.0.0" complete.
"Install Android SDK Build-Tools 34 v.34.0.0" finished.
Font asset "MaterialIcons-Regular.otf" was tree-shaken, reducing it from 1645184 to 1324 bytes (99.9% reduction). Tree-shaking can be disabled by providing the --no-tree-shake-icons flag when building your app.
Generating lint files for backported methods only (compile API B)
Running Gradle task 'assembleRelease'...                          122.0s
✓ Built build/app/outputs/flutter-apk/app-release.apk (19.1MB)
package_info_plus_example: SUCCESS
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------

$ melos exec
  └> flutter build apk --no-pub
     └> SUCCESS

melos run build:example_android
  └> melos exec -c 6 --fail-fast -- \
       "flutter build apk --no-pub"
     └> SUCCESS
ihancock commented 1 month ago

OK let me strip the compile down to a simpler app and see if I can get to the bottom of it, I think something changed in the gradle build that is breaking it, maybe something missed when I upgraded our main app. I will report back after some testing

ihancock commented 1 month ago

I could also build your example app just find but not any other app using the plugin. I recreated the issue with another simple plugin using your gradle files and was able to reproduce the issue again. Adding the following to the apps main build.gradle resolves the issue: -

ext { androidCore = "1.6.0" }

you can also add in your plugins build.gradle the following, which also resolves the issue: -

configurations.all { resolutionStrategy { force 'androidx.core:core:1.6.0' force 'androidx.core:core-ktx:1.6.0' } }

miquelbeltran commented 1 month ago

I could also build your example app just find but not any other app using the plugin.

I also tested on a newly created project:

$ flutter create check_build

$ cd check_build

$ flutter pub add package_info_plus

$ flutter build apk --debug

...

Running Gradle task 'assembleDebug'...                             55.5s
✓ Built build/app/outputs/flutter-apk/app-debug.apk
ihancock commented 1 month ago

Yeah I think it only affects projects built in older flutter versions, even when updating their Gradle builds. There is for sure some breaking change that is not documented (or at least I can't find it) with 3.24. I am doing some more digging with our own internal plugins to see if I can get to the root of it.

ihancock commented 1 month ago

OK found the breaking change that does it, which is why newer apps work off the bat. Applying this to the application makes everything work: - https://docs.flutter.dev/release/breaking-changes/flutter-gradle-plugin-apply

This does not require setting android core version. Thanks for your help, it helped point me to the correct solution and fixed the 'stop using imperative build in Gradle messages that have been on my todo list for a while ;-)

miquelbeltran commented 1 month ago

Thanks for the link! I wasn't aware of it, it will come handy for people with Android compilation issues.