添加cordova-android@11时出现离子android 12启动错误

rwqw0loc  于 2022-11-15  发布在  Android
关注(0)|答案(3)|浏览(241)

由于谷歌提高了最低sdk到31在Google Play控制台我不得不作出一些变化和更新Android 12,但当我试图添加一个新的Android平台android@11我有这个错误关于闪存已改变cordova 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\节点模块\cordova-android\库\准备.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);
}

在splashscreentheme上。在foreach上找到函数,有人能帮助我吗?

b4lqfgs4

b4lqfgs41#

如果它对任何人都有帮助,我发现我使用的一个插件(特别是cordova-plugin-telerik-imagepicker)正在将自己的themes.xml文件写入app/src/main/res/values,它会 * 覆盖 * cordova 生成的模板。
这就是为什么Cordova在尝试更新themes.xml中不再存在的元素时会崩溃。
我通过分叉插件和删除它的themes.xml解决了它。不知道这对插件有什么影响,但我不怀疑太多...

qf9go6mv

qf9go6mv2#

您必须从应用程序的config.xml中删除闪屏,请单击下面的链接
将帮助您:


exdqitrt

exdqitrt3#

事实上,我解决了编译问题,但应用程序只在android 12上运行,在所有其他android版本上都会在闪屏上崩溃。
错误出现在方法的节点_模块\cordova-android\lib\prepare. js中:updateProjectSplashScreen(...),因为找不到主题(= style[@name="Theme.App.SplashScreen"]),所以varsplashScreenTheme为null,或者找不到主题项目,所以varthemeTargetNode为null。
我在platforms/android/app/src/main/res/values目录下的themes.xml(& colors.xml)中手动添加了主题,内容如下:

<?xml version='1.0' encoding='utf-8'?>
<resources>
    <style name="Theme.App.SplashScreen" parent="@android:style/Theme.DeviceDefault.NoActionBar">
        <!-- Set the splash screen background -->
        <!-- <item name="android:windowBackground">@android:color/white</item> -->
        <item name="windowSplashScreenBackground">@color/cdv_splashscreen_background</item>
        
        <!-- Use windowSplashScreenAnimatedIcon to add either a drawable or an animated drawable. One of these is required. -->
        <item name="windowSplashScreenAnimatedIcon">@drawable/ic_cdv_splashscreen</item>
        
        <!-- Required for animated icons -->
        <item name="windowSplashScreenAnimationDuration">200</item>
        
        <!-- Required: Set the theme of the Activity that directly follows your splash screen. -->
        <!-- <item name="postSplashScreenTheme">@style/Theme.App</item> -->
        <item name="postSplashScreenTheme">@style/Theme.AppCompat.NoActionBar</item>
    </style>
</resources>

colors.xml的内容:

<?xml version='1.0' encoding='utf-8'?>
<resources xmlns:tools="http://schemas.android.com/tools">
    <color name="cdv_splashscreen_background">#FFFFFF</color>
</resources>

这解决了构建过程中的错误,但是应用程序在启动时在启动屏幕上崩溃,没有错误。我想我错误地配置了主题。我希望这里的任何人都可以纠正themes.xml文件。
P.S.:同样的问题被张贴在离子论坛: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个问题:

*删除cordova-plugin-androidx-adapter以防止出现以下错误:您访问的页面不存在或已被删除android.support.v7.app信息

  • 在一些旧插件的gradle文件中更改了编译到实现(在平台/android/cordova-plugin-badge/XXX-badge.gradle、com-sarriaroman-photoviewer/XXX-photoviewer.gradle和phonegap-plugin-barcodescanner/XXX-barcodescanner.gradle中)

我通过使用package.json中的“before ionic构建脚本”自动执行所有更正,例如:

"scripts": { "ionic:build:before": "./scripts/fix_android.sh", ... }

脚本/fix_android.sh的内容:

#!/usr/bin/env bash
echo ""
echo "Executing fix_android.sh"

## Copy resources/android/colors.xml & themes.xml to platforms/android/app/src/main/res/values
target=platforms/android/app/src/main/res/values
if [ -d "$target" ]; then
    file4="resources/android/colors.xml"
    if [ -f "$file4" ]; then
      cp -rvf "$file4" platforms/android/app/src/main/res/values
      echo "Copied colors.xml"
    else
      echo ${file4}" not found!"
    fi
    file5="resources/android/themes.xml"
    if [ -f "$file5" ]; then
      cp -rvf "$file5" platforms/android/app/src/main/res/values
      echo "Copied themes.xml"
    else
      echo ${file5}" not found!"
    fi
else
    echo ${target}" not found!"
fi

## Change compile to implementation in old plugins' gradle files
file6="platforms/android/cordova-plugin-badge/XXX-badge.gradle"
if [ -f "$file6" ]; then
    if grep -lr "compile" "$file6"; then
        sed -i '' "s/compile/implementation/g" "$file6"
        echo "Changed compile to implementation in XXX-badge.gradle"
    else
        echo "$file6"
        echo "File already corrected!"  
    fi
else
    echo ${file6}" not found!"
fi
file7="platforms/android/com-sarriaroman-photoviewer/XXX-photoviewer.gradle"
if [ -f "$file7" ]; then
    if grep -lr "compile" "$file7"; then
        sed -i '' "s/compile/implementation/g" "$file7"
        echo "Changed compile to implementation in XXX-photoviewer.gradle"
    else
        echo "$file7"
        echo "File already corrected!"
    fi  
else
    echo ${file7}" not found!"
fi
file8="platforms/android/phonegap-plugin-barcodescanner/XXX-barcodescanner.gradle"
if [ -f "$file8" ]; then
    if grep -lr "compile" "$file8"; then
        sed -i '' "s/compile/implementation/g" "$file8"
        echo "Changed compile to implementation in XXX-barcodescanner.gradle"
    else
        echo "$file8"
        echo "File already corrected!"  
    fi
else
    echo ${file8}" not found!"
fi

## Remove all <splash> tags from config.xml
file9="config.xml"
if [ -f "$file9" ]; then
    if grep -lr "<splash" "$file9"; then
        sed -i '' "s/<splash .* \/>//g" "$file9"
        echo "Removed <splash> tags in config.xml"
    else
        echo "$file9"
        echo "File already corrected!"  
    fi
else
    echo ${file9}" not found!"
fi

echo ""
echo ""

相关问题