Skip to content

flutter: Unable to build Android apk (Could not create service of type OutputFilesRepository) #443842

Description

@Jonas-Sander

Nixpkgs version

  • Unstable (25.11)

Describe the bug

We're trying to update our Flutter App from Flutter 3.32.0 to 3.35 in this PR: SharezoneApp/sharezone-app#1920. When building our app on Android (SharezoneApp/sharezone-app) with Flutter 3.35.2 from nix (27b23c7) i get the following error:

FAILURE: Build failed with an exception.

* Where:
Settings file '/home/jsan/development/projects/temp/sharezone-app/app/android/settings.gradle' line: 20

* What went wrong:
Error resolving plugin [id: 'dev.flutter.flutter-plugin-loader', version: '1.0.0']
> A problem occurred configuring project ':gradle'.
   > Could not create service of type OutputFilesRepository using ExecutionGradleServices.createOutputFilesRepository().
      > Failed to create directory '/nix/store/4x7fabh5qhwgckdwqpq9kf9kdxzbc6ap-flutter-wrapped-3.35.2-sdk-links/packages/flutter_tools/gradle/.gradle/buildOutputCleanup'

* 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 319ms
Running Gradle task 'assembleProdRelease'...                       745ms
Gradle task assembleProdRelease failed with exit code 1

It works when not using flutter not from nix.

Steps to reproduce

Run: git clone --depth 1 https://github.com/SharezoneApp/sharezone-app.git -b flutter-upgrade-3-35 (latest commit that I'm referencing in this issue is SharezoneApp/sharezone-app@f2d229f).

cd sharezone-app

Run devenv shell

Run cd app

Run flutter build apk -t lib/main_prod.dart --flavor prod

Expected behaviour

Build should succeed

Screenshots

No response

Relevant log output

[jsan@nixos:~/development/projects/temp/sharezone-app/app]$ flutter build apk -t lib/main_prod.dart --flavor prod
Resolving dependencies in `/home/jsan/development/projects/temp/sharezone-app`... 
Downloading packages... 
  _fe_analyzer_shared 85.0.0 (88.0.0 available)
  _flutterfire_internals 1.3.52 (1.3.61 available)
  analyzer 7.7.1 (8.1.1 available)
  args 2.6.0 (2.7.0 available)
  asn1lib 1.5.9 (1.6.5 available)
  bloc_presentation 1.1.0 (1.1.1 available)
  bloc_presentation_test 1.1.0 (1.2.0 available)
  build 2.4.2 (4.0.0 available)
  build_config 1.1.2 (1.2.0 available)
  build_resolvers 2.4.4 (3.0.4 available)
  build_runner 2.4.15 (2.8.0 available)
  build_runner_core 8.0.0 (9.3.2 available)
  built_value 8.9.3 (8.12.0 available)
  built_value_generator 8.9.5 (8.12.0 available)
  chalkdart 2.3.2 (3.0.5 available)
  characters 1.4.0 (1.4.1 available)
  checked_yaml 2.0.3 (2.0.4 available)
  chewie 1.10.0 (1.13.0 available)
  cloud_firestore 5.6.4 (6.0.1 available)
  cloud_firestore_platform_interface 6.6.4 (7.0.1 available)
  cloud_firestore_web 4.4.4 (5.0.1 available)
  cloud_functions 5.3.3 (6.0.1 available)
  cloud_functions_platform_interface 5.6.3 (5.8.4 available)
  cloud_functions_web 4.10.9 (5.0.1 available)
  code_builder 4.10.1 (4.11.0 available)
  coverage 1.11.1 (1.15.0 available)
  dart_style 3.1.1 (3.1.2 available)
  device_info_plus 10.1.2 (12.1.0 available)
  device_info_plus_platform_interface 7.0.2 (7.0.3 available)
  dio 5.8.0+1 (5.9.0 available)
  dio_web_adapter 2.1.0 (2.1.1 available)
  fast_rsa 3.7.1 (3.8.5 available)
  file_picker 9.0.0 (10.3.3 available)
  file_selector_macos 0.9.4+2 (0.9.4+4 available)
  firebase_analytics 11.4.3 (12.0.1 available)
  firebase_analytics_platform_interface 4.3.3 (5.0.1 available)
  firebase_analytics_web 0.5.10+9 (0.6.0+1 available)
  firebase_auth 5.5.0 (6.0.2 available)
  firebase_auth_platform_interface 7.6.0 (8.1.1 available)
  firebase_auth_web 5.14.0 (6.0.2 available)
  firebase_core 3.12.0 (4.1.0 available)
  firebase_core_platform_interface 5.4.0 (6.0.0 available)
  firebase_core_web 2.21.0 (3.1.0 available)
  firebase_crashlytics 4.3.3 (5.0.1 available)
  firebase_crashlytics_platform_interface 3.8.3 (3.8.12 available)
  firebase_messaging 15.2.3 (16.0.1 available)
  firebase_messaging_platform_interface 4.6.3 (4.7.1 available)
  firebase_messaging_web 3.10.3 (4.0.1 available)
  firebase_performance 0.10.1+3 (0.11.0+1 available)
  firebase_performance_platform_interface 0.1.5+3 (0.1.5+12 available)
  firebase_performance_web 0.1.7+9 (0.1.7+18 available)
  firebase_remote_config 5.4.1 (6.0.1 available)
  firebase_remote_config_platform_interface 1.5.1 (2.0.2 available)
  firebase_remote_config_web 1.8.1 (1.8.11 available)
  firebase_storage 12.4.3 (13.0.1 available)
  firebase_storage_platform_interface 5.2.3 (5.2.12 available)
  firebase_storage_web 3.10.10 (3.10.19 available)
! flare_flutter 3.0.2 from git https://github.com/mbfakourii/Flare-Flutter.git at d915c8 in flare_flutter (overridden)
  flutter_bloc 9.0.0 (9.1.1 available)
  flutter_lints 5.0.0 (6.0.0 available)
  flutter_plugin_android_lifecycle 2.0.24 (2.0.30 available)
  flutter_slidable 4.0.0 (4.0.1 available)
  flutter_svg 2.0.17 (2.2.1 available)
  font_awesome_flutter 10.8.0 (10.10.0 available)
  freezed_annotation 2.4.4 (3.1.0 available)
  gcloud 0.8.18 (0.8.19 available)
  git 2.3.1 (2.3.2 available)
  go_router 14.8.0 (16.2.1 available)
  google_identity_services_web 0.3.3 (0.3.3+1 available)
  google_mobile_ads 5.3.1 (6.0.0 available)
  google_sign_in 6.2.2 (7.2.0 available)
  google_sign_in_android 6.1.35 (7.1.0 available)
  google_sign_in_ios 5.8.0 (6.2.0 available)
  google_sign_in_platform_interface 2.4.5 (3.1.0 available)
  google_sign_in_web 0.12.4+3 (1.1.0 available)
  googleapis 13.2.0 (14.0.0 available)
  googleapis_auth 1.6.0 (2.0.0 available)
  html 0.15.5 (0.15.6 available)
  http 1.4.0 (1.5.0 available)
  image_picker 1.1.2 (1.2.0 available)
  image_picker_android 0.8.12+21 (0.8.13+3 available)
  image_picker_for_web 3.0.6 (3.1.0 available)
  image_picker_ios 0.8.12+2 (0.8.13 available)
  image_picker_linux 0.2.1+1 (0.2.2 available)
  image_picker_macos 0.2.1+2 (0.2.2 available)
  image_picker_platform_interface 2.10.1 (2.11.0 available)
  image_picker_windows 0.2.1+1 (0.2.2 available)
  in_app_review 2.0.10 (2.0.11 available)
  leak_tracker 11.0.1 (11.0.2 available)
  lints 5.1.1 (6.0.0 available)
  material_color_utilities 0.11.1 (0.13.0 available)
  material_symbols_icons 4.2805.1 (4.2873.0 available)
  meta 1.16.0 (1.17.0 available)
  mockito 5.4.5 (5.5.1 available)
! open_file_plus 3.4.1+1 from git https://github.com/postflow/open_file_plus.git at b29351 (overridden)
  package_config 2.1.1 (2.2.0 available)
  package_info_plus 8.3.0 (9.0.0 available)
  package_info_plus_platform_interface 3.2.0 (3.2.1 available)
  path_provider_android 2.2.15 (2.2.18 available)
  path_provider_foundation 2.4.1 (2.4.2 available)
  patrol 3.15.2 (3.19.0 available)
  patrol_finders 2.7.2 (2.9.0 available)
  patrol_log 0.3.0 (0.5.0 available)
  pdfx 2.8.0 (2.9.2 available)
  permission_handler 11.3.1 (12.0.1 available)
  permission_handler_android 12.0.13 (13.0.1 available)
  permission_handler_apple 9.4.5 (9.4.7 available)
  permission_handler_platform_interface 4.2.3 (4.3.0 available)
  petitparser 6.1.0 (7.0.1 available)
  pointycastle 3.9.1 (4.0.0 available)
  pool 1.5.1 (1.5.2 available)
  process 5.0.3 (5.0.5 available)
  provider 6.1.2 (6.1.5+1 available)
  pub_semver 2.1.5 (2.2.0 available)
  purchases_flutter 8.7.5 (9.6.1 available)
  share_plus 10.1.4 (12.0.0 available)
  share_plus_platform_interface 5.0.2 (6.1.0 available)
  shared_preferences 2.5.2 (2.5.3 available)
  shared_preferences_android 2.4.6 (2.4.12 available)
  source_gen 2.0.0 (4.0.1 available)
  sqflite_android 2.4.1 (2.4.2+2 available)
  sqflite_common 2.5.5 (2.5.6 available)
  synchronized 3.3.1 (3.4.0 available)
  test 1.26.2 (1.26.3 available)
  test_api 0.7.6 (0.7.7 available)
  test_core 0.6.11 (0.6.12 available)
  url_launcher 6.3.1 (6.3.2 available)
  url_launcher_android 6.3.14 (6.3.22 available)
  url_launcher_ios 6.3.2 (6.3.4 available)
  url_launcher_macos 3.2.2 (3.2.3 available)
  url_launcher_web 2.4.0 (2.4.1 available)
  vector_graphics 1.1.18 (1.1.19 available)
  vector_graphics_compiler 1.1.16 (1.1.19 available)
  video_player 2.9.2 (2.10.0 available)
  video_player_android 2.7.17 (2.8.13 available)
  video_player_avfoundation 2.7.0 (2.8.4 available)
  video_player_platform_interface 6.3.0 (6.4.0 available)
  video_player_web 2.3.4 (2.4.0 available)
  vm_service 15.0.0 (15.0.2 available)
  wakelock_plus 1.2.10 (1.4.0 available)
  wakelock_plus_platform_interface 1.2.2 (1.3.0 available)
  watcher 1.1.1 (1.1.3 available)
  web 1.1.0 (1.1.1 available)
  web_socket 0.1.6 (1.0.1 available)
  web_socket_channel 3.0.2 (3.0.3 available)
  webview_flutter 4.10.0 (4.13.0 available)
  webview_flutter_android 4.3.2 (4.10.2 available)
  webview_flutter_platform_interface 2.10.0 (2.14.0 available)
  webview_flutter_wkwebview 3.18.1 (3.23.1 available)
  win32 5.10.1 (5.14.0 available)
  win32_registry 1.1.5 (2.1.0 available)
  xml 6.5.0 (6.6.1 available)
Got dependencies in `/home/jsan/development/projects/temp/sharezone-app`!
150 packages have newer versions incompatible with dependency constraints.
Try `flutter pub outdated` for more information.

FAILURE: Build failed with an exception.

* Where:
Settings file '/home/jsan/development/projects/temp/sharezone-app/app/android/settings.gradle' line: 20

* What went wrong:
Error resolving plugin [id: 'dev.flutter.flutter-plugin-loader', version: '1.0.0']
> A problem occurred configuring project ':gradle'.
   > Could not create service of type OutputFilesRepository using ExecutionGradleServices.createOutputFilesRepository().
      > Failed to create directory '/nix/store/4x7fabh5qhwgckdwqpq9kf9kdxzbc6ap-flutter-wrapped-3.35.2-sdk-links/packages/flutter_tools/gradle/.gradle/buildOutputCleanup'

* 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 319ms
Running Gradle task 'assembleProdRelease'...                       745ms
Gradle task assembleProdRelease failed with exit code 1

Additional context

devenv config:

devenv.nix
# Copyright (c) 2024 Sharezone UG (haftungsbeschränkt)
# Licensed under the EUPL-1.2-or-later.
#
# You may obtain a copy of the Licence at:
# https://joinup.ec.europa.eu/software/page/eupl
#
# SPDX-License-Identifier: EUPL-1.2

{
  pkgs,
  inputs,
  lib,
  ...
}:
let
  # Used so that we can select a specific version of Flutter
  pkgs-flutter = import inputs.nixpkgs-flutter { system = pkgs.stdenv.system; };
in
{

  env = {
    CHROME_EXECUTABLE = "${pkgs.chromium}/bin/chromium";
  };

  # https://devenv.sh/packages/
  packages = [
    pkgs.git
    pkgs.nixpkgs-fmt

    # Running `fvm flutter` -> 'Missing "unzip" tool. Unable to extract Dart SDK.'
    pkgs.unzip

    # For Flutter Web development
    # pkgs.google-chrome lead to long local builds that don't happen with pkgs.chromium.
    pkgs.chromium

    # Used by sharezone developers / sz cli
    pkgs.addlicense
    pkgs.nodePackages.prettier
    pkgs.nodePackages.firebase-tools
  ];

  enterShell = ''
    export ANDROID_HOME=$(which android | sed -E 's/(.*libexec\/android-sdk).*/\1/')
    export PATH=$ANDROID_HOME/cmdline-tools/latest/bin:$PATH

    # Make sz cli work
    export PATH="$PATH":"$DEVENV_ROOT/bin"

    flutter config --android-sdk $ANDROID_HOME

    # When running e.g. `sz pub get -c 0` the analytics
    # will cause the task to fail (maybe because so many signals
    # are sent in a short time). So we just disable analytics
    # so that they can not fail because of this reason.
    dart --disable-analytics &
    flutter --disable-analytics

    # We get the package in the sz cli folder so that one can
    # start running e.g. `sz pub get` right away. Without this 
    # one would first have to run pub get in the sz cli folder 
    # manually.
    dart pub get --directory ./tools/sz_repo_cli
  '';

  # Create an Android emulator named "android-simple"
  scripts.create-emulator.exec = ''
    avdmanager create avd -n android-simple -k "system-images;android-34;google_apis_playstore;x86_64" --device "pixel_6_pro"
  '';

  android = {
    enable = true;
    # Otherwise we get:
    #    FAILURE: Build failed with an exception.
    #    * Where:
    #    Build file '/home/jsan/development/projects/sharezone-app/app/android/build.gradle' line: 13
    #
    #    * What went wrong:
    #    A problem occurred evaluating root project 'android'.
    #    > A problem occurred configuring project ':app'.
    #       > com.android.builder.sdk.InstallFailedException: Failed to install the following SDK components:
    #             ndk;26.3.11579264 NDK (Side by side) 26.3.11579264
    #         The SDK directory is not writable (/nix/store/iqrggkmmq55v3db7ns5rmr62x8bq0ymz-androidsdk/libexec/android-sdk)
    ndk = {
      enable = true;
      version = [ "26.3.11579264" ];
    };
    # > Failed to install the following SDK components:
    #  build-tools;34.0.0 Android SDK Build-Tools 34
    buildTools.version = [ "34.0.0" ];
    # > Failed to install the following SDK components:
    #   platforms;android-31 Android SDK Platform 31 (etc. for 33, 34, 35)
    platforms.version = [
      "31"
      "33"
      "34"
      "35"
    ];
    flutter = {
      enable = true;
      package = pkgs-flutter.flutter;
    };
  };

  # See full reference at https://devenv.sh/reference/options/
}
devenv.yaml
# Copyright (c) 2024 Sharezone UG (haftungsbeschränkt)
# Licensed under the EUPL-1.2-or-later.
#
# You may obtain a copy of the Licence at:
# https://joinup.ec.europa.eu/software/page/eupl
#
# SPDX-License-Identifier: EUPL-1.2

inputs:
  nixpkgs:
    url: github:cachix/devenv-nixpkgs/rolling
  # Used to select the same version of Flutter as used in `.fvmrc`.
  # Search here for a commit that updates Flutter to the desired version:
  # https://github.com/NixOS/nixpkgs/commits/nixos-unstable/pkgs/development/compilers/flutter
  nixpkgs-flutter:
    url: github:NixOS/nixpkgs/27b23c793a053b3cb802100a15a82d714c17629c

# If you're using non-OSS software, you can set allowUnfree to true.
# We need it for the Android SDK and Google Chrome
allowUnfree: true
clean.enabled: true
# If you're willing to use a package that's vulnerable
# permittedInsecurePackages:
#  - "openssl-1.1.1w"

# If you have more than one devenv you can merge them
#imports:
# - ./backend

System metadata

this path will be fetched (0.02 MiB download, 0.06 MiB unpacked):
/nix/store/p2mnji2cdxgf6h27hlqzqf7g8f9bqfsi-stdenv-linux
copying path '/nix/store/p2mnji2cdxgf6h27hlqzqf7g8f9bqfsi-stdenv-linux' from 'http://nixsv'...

  • system: "x86_64-linux"
  • host os: Linux 6.12.42, NixOS, 25.05 (Warbler), 25.05.20250820.9cb344e
  • multi-user?: yes
  • sandbox: yes
  • version: nix-env (Nix) 2.28.4
  • nixpkgs: /nix/store/8han14lkbind4nx63hqq3i2sv6fbqiy5-source

Notify maintainers

@ericdallo @mkg20001 @RossComputerGuy @FlafyDev @hacker1024


Note for maintainers: Please tag this issue in your pull request description. (i.e. Resolves #ISSUE.)

I assert that this issue is relevant for Nixpkgs

Is this issue important to you?

Add a 👍 reaction to issues you find important.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions