Whenever I run flutter build apk
, I get:
Running Gradle task 'assembleRelease'...
FAILURE: Build failed with an exception.
* Where:
Build file '/home/micycle/Documents/Dart/wordpair/android/app/build.gradle' line: 4
* What went wrong:
Error resolving plugin [id: 'dev.flutter.flutter-gradle-plugin', version: '1.0.0']
> A problem occurred configuring project ':gradle'.
> Could not create service of type OutputFilesRepository using ExecutionGradleServices.createOutputFilesRepository().
> Failed to create parent directory '/nix/store/jc032k4vpl3p5l37bl65a2649flqqybh-flutter-3.13.8-unwrapped/packages/flutter_tools/gradle/.gradle' when creating directory '/nix/store/jc032k4vpl3p5l37bl65a2649flqqybh-flutter-3.13.8-unwrapped/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 1s
Running Gradle task 'assembleRelease'... 2,775ms
Gradle task assembleRelease failed with exit code 1
I’m not quite sure why gradle is trying to make a folder in such a weird spot, nor do I know how to fix it.
The following is my flake.nix
:
{
description = "Flutter 3.13.x";
inputs = {
nixpkgs.url = "nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
config = {
android_sdk.accept_license = true;
allowUnfree = true;
};
};
buildToolsVersion = "34.0.0-rc4";
androidComposition = pkgs.androidenv.composeAndroidPackages {
buildToolsVersions = [ buildToolsVersion "28.0.3" ];
platformVersions = [ "34" "28" ];
abiVersions = [ "armeabi-v7a" "arm64-v8a" ];
includeEmulator = true;
emulatorVersion = "34.1.9";
};
androidSdk = androidComposition.androidsdk;
in
{
devShell =
with pkgs; mkShell rec {
ANDROID_SDK_ROOT = "${androidSdk}/libexec/android-sdk";
GRADLE_OPTS = "-Dorg.gradle.project.android.aapt2FromMavenOverride=${androidSdk}/libexec/android-sdk/build-tools/31.0.0/aapt2";
buildInputs = [
flutter
androidSdk
jdk17
xorg.libX11
];
};
});
}
chito
November 19, 2023, 9:37am
2
Hello !
For me, the issue came from the android/app/build.gradle
file generated by the latest version of Flutter.
By modifying it so that it looks like the file generated by an older version, the issue disappears.
After applying the changes, the beginning of the file looks like this to me:
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
// ...
And here is what it looked like before:
plugins {
id "com.android.application"
id "kotlin-android"
id "dev.flutter.flutter-gradle-plugin"
}
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
android {
// ...
I’m not sure what the real issue is, but I hope this helps!
Have a nice day!
2 Likes
hatch01
February 20, 2024, 3:51pm
3
Hi, this was working very well in previous versions, but flutter updated how they write their gradle configs.
I described the issue here : Unable to build flutter app with flutter 3.19 new Gradle structure · Issue #289936 · NixOS/nixpkgs · GitHub
I have a similar bug, when try debug flutter with my android phone got:
my flake.nix
{
description = "Flutter 3.13.x";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/23.11";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
config = {
android_sdk.accept_license = true;
allowUnfree = true;
};
};
buildToolsVersion = "34.0.0";
androidComposition = pkgs.androidenv.composeAndroidPackages {
buildToolsVersions = [ buildToolsVersion "28.0.3" ];
platformVersions = [ "34" "28" ];
abiVersions = [ "armeabi-v7a" "arm64-v8a" ];
};
androidSdk = androidComposition.androidsdk;
in
{
devShell =
with pkgs; mkShell rec {
ANDROID_SDK_ROOT = "${androidSdk}/libexec/android-sdk";
buildInputs = [
flutter
androidSdk # The customized SDK that we've made above
jdk17
];
};
});
}
1 Like