🤯
Android Studio Ladybugに更新した際にFlutterで遭遇したビルドエラー
概要
Android Studio を Ladybugに更新した際に、既存のFlutterプロジェクトで色々なビルドエラーに遭遇したので、その対応のメモになります。
もっとこう修正した方がいいよ〜などあれば教えて頂けると助かります 🙇
環境
- Android Studio Ladybug | 2024.2.1 Patch 2
ビルドエラー1 ~ 3 が起きた環境
- Flutter SDK: 3.24.0
ビルドエラー4とCodemagic上でのエラーが起きた環境
- Flutter SDK: 3.27.1
ビルドエラー 1
エラーは突然に…
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}
ひとまず👆を参考に android/gradle/wrapper/gradle-wrapper.properties
を以下に更新
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
次に android/build.gradle
の classpath 'com.android.tools.build:gradle
を以下に更新
classpath 'com.android.tools.build:gradle:8.3.2'
※ または android/settings.gradle
の plugins
に以下を追加
id "com.android.application" version "8.3.2" apply false
すると、今度は別のビルドエラーが発生… ビルドエラー 2 へ続く
ビルドエラー 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.
8.2.2
だと起きないみたいなので一旦戻す。
classpath 'com.android.tools.build:gradle:8.2.2'
すると別のビルドエラーが発生… ビルドエラー 3 へ続く
ビルドエラー 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)
ひとまず org.gradle.jvmargs=-Xmx4g
にしてビルドが通るようにりました。-Xmx4g
の部分は要調整。
ビルドエラー 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.
👆の対応を実施してあげるとビルドが通りました 🎉
Codemagic上でのエラー
最後にCIでエラーになっていた分の修正になります。
エラー内容
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
貼られてあったStackOverflowのリンクだと tasks.whenTaskAdded
が原因と書かれてある様です… 🤔
👆minifyをfalseにするといいらしいが、暫定対応みたいです。
→ 実際にfalseにしてcodemagicを走らせると通りました!
根本対応が調べても分からず。何か分かる方いたら教えて頂けると助かります!
Discussion