【问题标题】:Ionic android 12 splash error while adding cordova-android@11添加cordova-android@11时出现Ionic android 12启动错误
【发布时间】:2022-08-18 18:00:48
【问题描述】:

由于 Google 在 Google Play 控制台上将最低 sdk 提高到 31,我不得不对 Android 12 进行一些更改和更新,但是当我尝试添加新的 Android 平台 android@11 时,我遇到了关于已更改的闪存的此错误科尔多瓦11

谁能帮助我?

非常感谢您提前

这是错误:

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.

引发错误的文件是:E:\\DEV\\IONIC\\donateApp_cord\\node_modules\\cordova-android\\lib\\prepare.js

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 existing.

            //  - 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);
}

在 foreach 上的 splashScreenTheme.find 功能上,有人可以帮我吗?

  • 我也有同样的问题。你找到解决办法了吗?

标签: cordova ionic-framework android-12


【解决方案1】:

您必须从您的应用程序的 config.xml 中删除启动画面,此链接如下

会帮助你 :

https://ionic.zendesk.com/hc/en-us/articles/7891143965975-Migrating-to-Cordova-Android-11

【讨论】:

    【解决方案2】:

    实际上,我做到了不是现在解决了这个问题,但向前迈出了一小步。

    错误发生在node_modules\cordova-android\lib\prepare.js方法中:updateProjectSplashScreen(...),因为var闪屏主题为空,因为主题 (= style[@name="Theme.App.SplashScreen"]) 未找到或 var主题目标节点为空,因为找不到主题项。

    我手动添加了主题主题.xml平台/android/app/src/main/res/values具有以下内容的目录:

    <?xml version='1.0' encoding='utf-8'?>
    <resources>
        <style name="Theme.App.SplashScreen" parent="@android:style/Theme.DeviceDefault.NoActionBar">
            <item name="android:windowBackground">@android:color/white</item>
            <item name="windowSplashScreenBackground">@color/cdv_splashscreen_background</item>
            <item name="windowSplashScreenAnimationDuration">200</item>
            <item name="postSplashScreenTheme">@style/Theme.AppCompat.NoActionBar</item>
        </style>
    </resources>
    

    这解决了构建期间的错误,但如果启动,应用程序会在启动屏幕上崩溃。我想我错误地配置了主题。我希望这里的任何人都可以更正themes.xml 文件。

    P.S.:同样的问题发布在 ionic 论坛:https://forum.ionicframework.com/t/ionic-android-12-splash-error-while-adding-cordova-android-11/225896

    P.P.S.:我必须解决离子迁移指南 (https://ionic.zendesk.com/hc/en-us/articles/7891143965975-Migrating-to-Cordova-Android-11) 中未提及的其他 2 个问题:

    • 不是消除科尔多瓦-插件-androidx-适配器防止出现以下错误:包 android.support.v4.content 不存在或包 android.support.v7.app 不存在。
    • 已更改编译实现在一些旧插件的 gradle 文件中(在平台/android/科尔多瓦插件徽章/XXX-badge.gradle, com-sarriaroman-photoviewer/XXX-photoviewer.gradle & phonegap-plugin-barcodescanner/XXX-barcodescanner.gradle)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-08-15
      • 1970-01-01
      • 1970-01-01
      • 2019-08-01
      • 1970-01-01
      • 2018-12-14
      • 2016-09-02
      相关资源
      最近更新 更多