由于谷歌提高了最低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上找到函数,有人能帮助我吗?
3条答案
按热度按时间b4lqfgs41#
如果它对任何人都有帮助,我发现我使用的一个插件(特别是cordova-plugin-telerik-imagepicker)正在将自己的
themes.xml
文件写入app/src/main/res/values
,它会 * 覆盖 * cordova 生成的模板。这就是为什么Cordova在尝试更新
themes.xml
中不再存在的元素时会崩溃。我通过分叉插件和删除它的
themes.xml
解决了它。不知道这对插件有什么影响,但我不怀疑太多...qf9go6mv2#
您必须从应用程序的config.xml中删除闪屏,请单击下面的链接
将帮助您:
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)中手动添加了主题,内容如下:
colors.xml的内容:
这解决了构建过程中的错误,但是应用程序在启动时在启动屏幕上崩溃,没有错误。我想我错误地配置了主题。我希望这里的任何人都可以纠正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信息
我通过使用package.json中的“before ionic构建脚本”自动执行所有更正,例如:
脚本/fix_android.sh的内容: