前置き
定期的に実施されるAndroidのAPIをレベル上げる作業をしていた。
android {
- compileSdkVersion 34
+ compileSdkVersion 36
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
~
defaultConfig {
~
- minSdkVersion 20
- targetSdkVersion 34
+ minSdkVersion 21
+ targetSdkVersion 36
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
multiDexEnabled true
そうしたらこのエラー。
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:processDebugResources'.
> A failure occurred while executing com.android.build.gradle.internal.res.LinkApplicationAndroidResourcesTask$TaskAction
> Android resource linking failed
ERROR:AAPT: aapt2 E 08-21 09:31:30 7504 1286515 LoadedArsc.cpp:94] RES_TABLE_TYPE_TYPE entry offsets overlap actual entry data.
aapt2 E 08-21 09:31:30 7504 1286515 ApkAssets.cpp:149] Failed to load resources table in APK '/Users/***/Library/Android/sdk/platforms/android-36/android.jar'.
error: failed to load include path /Users/***/Library/Android/sdk/platforms/android-36/android.jar.
解決しても次々に迫り来るエラー。
その痕跡を残す……。
対応1:android.jar関連
エラー内容
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:processDebugResources'.
> A failure occurred while executing com.android.build.gradle.internal.res.LinkApplicationAndroidResourcesTask$TaskAction
> Android resource linking failed
ERROR:AAPT: aapt2 E 08-21 09:31:30 7504 1286515 LoadedArsc.cpp:94] RES_TABLE_TYPE_TYPE entry offsets overlap actual entry data.
aapt2 E 08-21 09:31:30 7504 1286515 ApkAssets.cpp:149] Failed to load resources table in APK '/Users/***/Library/Android/sdk/platforms/android-36/android.jar'.
error: failed to load include path /Users/***/Library/Android/sdk/platforms/android-36/android.jar.
解決方法
failed to loadって言われているjarは存在しているので問題なさそう。
エラーで調べると、以下のようなものを発見。
https://github.com/superlistapp/super_editor/pull/2282
どうやらgradleのバージョンがよくなさそう。ということで、変えてみた。
```diff:android/build.gradle
~
dependencies {
- classpath 'com.android.tools.build:gradle:7.1.2'
+ classpath 'com.android.tools.build:gradle:8.12.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
- distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip
+ distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-all.zip
gradleのバージョンはこちらを参考にした。
https://developer.android.com/build/releases/gradle-plugin?hl=ja#updating-gradle
エラーが変わった……次のエラーだ。
対応2:namespace関連
エラー内容
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/nir/git/shopping_memo/android/build.gradle' line: 24
* What went wrong:
A problem occurred evaluating root project 'android'.
> A problem occurred configuring project ':app'.
> Could not create an instance of type com.android.build.api.variant.impl.ApplicationVariantImpl.
> Namespace not specified. Specify a namespace in the module's build file: /Users/nir/git/shopping_memo/android/app/build.gradle. 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.
解決方法
検索したら以下がヒット。gradleのアップデートが悪さしているとのこと。
詳しく説明もしてくれてる。ので従い修正
https://minpro.net/namespace-not-specified
~
allprojects {
repositories {
google()
jcenter()
}
+ subprojects {
+ afterEvaluate { project ->
+ if (project.hasProperty('android')) {
+ project.android {
+ if (namespace == null) {
+ namespace project.group
+ }
+ }
+ }
+ }
+ }
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
project.evaluationDependsOn(':app')
}
~
エラーが変わった…………次のエラーだ。
対応3:AndroidManufest
エラー内容
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:processDebugMainManifest'.
> Incorrect package="***" found in source AndroidManifest.xml: /Users/***/android/app/src/main/AndroidManifest.xml.
Setting the namespace via the package attribute in the source AndroidManifest.xml is no longer supported.
Recommendation: remove package="***" from the source AndroidManifest.xml: /Users/***/android/app/src/main/AndroidManifest.xml.
解決方法
これはエラー内容通りに。AndroidManifest.xmlからpackage名を削除すればOKそう。
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="***">
<!-- Flutter needs it to communicate with the running application
to allow setting breakpoints, to provide hot reload, etc.
-->
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="***">
<queries>
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="https" />
</intent>
<intent>
<action android:name="android.intent.action.DIAL" />
<data android:scheme="tel" />
</intent>
<intent>
<action android:name="android.intent.action.SEND" />
<data android:mimeType="*/*" />
</intent>
</queries>
<uses-permission android:name="android.permission.INTERNET"/>
~
エラーが変わった………………次のエラーだ。
対応4:Kotlin周り
エラー内容
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileDebugKotlin'.
> 'compileDebugJavaWithJavac' task (current target is 1.8) and 'compileDebugKotlin' task (current target is 17) jvm target compatibility should be set to the same Java version.
Consider using JVM toolchain: https://kotl.in/gradle/jvm/toolchain
解決方法
Javaの1.8を見に行ってる(?)ので、installされてる17と紐づけて上げる必要がありそう。
https://stackoverflow.com/questions/77520506/inconsistent-jvm-target-compatibility-detected-for-tasks-despite-already-definin
signingConfig signingConfigs.release
}
}
+
+ compileOptions {
+ sourceCompatibility JavaVersion.VERSION_17
+ targetCompatibility JavaVersion.VERSION_17
+ }
+ project.tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
+ kotlinOptions {
+ jvmTarget = '17'
+ }
+ }
}
以上でビルドできました!
感想
- Androidつらい
- APIレベル上げるだけなのに、色々いじらないといけないのは罠
- Cursorでここら辺解決しようとしたけどできなかった。AIに勝った