iTranslated by AI
Flutter Build Errors Encountered After Updating to Android Studio Ladybug
Overview
When I updated Android Studio to Ladybug, I encountered various build errors in my existing Flutter projects. This is a note on how I addressed them.
I would appreciate it if you could let me know if there are better ways to fix these! 🙇
Environment
- Android Studio Ladybug | 2024.2.1 Patch 2
Environment where Build Errors 1–3 occurred:
- Flutter SDK: 3.24.0
Environment where Build Error 4 and Codemagic errors occurred:
- Flutter SDK: 3.27.1
Build Error 1
The error appeared out of nowhere...
Execution failed for task ':flutter_image_compress_common:compileDebugJavaWithJavac'.
> Could not resolve all files for configuration ':flutter_image_compress_common:androidJdkImage'.
> Failed to transform core-for-system-modules.jar to match attributes {artifactType=_internal_android_jdk_image, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime}.
> Execution failed for JdkImageTransform: /Users/xxxxx/Develop/android-sdk/platforms/android-31/core-for-system-modules.jar.
> Error while executing process /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/jlink with arguments
{--module-path /Users/xxxxx/.gradle/caches/transforms-3/be939630b59b5e5390087ebc288d398f/transformed/output/temp/jmod --add-modules java.base
--output /Users/xxxxx/.gradle/caches/transforms-3/be939630b59b5e5390087ebc288d398f/transformed/output/jdkImage --disable-plugin system-modules}
For now, referring to 👆, I updated android/gradle/wrapper/gradle-wrapper.properties as follows:
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
Next, I updated classpath 'com.android.tools.build:gradle in android/build.gradle to the following:
classpath 'com.android.tools.build:gradle:8.3.2'
- Or add the following to
pluginsinandroid/settings.gradle:
id "com.android.application" version "8.3.2" apply false
Then, another build error occurred... Continuing to Build Error 2.
Build Error 2
Execution failed for task ':app:processDevDebugMainManifest'.
> Manifest merger failed : Attribute property#android.adservices.AD_SERVICES_CONFIG@resource value=(@xml/gma_ad_services_config) from [com.google.android.gms:play-services-ads-lite:23.0.0] AndroidManifest.xml:92:13-59
is also present at [com.google.android.gms:play-services-measurement-api:22.1.2] AndroidManifest.xml:32:13-58 value=(@xml/ga_ad_services_config).
Suggestion: add 'tools:replace="android:resource"' to <property> element at AndroidManifest.xml to override.
It seems like this doesn't happen with 8.2.2, so I reverted it for now.
classpath 'com.android.tools.build:gradle:8.2.2'
Then another build error occurred... Continuing to Build Error 3.
Build Error 3
Execution failed for task ':app:packageDevDebug'.
> A failure occurred while executing com.android.build.gradle.tasks.PackageAndroidArtifact$IncrementalSplitterRunnable
> java.lang.OutOfMemoryError (no error message)
For now, I set org.gradle.jvmargs=-Xmx4g so that the build passed. The -Xmx4g part may need adjustment.
Build Error 4
A problem occurred configuring project ':isar_flutter_libs'.
> Could not create an instance of type com.android.build.api.variant.impl.LibraryVariantBuilderImpl.
> Namespace not specified. Specify a namespace in the module's build file. See https://d.android.com/r/tools/upgrade-assistant/set-namespace for information about setting the namespace.
If you've specified the package attribute in the source AndroidManifest.xml, you can use the AGP Upgrade Assistant to migrate to the namespace value in the build file. Refer to https://d.android.com/r/tools/upgrade-assistant/agp-upgrade-assistant for general information about using the AGP Upgrade Assistant.
After applying the fix mentioned in 👆, the build passed! 🎉
Errors on Codemagic
Lastly, here are the fixes for the errors that occurred on CI.
Error details
Your project is configured with Android NDK 23.1.7779620, but the following plugin(s) depend on a different Android NDK version:
...
Fix this issue by using the highest Android NDK version (they are backward compatible).
Add the following to /Users/builder/clone/android/app/build.gradle:
android {
ndkVersion = "25.1.8937393"
...
}
...
ERROR: /Users/builder/clone/build/app/intermediates/merged_java_res/release/base.jar: R8: com.android.tools.r8.ResourceException: com.android.tools.r8.internal.vc: I/O exception while reading '/Users/builder/clone/build/app/intermediates/merged_java_res/release/base.jar': /Users/builder/clone/build/app/intermediates/merged_java_res/release/base.jar
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:minifyReleaseWithR8'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.R8Task$R8Runnable
> Compilation failed to complete, origin: /Users/builder/clone/build/app/intermediates/merged_java_res/release/base.jar
According to the StackOverflow link provided, it seems that tasks.whenTaskAdded is the cause... 🤔
👆 It seems that setting minify to false works, but it appears to be a workaround.
→ I actually set it to false and ran Codemagic, and it passed!
I couldn't find a permanent fix even after researching. I would appreciate it if anyone who knows something could let me know!
Discussion