Cordova _Android11で、Splash画面を変更する時のメモ・・・
Cordova_Android11
Cordovaでは、Android11では、スプラッシュプラグインが廃止され、スプラッシュ画面が、デフォルトで設定されている。
しかし、このスプラッシュスクリーンの変更が、なかなか、困難だったので、ブロクに、メモしておく・・・
「res」=リソース
「res」と言えば、アンドロイドのプロジェクトフォルダーの階層にある、アイコンなどを、格納するフォルダだ、drawableなど、アプリケーションの、従来のスプラッシュスクリーンの画像はここにあった、
<vector
android:height="24dp"
android:tint="#000000"
android:viewportHeight="24"
android:viewportWidth="24"
android:width="24dp"
xmlns:android="http://schemas.android.com/apk/res/android">
<path
android:fillColor="#FF000000"
android:pathData="M17.6,11.48 L19.44,8.3a0.63,0.63 0,0 0,-1.09 -0.63l-1.88,3.24a11.43,11.43 0,0 0,-8.94 0L5.65,7.67a0.63,0.63 0,0 0,-1.09 0.63L6.4,11.48A10.81,10.81 0,0 0,1 20L23,20A10.81,10.81 0,0 0,17.6 11.48ZM7,17.25A1.25,1.25 0,1 1,8.25 16,1.25 1.25,0 0,1 7,17.25ZM17,17.25A1.25,1.25 0,1 1,18.25 16,1.25 1.25,0 0,1 17,17.25Z"/>
</vector>
新しいCordovaのデフォルトのスプラッシュでは、「android:pathData」が、使われている。これは、いわゆる「base64のイメージ」のように、ベクター画像を、画像ファイルを、アップロードしなくても、配列変数により、画像が、表示されるものだ、「base64」は、使った経験があったので、画像ファイルが、無い場合でも、画像は、表示できる。というとは、すぐに分かった。AndroidStudioの「Vector Asset Studio」で、製作したものを移植し、Androidのプロジェクトフォルダの「res」にいれた、これで、スプラッシュスクリーンの画像が変更できる筈だ・・・
しかし、何故か、変更できない・・・😑
<platform name="android">
<preference name="AndroidWindowSplashScreenAnimatedIcon" value="res/screen/android/layout/activity_main.xml" />
</platform>
スプラッシュスクリーンの画像を、変更したにも、関わらず、何故か、スプラッシュスクリーンが変更できない・・・
<platform name="android">
<!-- Default -->
<preference name="AndroidWindowSplashScreenAnimatedIcon" value="res/android/screen/splash-port-xxxhdpi.png"/>
</platform>
ググッてみると、この課題は、スタックオーバーフローや、Githubでも、話題になっているようだ・・・
更にググると、このエラー、アイオニック(イオン)のドキュメントに、ヒントがあった。
https://ionic.zendesk.com/hc/en-us/articles/7891143965975-Migrating-to-Cordova-Android-11
Missing AndroidWindowSplashScreenAnimatedIcon
Your config.xml requires this addition element otherwise this error will occur:
The "AndroidWindowSplashScreenAnimatedIcon" value does not exist
This is caused by the path specified in your config.xml being incorrect. Eg: in the below example if the path specified in value is incorrect this error will occur:
<preference name="AndroidWindowSplashScreenAnimatedIcon" value="resources/android/icon/drawable-xxxhdpi-icon.png" />
At a bare minimum you should provide a png of size 2732x2732 (see requirements). You can enhance this later using launch storyboard images.
エラーコードは、やはり、パスが、違う場合らしい・・
2732x2732以上のサイズの画像を使えか・・・サイズが違ったのか・・・
アイオニックのドキュメントでは、「res」でなく、「resources」になっている。
もしかして、ここで、ピンと来た・・・🙄
resources/android/icon/drawable-xxxhdpi-icon.png
res・・・・resources・・・
このパスは、Androidのプロジェクトフォルダーの「res」フォルダーでは、無いのかも・・・🤔
下手に、アンドロイド開発に、慣れ過ぎていた・・・
試しに、コンフィグのある、階層に「res」を作って試して見ると・・
やはりだ・・・
「res」はAndroidプロジェクトフォルダ無いの「res」ではない。
「WWWと、同じ階層、ここから数えた、パスを意味している」のだ・・・
ここに、「2732x2732以上の画像」を入れて、ビルドすれば、スプラッシュスクリーンを、変更できるのだ・・・