Migrating to Cordova-Android 11

Follow

Comments

6 comments

  • Avatar
    Nelson Oraibo Chadali

    Hi, excellent article, it helped me a lot because I was going through the same problem for days, I followed your entire article, but I'm having an error when adding the android platform

    Cannot read properties of null (reading 'find')

    Can you help me please, i don't know what it means

    0
    Comment actions Permalink
  • Avatar
    Damian Tarnawsky

    The problem is very specific to your project and could be related to plugins used, how you manipulate resources in config.xml. I would remove anything in your config.xml that has <resource-file in it to narrow down where the project is getting messing up.

    0
    Comment actions Permalink
  • Avatar
    Nelson Oraibo Chadali

    The problem is in splash 

     

    here the error: 

    Cannot read properties of null (reading 'find')
    TypeError: Cannot read properties of null (reading 'find')
        at E:\DEV\IONIC\donateApp_cord\node_modules\cordova-android\lib\prepare.js:387:49
        at Array.forEach (<anonymous>)
        at updateProjectSplashScreen (E:\DEV\IONIC\donateApp_cord\node_modules\cordova-android\lib\prepare.js:384:7)
        at updateProjectAccordingTo (E:\DEV\IONIC\donateApp_cord\node_modules\cordova-android\lib\prepare.js:269:5)
        at E:\DEV\IONIC\donateApp_cord\node_modules\cordova-android\lib\prepare.js:67:21
        at processTicksAndRejections (node:internal/process/task_queues:96:5)
        at async Promise.all (index 0)
    [ERROR] An error occurred while running subprocess cordova.

            cordova.cmd platform add android@11 --verbose exited with exit code 1.

    and the file wich raise the erro is:

    function updateProjectSplashScreen (platformConfig, locations) {

        // res/values/themes.xml

        const themes = xmlHelpers.parseElementtreeSync(locations.themes);

        const splashScreenTheme = themes.find('style[@name="Theme.App.SplashScreen"]');

        [

            'windowSplashScreenAnimatedIcon',

            'windowSplashScreenAnimationDuration',

            'windowSplashScreenBackground',

            'windowSplashScreenBrandingImage',

            'windowSplashScreenIconBackgroundColor',

            'postSplashScreenTheme'

        ].forEach(themeKey => {

            const cdvConfigPrefKey = 'Android' + themeKey.charAt(0).toUpperCase() + themeKey.slice(1);

            const cdvConfigPrefValue = platformConfig.getPreference(cdvConfigPrefKey, this.platform);

            let themeTargetNode = splashScreenTheme.find(`item[@name="${themeKey}"]`);

            switch (themeKey) {

            case 'windowSplashScreenBackground':

                // use the user defined value for "colors.xml"

                updateProjectSplashScreenBackgroundColor(cdvConfigPrefValue, locations);

                // force the themes value to `@color/cdv_splashscreen_background`

                themeTargetNode.text = '@color/cdv_splashscreen_background';

                break;

            case 'windowSplashScreenAnimatedIcon':

                // handle here the cases of "png" vs "xml" (drawable)

                // If "png":

                //  - Clear out default or previous set "drawable/ic_cdv_splashscreen.xml" if exisiting.

                //  - Copy png in correct mipmap dir with name "ic_cdv_splashscreen.png"

                // If "xml":

                //  - Clear out "{mipmap}/ic_cdv_splashscreen.png" if exisiting.

                //  - Copy xml into drawable dir with name "ic_cdv_splashscreen.xml"

                // updateProjectSplashScreenIcon()

                // value should change depending on case:

                // If "png": "@mipmap/ic_cdv_splashscreen"

                // If "xml": "@drawable/ic_cdv_splashscreen"

                updateProjectSplashScreenImage(locations, themeKey, cdvConfigPrefKey, cdvConfigPrefValue);

                break;

            case 'windowSplashScreenBrandingImage':

                // display warning only when set.

                if (cdvConfigPrefValue) {

                    events.emit('warn', `"${themeKey}" is currently not supported by the splash screen compatibility library. https://issuetracker.google.com/issues/194301890`);

                }

                updateProjectSplashScreenImage(locations, themeKey, cdvConfigPrefKey, cdvConfigPrefValue);

                // force the themes value to `@color/cdv_splashscreen_icon_background`

                if (!cdvConfigPrefValue && themeTargetNode) {

                    splashScreenTheme.remove(themeTargetNode);

                } else if (cdvConfigPrefValue) {

                    // if there is no current node, create a new node.

                    if (!themeTargetNode) {

                        themeTargetNode = themes.getroot().makeelement('item', { name: themeKey });

                        splashScreenTheme.append(themeTargetNode);

                    }

                    // set the user defined color.

                    themeTargetNode.text = '@drawable/ic_cdv_splashscreen_branding';

                }

                break;

            case 'windowSplashScreenIconBackgroundColor':

                // use the user defined value for "colors.xml"

                updateProjectSplashScreenIconBackgroundColor(cdvConfigPrefValue, locations);

                // force the themes value to `@color/cdv_splashscreen_icon_background`

                if (!cdvConfigPrefValue && themeTargetNode) {

                    // currentItem.remove();

                    splashScreenTheme.remove(themeTargetNode);

                } else if (cdvConfigPrefValue) {

                    // if there is no current color, create a new node.

                    if (!themeTargetNode) {

                        themeTargetNode = themes.getroot().makeelement('item', { name: themeKey });

                        splashScreenTheme.append(themeTargetNode);

                    }

                    // set the user defined color.

                    themeTargetNode.text = '@color/cdv_splashscreen_icon_background';

                }

                break;

            case 'windowSplashScreenAnimationDuration':

                themeTargetNode.text = cdvConfigPrefValue || '200';

                break;

            case 'postSplashScreenTheme':

                themeTargetNode.text = cdvConfigPrefValue || '@style/Theme.AppCompat.NoActionBar';

                break;

            default:

                events.emit('warn', `The theme property "${themeKey}" does not exist`);

            }

        });

        fs.writeFileSync(locations.themes, themes.write({ indent: 4 }), 'utf-8');

      events.emit('verbose', 'Wrote out Android application themes to ' + locations.themes);
    }

    on the find() funtion on foreach, do you know whats happining?

    0
    Comment actions Permalink
  • Avatar
    Aishwarya Rh

    Hi, im getting the following error :

    Execution failed for task ':app:processDebugMainManifest'. > Manifest merger failed : android:exported needs to be explicitly specified for element <receiver#nl.xservices.plugins.ShareChooserPendingIntent>. Apps targeting Android 12 and higher are required to specify an explicit value for `android:exported` when the corresponding component has an intent filter defined. See https://developer.android.com/guide/topics/manifest/activity-element#exported for details

    even i have added this code:

    <edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application/activity[@android:name='MainActivity']" xmlns:android="http://schemas.android.com/apk/res/android">
    <activityandroid:exported="true"/>
    </edit-config>
    1
    Comment actions Permalink
  • Avatar
    wrg

    Thanks bro! This is what i was searching for 🤙

    1
    Comment actions Permalink
  • Avatar
    Damian Tarnawsky

    A good place for a discussion on issues updating to Cordova Android 11 is either the Ionic Discord server or the Ionic forum. If your company wants more detailed help then our Advisory services are what you are after, we often get on Zoom calls to troubleshoot code.

    Aishwarya, you are missing a space between activity and android in the line: <activityandroid:exported="true"/>

    0
    Comment actions Permalink

Article is closed for comments.