When building a Flutter APK, you might encounter the following error:
ERROR: C:\path\to\project\build\webview_cookie_manager\intermediates\merged_res\release\mergeReleaseResources\values\values.xml:194: AAPT: error: resource android:attr/lStar not found.
This error can be frustrating, especially when it originates from an outdated dependency like the webview_cookie_manager package. In this post, we’ll walk through the steps taken to resolve the error and ensure your project builds successfully.
Background
The webview_cookie_manager package was originally created to simplify cookie management for WebViews in Flutter applications. However, support for the package ended several years ago. As a result, it has not kept pace with Android’s evolving build requirements, such as the introduction of the lStar
attribute in Android 15 (API level 35).
Upgrading your Flutter SDK and your project’s compile configuration isn’t always enough when a dependency has its own internal build settings. This blog explains how to patch the plugin locally to update its Android build configuration.
The Problem
Even after upgrading to the latest Flutter version and ensuring your project’s compileSdkVersion
is set to a recent API level, the build fails because the plugin’s own configuration still targets an older SDK version. The error:
resource android:attr/lStar not found.
indicates that the attribute lStar
—introduced in Android 12—is missing. This discrepancy arises because the webview_cookie_manager plugin uses its own build.gradle
file that does not reference a recent compile SDK.
Step-by-Step Fix
1. Patch the Plugin Locally
Since the package is no longer maintained, the most robust solution is to patch the plugin locally. This involves copying the package from the Flutter cache into your project and updating its Android build configuration.
a. Copy the Plugin
- Locate the Plugin in the Pub Cache
The package is typically located at:C:\Users\<YourUsername>\AppData\Local\Pub\Cache\hosted\pub.dev\webview_cookie_manager-<version>\
- Copy the Plugin Folder
Create a new folder in your project (for example,./plugins/webview_cookie_manager/
) and copy the entire contents of the plugin into this folder.
b. Update the Plugin’s Android Build Configuration
- Open the Plugin’s Build File
Navigate to the copied plugin folder and open theandroid/build.gradle
file (or the module’s build.gradle if applicable). - Modify the SDK Versions
Update thecompileSdkVersion
andtargetSdkVersion
to a value that includes thelStar
attribute. For example:android {
compileSdkVersion 33 // or 34
defaultConfig {
minSdkVersion 21
targetSdkVersion 33 // or 34, as needed
}
// Other configurations...
}
c. Point Your pubspec.yaml to the Local Plugin
In your project’s pubspec.yaml
, update the dependency to use the local version:
dependencies:
flutter:
sdk: flutter
webview_cookie_manager:
path: ./plugins/webview_cookie_manager
2. Clean and Rebuild the Project
After patching the plugin, run the following commands in your terminal:
flutter clean
flutter pub get
flutter build apk
These steps ensure that your project picks up the local changes and rebuilds using the updated SDK configuration.
Alternative: Consider a Maintained Replacement
Because webview_cookie_manager is no longer actively maintained, another viable solution is to replace it with an alternative package such as flutter_inappwebview. This package offers robust cookie management along with a wide range of WebView features and receives regular updates.
To switch:
- Remove webview_cookie_manager from your
pubspec.yaml
. - Add flutter_inappwebview:
dependencies:
flutter:
sdk: flutter
flutter_inappwebview: ^5.7.1
- Update your code accordingly to use the new package’s API.
Conclusion
Encountering build errors like the missing lStar
attribute can be challenging, especially when they stem from outdated dependencies. By patching webview_cookie_manager locally and updating its build configuration, you can resolve the error and continue building your Flutter APK successfully. Alternatively, migrating to a maintained package ensures future compatibility and access to ongoing updates.
I hope this guide helps anyone facing a similar issue. Feel free to leave comments or reach out if you have any questions or further insights!