Message “error: resource android:attr/lStar not found”

In this blog post, we will delve into the solution of a common error that developers face when working with Flutter. The error in question is “error: resource android:attr/lStar not found”. This error typically arises after updating Flutter to a newer version, specifically 3.24. We’ll explore the root cause of this issue and provide a step-by-step guide on how to resolve it.

The Root Cause

As mentioned earlier, the error “error: resource android:attr/lStar not found” is related to the fact that Flutter now checks for the versions of compileSdkVersion and buildToolsVersion in your project. This check is enforced starting from Flutter 3.24. Some packages might either specify outdated versions or do not specify them at all, leading to this error.

The Solution

To resolve this issue, you need to update the affected packages to their latest versions. If there are any packages in your project that still have outdated or unspecified values for compileSdkVersion and buildToolsVersion, you can add a script to your build.gradle file between the subprojects instructions.

Adding Scripts to Your build.gradle File

The script will look something like this:

subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    afterEvaluate { project ->
        if (project.plugins.hasPlugin("com.android.application") ||
                project.plugins.hasPlugin("com.android.library")) {
            project.android {
                compileSdkVersion 34
                buildToolsVersion "34.0.0"
            }
        }
    }
}
subprojects {
    project.evaluationDependsOn(':app')
}

Please note that you should replace the values of compileSdkVersion and buildToolsVersion with your desired versions.

Updating Other Settings

In addition to updating your packages, you may also need to update other settings in your project. Specifically, you might need to update compileSdkVersion and targetSdkVersion to 31 in your android/build.gradle file.

android {
    ...
    defaultConfig {
        ...
        compileSdkVersion 31
        targetSdkVersion 31
        ...
    }
}

You may also need to add the following code snippet at the very end of your android/build.gradle file:

configurations.all {
    resolutionStrategy {
        force 'androidx.core:core-ktx:1.6.0'
    }
}

Audioplayers Package Update

If the issue you’re facing is related to the audioplayers package, please note that the original author has recently fixed this issue in his recent PR. This fix was implemented in version 0.20.1 of audioplayers, so make sure to upgrade to this version or later.

Conclusion

The error “error: resource android:attr/lStar not found” is a common issue that arises after updating Flutter to version 3.24. To resolve this problem, you need to update your packages to their latest versions and possibly add scripts to your build.gradle file to specify the correct values for compileSdkVersion and buildToolsVersion. Additionally, make sure to upgrade other settings in your project according to the guidelines provided above.

Please note that this solution is based on the answer from here: https://github.com/livekit/client-sdk-flutter/issues/569#issuecomment-2275686786