その他

Androidプラットフォーム11系について

Cordova

Monaca

Monacaチームの小田川です。

2022年7月4日に、GitHubにAndroidプラットフォーム11.0.0がリリースされました。

Androidプラットフォーム11.0.0の主な変更点は、下記になります。

  • Android 12用SplashScreen APIの統合
  • targetSdkVersionが32に更新
  • compileSdkVersionの個別設定

詳しくは、Cordova Android 11.0.0 Released!を参照してください。

Androidプラットフォーム11.0.0の大きな変更点は、AndroidプラットフォームにSplashScreen APIを使用したスプラッシュスクリーン機能が統合された点になります。今回は、統合されたスプラッシュスクリーン機能を中心に見ていきたいと思います。

Android 12用SplashScreen APIの統合

Android 12のスプラッシュスクリーンについては、下記の記事に注意点等を掲載しているので、一度チェックしてみてください。

Androidプラットフォーム11.0.0からは、AndroidプラットフォームにSplashScreen APIを使用したスプラッシュスクリーンの機能が統合されました。そのため、cordova-plugin-splashscreenは、非推奨になりました。

Androidプラットフォーム11系以降を使用する場合は、cordova-plugin-splashscreen@6.0.2を使用するか、Monacaプロジェクトからcordova-plugin-splashscreenを無効にする必要があります。

cordova-plugin-splashscreen@6.0.2では、インストール対象がAndroidプラットフォーム11未満に設定されたため、cordova-plugin-splashscreen@6.0.2を使用した場合は、ビルドの際に下記のメッセージが出力され、cordova-plugin-splashscreenは、インストールされません。

Discovered plugin "cordova-plugin-splashscreen". Adding it to the project
Installing "cordova-plugin-splashscreen" for android
Plugin doesn't support this project's cordova-android version. cordova-android: 11.0.0, failed version requirement: >=3.6.0 <11.0.0
Skipping 'cordova-plugin-splashscreen' for android
Adding cordova-plugin-splashscreen to package.json

スプラッシュスクリーン画像の設定方法

Androidプラットフォーム11.0.0からは、cordova-plugin-splashscreenを使用しないため、config.xmlのsplashタグも使用されなくなりました。ビルドの際にconfig.xmlにsplashタグが検出された場合は、下記のメッセージが出力されます。

The "<splash>" tags were detected and are no longer supported. Please migrate to the "preference" tag "AndroidWindowSplashScreenAnimatedIcon".

Androidプラットフォーム11.0.0以降でスプラッシュスクリーン画像を設定する場合は、config.xmlのpreferenceタグを使用して、下記の例のようにAndroidWindowSplashScreenAnimatedIconを使用します。

<platform name="android">
  <preference name="AndroidWindowSplashScreenAnimatedIcon" value="res/android/screen/splashscreen.xml" />
</platform>

valeuに設定されているパスは、Monacaプロジェクトのresフォルダー配下に配置したファイルを設定しています。設定できる画像は、Android Drawableに対応したxmlファイルまたはpngファイルになります。

上記のAndroidWindowSplashScreenAnimatedIcon設定は、ネイティブ側で提供されているAndroidWindowSplashScreenAnimatedIcon設定に対応しています。Androidプラットフォーム11.0.0では、AndroidXが提供しているSplashScreenの互換性ライブラリを使用しているため、対象のアプリをAndroid 12未満の端末にインストールした場合でも、SplashScreen APIのスプラッシュスクリーンが表示されます。

その他の機能

Androidプラットフォーム 11.0.0では、AndroidWindowSplashScreenAnimatedIcon設定の他に、下記の設定を使用することができます。詳しい設定については、Splash Screenを参照してください。

主に使用する設定は、下記になると思います。

  • AndroidWindowSplashScreenAnimationDuration(Animated Vector Drwableのアニメーションの表示時間)
  • AndroidWindowSplashScreenBackground(スプラッシュスクリーンの背景色)
  • AndroidWindowSplashScreenIconBackgroundColor(スプラッシュスクリーン画像の背景色)

使用例は、下記になります。

<platform name="android">
  <preference name="AndroidWindowSplashScreenAnimatedIcon" value="res/android/screen/splashscreen.xml" />
  <preference name="AndroidWindowSplashScreenAnimationDuration" value="1000" />
  <preference name="AndroidWindowSplashScreenBackground" value="#000000"/>
  <preference name="AndroidWindowSplashScreenIconBackgroundColor" value="#c0c0c0" />
</platform>

注意点として、上記のSplash Screenのドキュメントでは、AndroidWindowSplashScreenAnimationDurationのvalueの値が3000になっていますが、対応しているネイティブ側のAndroidWindowSplashScreenAnimationDuration設定の最長時間は、1000ミリ秒のため、1000以上の値を設定しても動作しない可能性があります。

下記の設定については、自己責任で使用可能SplashScreen互換性ライブラリ非対応となっています。

  • AndroidPostSplashScreenTheme(自己責任で使用可能)
  • AndroidWindowSplashScreenBrandingImage(SplashScreen互換性ライブラリ非対応)

compileSdkVersionの個別設定

Androidプラットフォーム10系では、targetSdkVersionに設定した値がcompileSdkVersionにも反映されていました。Androidプラットフォーム 11.0.0からは、config.xmlのpreference設定として、android-compileSdkVersionが追加され、compileSdkVersionを個別に設定できるようになりました。

使用例は、下記になります。

<platform name="android">
  <preference name="android-compileSdkVersion" value="31" />
</platform>

おわりに

Androidプラットフォーム11系からSplashScreen APIに対応したことにより、最新のスプラッシュスクリーンに対応することができるようになりました。現在のところ、MonacaでのAndroidプラットフォーム11系サポートの時期については決まっていませんが、引き続き最新のAndroidプラットフォームに対応していく予定になっていますので、一度、今回紹介した機能やドキュメント内容をチェックしてみてください。

author img for keiji_asial

keiji_asial

前の記事へ

次の記事へ

一覧へ戻る
PAGE TOP