これまでは、Cordovaプラグインを理解するために必要な項目の説明を行なってきました。今回と次回は、比較的多いCordovaプラグインに関連するビルドエラーについて説明していきたいと思います。今回は、Android編になります。
エラー1
Execution failed for task ':app:checkDebugAarMetadata'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction
> 6 issues were found when checking AAR metadata:
1. Dependency 'androidx.appcompat:appcompat-resources:1.7.0'; requires libraries and applications that
depend on it to compile against version 34 or later of the
Android APIs.
:app is currently compiled against android-33.
Recommended action: Update this project to use a newer compileSdk
of at least 34, for example 35.
このエラーは、Cordovaプラグインが要求しているcompileSdkのバージョンにMonacaプロジェクトが対応していない場合に出力されます。
対応方法については、MonacaクラウドIDEのメニュー、
- 設定 - Androidアプリ設定 - ターゲットSDKバージョン
に、33が設定されている場合は、34以降に変更することで対応できる場合があります。また、Androidプラットフォーム 14以降では、デフォルトでcompileSdkのバージョン35でビルドすることができるので、Androidプラットフォーム 14未満を使用している場合は、MonacaクラウドIDEのメニュー、
- ビルド - ビルド環境の設定 - Androidタブ - プラットフォーム - Android 14.0.1
を選択することでも対応できる場合があります。Androidプラットフォーム 14.0.1を使用する場合は、上記のターゲットSDKバージョンは、空にしてください。
エラー2
Execution failed for task ':app:checkDebugAarMetadata'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction
> 2 issues were found when checking AAR metadata:
1. Dependency 'androidx.core:core-ktx:1.16.0' requires Android Gradle plugin 8.6.0 or higher.
This build currently uses Android Gradle plugin 8.3.0.
2. Dependency 'androidx.core:core:1.16.0' requires Android Gradle plugin 8.6.0 or higher.
This build currently uses Android Gradle plugin 8.3.0.
* Try:
このエラーは、Cordovaプラグインが要求しているAndroid Gradle plugin(AGP)のバージョンにMonacaプロジェクトが対応していない場合に出力されます。
対応方法については、Monacaプロジェクトのconfig.xmlに、Cordovaが提供している下記のAndroidGradlePluginVersion設定を追加することで対応できる場合があります。
<platform name="android">
<preference name="AndroidGradlePluginVersion" value="8.6.0" />
</platform>
また、上記のエラーの場合、Androidプラットフォーム 14.0.1に設定されているAGPのバージョンは8.7.3になるため、MonacaクラウドIDEのメニュー、
ビルド - ビルド環境の設定 - ANDROID- プラットフォーム - Android 14.0.1
を選択することでも対応できる場合があります。
エラー3
+ ANDROID_PLATFORM_VERSION=14.0.1
A problem occurred configuring project ':app'.
> Failed to apply plugin class 'com.google.gms.googleservices.GoogleServicesPlugin'.
>
Extension of type 'ApplicationAndroidComponentsExtension' does not exist. Currently registered extension types: [ExtraPropertiesExtension, VersionCatalogsExtension, BasePluginExtension, DefaultArtifactPublicationSet, SourceSetContainer, ReportingExtension, JavaToolchainService, JavaPluginExtension, BaseAppModuleExtension, ApplicationAndroidComponentsExtension, NamedDomainObjectContainer<BaseVariantOutput>, GoogleServicesPlugin.GoogleServicesPluginConfig]
* Try:
このエラーは、
- com.google.gms.googleservices.GoogleServicesPlugin
を使用しているサードパーティー製Cordovaプラグインが、ビルド環境に対応していない場合に出力されます。古いバージョンのサードパーティー製Cordovaプラグインを使用している場合に多くみられるエラーになるため、現在使用しているバージョンよりも新しいバージョンが公開されている場合は、最新版を使用することでエラーに対応できる可能性があります。
エラー4
A problem occurred evaluating script.
> Could not find method compile() for arguments [com.commit451:PhotoView:1.2.4] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
このエラーは、サードパーティー製Cordovaプラグインのgradleファイル設定が、Androidプラットフォーム 11以降の環境に対応していない場合に出力されます。
このエラーも古いバージョンのサードパーティー製Cordovaプラグインを使用している場合に多くみられるエラーになるため、現在使用しているバージョンよりも新しいバージョンが公開されている場合は、最新版を使用することでエラーに対応できる可能性があります。
最新版が公開されていない場合は、対象のサードパーティー製Cordovaプラグインに設定されているgradleファイルのdependenciesに設定されている旧設定のcompileをimplementationに変更することで対応できる場合があります。
最新版が公開されていない場合は、compileをimplementationに変更したカスタム版の作成を検討してください。
エラー5(google-services.json)
5-1
> File google-services.json is missing. The Google Services Plugin cannot function without it.
Searched Location:
/tmp/download/platforms/android/app/src/debug/google-services.json
/tmp/download/platforms/android/app/src/google-services.json
/tmp/download/platforms/android/app/src/Debug/google-services.json
/tmp/download/platforms/android/app/google-services.json
このエラーは、サードパーティー製Cordovaプラグインが使用するgoogle-services.jsonが、Monacaプロジェクトのルートにアップロードされていない場合に出力されます。
対応方法については、MonacaクラウドIDEのメニュー、
- ファイル - アップロード
からMonacaプロジェクトのルートに対応したgoogle-services.jsonファイルをアップロードすることで対応できます。上記のエラーで、iOSで使用するGoogleService-Info.plistファイルが出力された場合も同様になります。
5-2
Execution failed for task ':app:processReleaseGoogleServices'.
> No matching client found for package name 'xxx.xxx.xxx' in /tmp/download/platforms/android/app/google-services.json
このエラーは、Monacaプロジェクトにアップロードされたgoogle-services.jsonに設定されているパッケージIDとMonacaプロジェクトのパッケージIDが違う場合に出力されます。
対応方法については、MonacaクラウドIDEのメニュー、
- ファイル - アップロード
からMonacaプロジェクトのルートに対応したgoogle-services.jsonファイルをアップロードすることで対応できます。上記のエラーで、iOSで使用するGoogleService-Info.plistファイルが出力された場合も同様になります。
エラー6
/tmp/download/platforms/android/app/src/main/AndroidManifest.xml:20:5-81 Error:
Element uses-permission#android.permission.WRITE_EXTERNAL_STORAGE at AndroidManifest.xml:20:5-81 duplicated with element declared at AndroidManifest.xml:7:5-108
/tmp/download/platforms/android/app/src/main/AndroidManifest.xml Error:
Validation failed, exiting
FAILURE: Build failed with an exception.
このエラーは、複数のCordovaプラグインでuses-permission設定が重複している場合に出力されます。対応方法について、上記のようなuses-permission設定が重複している場合は、MonacaクラウドIDEのメニュー、
- ビルド - ビルド環境の設定 - ANDROID - Monacaフックスクリプト - 重複パーミッションの削除
を「有効」にすることで対応できる場合があります。
おわりに
今回は、Cordovaプラグインに関連するAndroidのビルドエラーについて説明しました。Androidビルドエラーの解決の参考にしてください。次回は、iOS編を説明したいと思います。
