0

I am trying to deploy the android version of my flutter app, but gradle keeps failing on the task com.android.build.gradle.internal.tasks.CompressAssetsWorkAction with this error: Java Heap Space

Can someone please try to replicate the error and let me know what the error is? Please let me know if I can provide any additional details!

This is my app/build.gradle:

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: 'com.google.gms.google-services'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {

    packagingOptions {
        pickFirst 'lib/x86/libc++_shared.so'
        pickFirst 'lib/x86_64/libc++_shared.so'
        pickFirst 'lib/armeabi-v7a/libc++_shared.so'
        pickFirst 'lib/arm64-v8a/libc++_shared.so'
    }

    compileSdkVersion 30
    buildToolsVersion = "29.0.2"

    dexOptions {
        javaMaxHeapSize "4g"
    }
    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        multiDexEnabled true
        applicationId "com.flyt.flyt"
        minSdkVersion 21
        targetSdkVersion 30
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            getByName("release") {
                // Enables code shrinking, obfuscation, and optimization for only
                // your project's release build type.
                minifyEnabled = true

                // Enables resource shrinking, which is performed by the
                // Android Gradle plugin.
                shrinkResources = true

                // Includes the default ProGuard rules files that are packaged with
                // the Android Gradle plugin. To learn more, go to the section about
                // R8 configuration files.
                proguardFiles(
                        getDefaultProguardFile("proguard-android-optimize.txt"),
                "proguard-rules.pro"
                )
            }
            signingConfig signingConfigs.debug
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation platform("com.google.firebase:firebase-bom:28.3.1")
    implementation "com.google.firebase:firebase-auth"
    implementation "androidx.browser:browser:1.3.0"
    implementation "androidx.constraintlayout:constraintlayout:1.1.3"
    implementation "com.android.support:multidex:2.0.1"
}

I tried adding the dex option to increase max heap size, but it didn't work.

Here is my project\build.gradle:

buildscript {
    ext.kotlin_version = '1.5.10'
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:4.2.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.3.10'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
    project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

I've also tried to change the gradle version, but I'm not sure if it is a version error^

and here is my gradle.properties:

android.useAndroidX=true
android.enableJetifier=true
org.gradle.daemon=true
org.gradle.configureondemand=true
org.gradle.jvmargs=-Xmx4096m

I've tried tweaking with the above jvm args to attempt to get more heap space, but it hasn't worked.

Neeraj
  • 5
  • 5
  • https://stackoverflow.com/questions/43091368/errorexecution-failed-for-task-apppackagedebug-java-heap-space – fartem Jan 06 '22 at 06:13
  • @fartem I just tried their solution with the edited jvm args line and got the same error – Neeraj Jan 06 '22 at 07:12

1 Answers1

0

Update: I Solved all of these issues by updating flutter and deleting my old API 30 android emulator and I downloaded a new emulator with the newest version which was API 32

Neeraj
  • 5
  • 5