flutterdartgradleandroid-gradle-plugin

"Failed to transform appcompat-1.7.0.aar" error upon build


I have a repetitive reminder application, Rem. The problem started when I tried to work with the Android Alarm Manager Plus Flutter Plugin. The plugin has a set of requirements.

Requirements:

Most of these were already fulfilled, some that left to be updated were the flutter version, which was easily updated. Then the gradle and the AGP. I updated the version number in the distributionUrl in gradle-wrapper.properties to 8.4. And then added

classpath "com.android.tools.build:gradle:8.3.0"

to the dependencies in build.gradle for the AGP. Tried building and the app was fine. Then I added the android_alarm_manager_plus plugin related code and then tried to build, which started giving me some errors. I went through solving them and finally I am stuck with this:

ERROR:/home/sidam/.gradle/caches/transforms-3/53066ed9dfa936b8cd76913b06100409/transformed/jetified-appcompat-resources-1.7.0-runtime.jar: D8: java.lang.NullPointerException: Cannot invoke "String.length()" because "<parameter1>" is null
Running Gradle task 'assembleDebug'...                                
ERROR:/home/sidam/.gradle/caches/transforms-3/7038acadd030567fcf0c7254fa247a16/transformed/appcompat-1.7.0-runtime.jar: D8: java.lang.NullPointerException: Cannot invoke "String.length()" because "<parameter1>" is null
Running Gradle task 'assembleDebug'...                                

Running Gradle task 'assembleDebug'...                                
FAILURE: Build failed with an exception.
Running Gradle task 'assembleDebug'...                                

Running Gradle task 'assembleDebug'...                                
* What went wrong:
Running Gradle task 'assembleDebug'...                                
Execution failed for task ':app:mergeExtDexDebug'.
Running Gradle task 'assembleDebug'...                                
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
Running Gradle task 'assembleDebug'...                                
   > Failed to transform appcompat-resources-1.7.0.aar (androidx.appcompat:appcompat-resources:1.7.0) to match attributes {artifactType=android-dex, asm-transformed-variant=NONE, dexing-enable-desugaring=true, dexing-enable-jacoco-instrumentation=false, dexing-is-debuggable=true, dexing-min-sdk=24, org.gradle.category=library, org.gradle.dependency.bundling=external, org.gradle.libraryelements=aar, org.gradle.status=release, org.gradle.usage=java-runtime}.
Running Gradle task 'assembleDebug'...                                
      > Execution failed for DexingNoClasspathTransform: /home/sidam/.gradle/caches/transforms-3/53066ed9dfa936b8cd76913b06100409/transformed/jetified-appcompat-resources-1.7.0-runtime.jar.
Running Gradle task 'assembleDebug'...                                
         > Error while dexing.
Running Gradle task 'assembleDebug'...                                
   > Failed to transform appcompat-1.7.0.aar (androidx.appcompat:appcompat:1.7.0) to match attributes {artifactType=android-dex, asm-transformed-variant=NONE, dexing-enable-desugaring=true, dexing-enable-jacoco-instrumentation=false, dexing-is-debuggable=true, dexing-min-sdk=24, org.gradle.category=library, org.gradle.dependency.bundling=external, org.gradle.libraryelements=aar, org.gradle.status=release, org.gradle.usage=java-runtime}.
Running Gradle task 'assembleDebug'...                                
      > Execution failed for DexingNoClasspathTransform: /home/sidam/.gradle/caches/transforms-3/7038acadd030567fcf0c7254fa247a16/transformed/appcompat-1.7.0-runtime.jar.
Running Gradle task 'assembleDebug'...                                
         > Error while dexing.
Running Gradle task 'assembleDebug'...                                

Running Gradle task 'assembleDebug'...                                
* Try:
Running Gradle task 'assembleDebug'...                                
> Run with --stacktrace option to get the stack trace.
Running Gradle task 'assembleDebug'...                                
> Run with --info or --debug option to get more log output.
Running Gradle task 'assembleDebug'...                                
> Run with --scan to get full insights.
Running Gradle task 'assembleDebug'...                                
> Get more help at https://help.gradle.org.
Running Gradle task 'assembleDebug'...                                

Running Gradle task 'assembleDebug'...                                
BUILD FAILED in 36s
Running Gradle task 'assembleDebug'...                                   36.6s
Error: Gradle task assembleDebug failed with exit code 1

Here is my build.gradle:

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 {
    namespace "rem.reminds.you"
    compileSdkVersion 34
    ndkVersion flutter.ndkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "rem.reminds.you"
        // You can update the following values to match your application needs.
        // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
        minSdkVersion 24
        targetSdkVersion flutter.targetSdkVersion
        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.
            signingConfig signingConfigs.debug
        }
    }
}

flutter {
    source '../..'
}

dependencies {}

I have tried a lot of googled stuff but nothing worked. Some of which are:

THis error regarding the gradle build and appcompat is coming in flutter : I didn't have multipDex support added. So tried adding it.

Execution failed for task ':app:mergeExtDexDebug'. Could not resolve all files for configuration ':app:debugRuntimeClasspath' : One answer mentions downgrading the appcompat version works, but I couldn't find how to downgrade the appcompat version.

Failed to transform firebase-auth-22.2.0.aar : Upgrading minSdkVersion from 21 to 24 helps cut off part of the error but not the important part.

I also have this warning that I get from VS Code:

Project android: Unsupported Java Runtime: The Java version: 17, that is selected for the project is not supported by Gradle 7.2.The IDE will attempt to use Gradle 8.7 to gather the project information.
Possible solutions:
* Upgrade your Gradle version on your project
* Select Java Runtime 16 (or below), on Build > Gradle Execution settings, to avoid this problem!

I although have Gradle 8.4 as I have mentioned before, but this warning suggests that 7.2 is being used. Maybe that could be the problem but how and why. I don't know.


Solution

  • You can work around this by forcing a lower version of the AndroidX Appcompat library (e.g., 1.6.1), project-wide.
    build.gradle:

    allprojects {
        repositories {
            google()
            mavenCentral()
        }
        configurations.all {
            resolutionStrategy {
                force("androidx.appcompat:appcompat:1.6.1")
            }
        }
    }
    

    This way, dependencies or modules that reference the AndroidX Appcompat library will fall back to use the forced version. As always, do not forget to clean and rebuild the project.