You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cordova.apache.org by "geoidesic (via GitHub)" <gi...@apache.org> on 2024/07/31 10:05:15 UTC

[I] Cordova Android doesn't work with adaptive icons. [cordova-android]

geoidesic opened a new issue, #1727:
URL: https://github.com/apache/cordova-android/issues/1727

   # Bug Report
   
   ## Problem
   The documentation is unclear. And I tried ChatGPT too. I have this config.xml in the cordova project root. 
   
   ```xml
       <platform name="android">
           <allow-intent href="market:*" />
           <plugin name="@havesource/cordova-plugin-push" spec="3.0.0">
               <variable name="SENDER_ID" value="661392819841" />
           </plugin>
           <preference name="AndroidInsecureFileModeEnabled" value="true" />
           <preference name="EnableWebViewDebugging" value="true" />
          
           <icon src="res/screen/android/sportch-logo.xml" density="anydpi" />
   
           <!-- New Splash Screen Preferences -->
           <preference name="AutoHideSplashScreen" value="true" />
           <preference name="AndroidWindowSplashScreenBackground" value="#000" />
           <preference name="AndroidWindowSplashScreenAnimatedIcon" value="ic_cdv_splashscreen.xml" />
           <preference name="SplashScreen" value="screen" />
           <preference name="ShowSplashScreenSpinner" value="false" />
           <preference name="SplashScreenDelay" value="0" />
           <preference name="FadeSplashScreenDuration" value="300" />
           <preference name="SplashMaintainAspectRatio" value="true" />
   
           <!-- Adaptive App Icons -->
           <!-- Copy colors.xml -->
           <resource-file src="res/values/colors.xml" target="app/src/main/res/values/colors.xml" />
   
           <!-- Copy foreground SVG -->
           <resource-file src="res/icon/android/ic_launcher_foreground.xml" target="app/src/main/res/drawable/ic_launcher_foreground.xml" />
           
           <!-- Copy monochrome SVG -->
           <resource-file src="res/icon/android/ic_launcher_monochrome.xml" target="app/src/main/res/drawable/ic_launcher_monochrome.xml" />
   
           <!-- Define adaptive icons -->
           <icon 
               foreground="@drawable/ic_launcher_foreground" 
               background="@color/background" 
               density="ldpi" 
               monochrome="@drawable/ic_launcher_monochrome" />
           <icon 
               foreground="@drawable/ic_launcher_foreground" 
               background="@color/background" 
               density="mdpi" 
               monochrome="@drawable/ic_launcher_monochrome" />
           <icon 
               foreground="@drawable/ic_launcher_foreground" 
               background="@color/background" 
               density="hdpi" 
               monochrome="@drawable/ic_launcher_monochrome" />
           <icon 
               foreground="@drawable/ic_launcher_foreground" 
               background="@color/background" 
               density="xhdpi" 
               monochrome="@drawable/ic_launcher_monochrome" />
           <icon 
               foreground="@drawable/ic_launcher_foreground" 
               background="@color/background" 
               density="xxhdpi" 
               monochrome="@drawable/ic_launcher_monochrome" />
           <icon 
               foreground="@drawable/ic_launcher_foreground" 
               background="@color/background" 
               density="xxxhdpi" 
               monochrome="@drawable/ic_launcher_monochrome" />
   
           <preference name="android-targetSdkVersion" value="34" />
           <resource-file src="google-services.json" target="/app/google-services.json" />
           <resource-file src="firebase-service-account-pvt-key.json" target="app/src/main/assets/firebase-service-account-pvt-key.json" />
       </platform>
    ```
   
   In the project root I have the `res` folder:
   <img width="293" alt="Screenshot 2024-07-31 at 10 42 27" src="https://github.com/user-attachments/assets/3248155a-bd9e-478a-a804-739009c6c076">
   
   Which contains the assets that match the `resource-file` elements in the `config.xml` but they are not copied into the target folders.
   
   
   ### What is expected to happen?
   I want to define: colors.xml, splash.xml, foreground.xml and monochrome.xml in my project root `res` folder and then have those copied across into the android platform as appropriate.
   
   
   ### What does actually happen?
    causes an error:
   ```
   Android project created with cordova-android@13.0.0
   Source path does not exist: @drawable/ic_launcher_foreground
   ```
   
   
   ## Information
   <!-- Include all relevant information that might help understand and reproduce the problem -->
   
   
   
   ### Command or Code
   <!-- What command or code is needed to reproduce the problem? -->
   `cordova platform remove android; cordova platform add android;`
   
   
   ### Environment, Platform, Device
   <!-- In what environment, on what platform or on which device are you experiencing the issue? -->
   I'm running cordova on Mac OS X and trying to build it for Android API v13 for emulator.
   
   
   ### Version information
   <!--
   What are relevant versions you are using?
   For example:
   Cordova: Cordova CLI, Cordova Platforms, Cordova Plugins
   Other Frameworks: Ionic Framework and CLI version
   Operating System, Android Studio, Xcode etc.
   -->
   Cordova: 12.0.0 (cordova-lib@12.0.1)
   cordova-android@13.0.0
   Mac OS X: 14.5 (23F79)
   Android Studio Koala | 2024.1.1 Patch 1
   Node: v20.15.1
   
   
   ## Checklist
   <!-- Please check the boxes by putting an x in the [ ] like so: [x] -->
   
   - [x] I searched for existing GitHub issues
   - [x] I updated all Cordova tooling to most recent version
   - [x] I included all the necessary information above
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org


Re: [I] Cordova Android doesn't work with adaptive icons. [cordova-android]

Posted by "breautek (via GitHub)" <gi...@apache.org>.
breautek commented on issue #1727:
URL: https://github.com/apache/cordova-android/issues/1727#issuecomment-2278366077

   The `<icon>` foreground, background, and monochrome expects a file resource, not a resource reference, but will accept a color reference.
   
   So it needs to point to a PNG file or an AVD on disk, or a `@color/...` value.
   
   An example based on your provided config will look something like:
   
   ```xml
   <!-- Cordova already defines colors.xml, so I'm using a new name despite the Cordova Docs guide -->
   <resource-file src="res/values/colors.xml" target="app/src/main/res/values/myColors.xml" />
   <icon
     foreground="res/icon/android/ic_launcher_foreground.xml" 
     background="@color/background" 
     density="mdpi" 
     monochrome="res/icon/android/ic_launcher_monochrome.xml" />
   ```
   
   Don't create a `<resource-file>` for your foreground and monochrome, the Cordova CLI will do this behind the scenes.
   
   Note that despite that vectors can be used on any DPI, the `<icon>` directive still requires the `density` declared. So you'll need to replicate the `<icon>` directive for each dpi, `mdpi`, `hdpi`, xhdpi`, `xxhdpi`, and `xxxhpdi`. There is no device on market that Cordova supports that uses `ldpi` so it can safely be omitted.
   
   With that being said, I think expanding support to allow more (or all) resource references would be desirable so I'll keep this ticket open.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org