見出し画像

UnityでAndroidアプリのAPIレベルを上げた際にビルドエラー解決した方法

1.はじめに

カエルパンダで配信している5年前のAndroidアプリ(ゆるゆる劇場シリーズ)についてAPIレベルを上げる必要が出てきました。Unityのバージョンを上げた上でAPIレベルを31に上げてビルドをしようとしたところ、いわゆるGradle周りを中心にエラーで盛大につまづきました。本件について有名な記事がいくつかありますが、それだけでは解決せず、いちおう自己解決出来ましたので、同様の問題に遭遇した方の助けになれば幸いです!


2.詰まった問題

ビルドした際、Gradle周りでことごとくエラーが出ました・・・。

エラー


3.参考記事

これらの記事を元にGradle周りのエラーを除去していったのですが、、、

以下のエラーが解消できず、頭を抱えていました。

FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':launcher:lintVitalRelease'.
> Could not resolve all artifacts for configuration ':launcher:debugRuntimeClasspath'.
   > Did not resolve 'com.android.support:support-core-ui:26.1.0' which is part of the dependency lock state
   > Did not resolve 'com.android.support:support-compat:26.1.0' which is part of the dependency lock state
   > Did not resolve 'android.arch.core:runtime:1.1.1' which is part of the dependency lock state
   > Did not resolve 'com.android.support:support-annotations:26.1.0' which is part of the dependency lock state
   > Did not resolve 'android.arch.lifecycle:livedata:1.1.1' which is part of the dependency lock state
   > Did not resolve 'com.android.support:support-core-utils:26.1.0' which is part of the dependency lock state
   > Did not resolve 'android.arch.lifecycle:livedata-core:1.1.1' which is part of the dependency lock state
   > Did not resolve 'com.android.support:support-fragment:26.1.0' which is part of the dependency lock state
   > Did not resolve 'android.arch.lifecycle:viewmodel:1.1.1' which is part of the dependency lock state
   > Did not resolve 'android.arch.lifecycle:common:1.1.1' which is part of the dependency lock state
   > Did not resolve 'android.arch.core:common:1.1.1' which is part of the dependency lock state
   > Resolved 'androidx.lifecycle:lifecycle-extensions:2.0.0' which is not part of the dependency lock state
   > Did not resolve 'android.arch.lifecycle:runtime:1.1.1' which is part of the dependency lock state
   > Did not resolve 'android.arch.lifecycle:extensions:1.1.1' which is part of the dependency lock state
   > Resolved 'androidx.lifecycle:lifecycle-service:2.0.0' which is not part of the dependency lock state

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org


4.解決策した方法

最終的に、以下の方法でエラーが解消しました。
「Assets\Editor\Platform-Dependencies\Android」以下に生成されていた「xxxxx.lockfile」というファイル群を削除することで、エラーが消えてビルドが通りました。他にもエラーがあったのですが、この対応で他のエラーも解消しました。
(このフォルダ内のファイルはクリーンビルドすると再構築されるため、環境をアップデートした際は一度消して良いかもしれません)

消した xxxxx.lockfile

5.まとめ

古いアプリのメンテナンスでアンドロイドAPIレベルを上げた際のビルドエラーが解決できず詰まった場合、試しに「xxxxx.lockfile」をが生成していないかを確認して削除してみると解決できるかもしれません。


よかったらサポートいただけると嬉しいです。 ヘルプしてくれているメンバーやゲストへのギャラ等の活動費に使用させていただきます