Android Oreo - how do I set Adaptive Icons in Cordova?

前端 未结 9 1608
死守一世寂寞
死守一世寂寞 2020-12-24 13:57

Just wondering if anyone been able to set adaptive icons on Cordova for Android Oreo? I\'m using the android 6.4.0 and my square icon shrinks to fit the circle. I just want

9条回答
  •  有刺的猬
    2020-12-24 15:00

    WARNING: Don't use this answer. This is now supported out of the box as of Cordova 9. See https://stackoverflow.com/a/55169307/2947592

    So while the above answers helped me get to an answer, they are either dated or incomplete. So, to help anyone moving forward, this is a complete answer with all the ins and outs I could think of.

    Step 1: Create the icons

    You'll want to do this using the Image Asset Studio (https://developer.android.com/studio/write/image-asset-studio). There a number of guides on doing this.

    Step 2: Move the icons to your ionic/cordova project

    Copy the entire res folder into your project. The below example is for ionic v1.

    cp -a AndroidStudioProjects/MyApplication4/app/src/main/res MyIonicProject/myapp/resources/android/adaptiveicon
    

    Step 3: Edit config.xml

    First, to use the icons (this is missing from other answers), you need to alter the top widget line. You'll want to add xmlns:android="schemas.android.com/apk/res/android" to it, so it looks like the below. This allows the system to change the AndroidMenifest.xml file.

    
    

    Next, you'll need to adjust the platform section of your config.xml.

    First remove any instances of from the section.

    Then, Add in the alteration to the Android Manifest file:

    
        
    
    

    And lastly, for every file in the new resources/android/adaptiveicon folder, you will need to add a line like this:

    
    

    Make sure every file is represented! Your final platform section will probably look like this (this example is for when a PNG is used for both foreground and background):

    
        
        
        
        
        
        
        
        
        
        
        
        
        
        
            
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
    
    

    Step 4: Play it safe, clean the Android platform

    Run the following commands to clean the platform.

    cd myapp
    rm -rf platforms/android
    ionic cordova prepare
    

    For good measure, fix the bugs with the Android emulator start-up in ionic:

    wget https://raw.githubusercontent.com/gegenokitaro/cordova-android/8d497784ac4a40a9689e616cd486c4ed07d3e063/bin/templates/cordova/lib/emulator.js -O platforms/android/cordova/lib/emulator.js
    

    Step 5: Build!

    Build:

    ionic cordova build android
    

    Or Emulate:

    ionic cordova emulate android --consolelogs --serverlogs --target "Android8"
    

提交回复
热议问题