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

Flutter apk Build Error #1

Closed
0x3639 opened this issue May 14, 2024 · 5 comments
Closed

Flutter apk Build Error #1

0x3639 opened this issue May 14, 2024 · 5 comments

Comments

@0x3639
Copy link

0x3639 commented May 14, 2024

I tried to build with

flutter pub get

then

flutter build apk --release

And got the following errors.

UPDATE: Looks like I'm missing some android components. I will try to install them.

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.22.0, on macOS 14.3.1 23D60 darwin-arm64, locale en-US)
[!] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    ✗ cmdline-tools component is missing
      Run `path/to/sdkmanager --install "cmdline-tools;latest"`
      See https://developer.android.com/studio/command-line for more details.
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/macos#android-setup for more details.
[✗] Xcode - develop for iOS and macOS
    ✗ Xcode installation is incomplete; a full installation is necessary for iOS and macOS development.
      Download at: https://developer.apple.com/xcode/
      Or install Xcode via the App Store.
      Once installed, run:
        sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
        sudo xcodebuild -runFirstLaunch
    ✗ CocoaPods not installed.
        CocoaPods is used to retrieve the iOS and macOS platform side's plugin code that responds to your plugin usage on the Dart side.
        Without CocoaPods, plugins will not work on iOS or macOS.
        For more info, see https://flutter.dev/platform-plugins
      To install see https://guides.cocoapods.org/using/getting-started.html#installation for instructions.
[✓] Chrome - develop for the web
[!] Android Studio (not installed)
[✓] VS Code (version 1.88.1)
[✓] Connected device (2 available)
[✓] Network resources
flutter build apk --release                                                                                 ok  18s  06:53:49 PM



FAILURE: Build failed with an exception.

* What went wrong:
Could not resolve all files for configuration 'classpath'.
> Could not resolve com.android.tools.build:gradle:7.4.2.
  Required by:
      unspecified:unspecified:unspecified > com.android.application:com.android.application.gradle.plugin:7.4.2
   > No matching variant of com.android.tools.build:gradle:7.4.2 was found. The consumer was configured to find a runtime of a library compatible with Java 8, packaged as a jar, and its dependencies declared externally, as well as attribute 'org.gradle.plugin.api-version' with value '7.5' but:
       - Variant 'apiElements' capability com.android.tools.build:gradle:7.4.2 declares a library, packaged as a jar, and its dependencies declared externally:
           - Incompatible because this component declares an API of a component compatible with Java 11 and the consumer needed a runtime of a component compatible with Java 8
           - Other compatible attribute:
               - Doesn't say anything about org.gradle.plugin.api-version (required '7.5')
       - Variant 'javadocElements' capability com.android.tools.build:gradle:7.4.2 declares a runtime of a component, and its dependencies declared externally:
           - Incompatible because this component declares documentation and the consumer needed a library
           - Other compatible attributes:
               - Doesn't say anything about its target Java version (required compatibility with Java 8)
               - Doesn't say anything about its elements (required them packaged as a jar)
               - Doesn't say anything about org.gradle.plugin.api-version (required '7.5')
       - Variant 'runtimeElements' capability com.android.tools.build:gradle:7.4.2 declares a runtime of a library, packaged as a jar, and its dependencies declared externally:
           - Incompatible because this component declares a component compatible with Java 11 and the consumer needed a component compatible with Java 8
           - Other compatible attribute:
               - Doesn't say anything about org.gradle.plugin.api-version (required '7.5')
       - Variant 'sourcesElements' capability com.android.tools.build:gradle:7.4.2 declares a runtime of a component, and its dependencies declared externally:
           - Incompatible because this component declares documentation and the consumer needed a library
           - Other compatible attributes:
               - Doesn't say anything about its target Java version (required compatibility with Java 8)
               - Doesn't say anything about its elements (required them packaged as a jar)
               - Doesn't say anything about org.gradle.plugin.api-version (required '7.5')

* 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 17s
Running Gradle task 'assembleRelease'...                           79.6s
Gradle task assembleRelease failed with exit code 1
@KingGorrin
Copy link

I'm also unable to build, but with a different error.

> flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.22.0, on Microsoft Windows [Version 10.0.19045.4355], locale en-EN)
[√] Windows Version (Installed version of Windows is version 10 or higher)
[√] Android toolchain - develop for Android devices (Android SDK version 32.0.0)
[√] Chrome - develop for the web
[√] Visual Studio - develop Windows apps (Visual Studio Professional 2022 17.8.7)
[√] Android Studio (version 2023.3)
[√] VS Code (version 1.89.1)
[√] Connected device (3 available)
[√] Network resources

• No issues found!

Build using stable channel and made sure to clear pub cache and upgrade all dependencies.

>flutter build apk --debug

//AppData/Local/Pub/Cache/hosted/pub.dev/agent_dart-1.0.0-dev.20/lib/archiver/encoder.dart:162:8: Error: The return type of the method 'SingingBlockZipFileEncoder.close' is 'void', which does not match the return type, 'Future<void>', of the overridden method, 'ZipFileEncoder.close'.
 - 'Future' is from 'dart:async'.
Change to a subtype of 'Future<void>'.
  void close() {
       ^
//AppData/Local/Pub/Cache/hosted/pub.dev/archive-3.5.1/lib/src/io/zip_file_encoder.dart:235:16: Context: This is the overridden method ('close').
  Future<void> close() async {
               ^
Target kernel_snapshot failed: Exception


FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'd:\flutter\bin\flutter.bat'' finished with non-zero exit value 1

* 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 29s
Running Gradle task 'assembleDebug'...                             30,0s
Gradle task assembleDebug failed with exit code 1

@coinselor
Copy link

I got the same error than @KingGorrin.

I believe @0x3639 is just missing the Android toolchain stuff, since he is trying to build an Android apk. Just follow the flutter doctor instructions.

@drblazer21
Copy link
Owner

@0x3639 please reinstall the Android toolchain and retry.

@KingGorrin @coinselor the problem you're encountering is due to a transitive library mismatch, more specifically the archive package. agent_dart 1.0.0-dev.20 requires archive version 3.4.10, otherwise you get compile time errors.

Fixed by adding a pubspec.lock with the correct library versions.

Feel free to close the issue if it works for you. Thanks!

@0x3639
Copy link
Author

0x3639 commented May 15, 2024

I update and ran

flutter clean
flutter pub get
flutter build apk --release

Now I get the following error

Screenshot 2024-05-15 at 5 06 26 PM

followed by this

Target kernel_snapshot failed: Exception


FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileFlutterBuildRelease'.
> Process 'command '/opt/homebrew/Caskroom/flutter/3.22.0/flutter/bin/flutter'' finished with non-zero exit value 1

* 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 37s
Running Gradle task 'assembleRelease'...                           38.3s
Gradle task assembleRelease failed with exit code 1

I accepted the security warning and it seems to be building as expected.

@0x3639 0x3639 closed this as completed May 15, 2024
@KingGorrin
Copy link

@0x3639 please reinstall the Android toolchain and retry.

@KingGorrin @coinselor the problem you're encountering is due to a transitive library mismatch, more specifically the archive package. agent_dart 1.0.0-dev.20 requires archive version 3.4.10, otherwise you get compile time errors.

Fixed by adding a pubspec.lock with the correct library versions.

Feel free to close the issue if it works for you. Thanks!

This fixed the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants