Cordova 构建/运行 android 失败:无法读取 null 的属性“标签”

Posted

技术标签:

【中文标题】Cordova 构建/运行 android 失败:无法读取 null 的属性“标签”【英文标题】:Cordova build/run android fails: Cannot read property 'tag' of null 【发布时间】:2019-08-06 11:31:18 【问题描述】:

我正在构建一个 Ionic 应用程序,我想使用插件 firebasex。

不幸的是,在运行 Ionic cordova build/run android 时,我收到以下错误:Cannot read property 'tag' of null

看来我的 config.xml 没问题。

我唯一发现的是缺少“名称”标签,但它存在于我的 xml 中。

如果我运行 cordova run android --verbose,我会得到以下输出:

No scripts found for hook "before_run".
No scripts found for hook "before_prepare".
Checking config.xml and package.json for saved platforms that haven't been added to the project
Config.xml and package.json platforms are the same. No pkg.json modification.
Package.json and config.xml platforms are different. Updating config.xml with most current list of platforms.
PlatformApi successfully found for platform android
Checking config.xml for saved plugins that haven't been added to the project
Checking for any plugins added to the project that have not been installed in android platform
No differences found between plugins added to project and installed in android platform. Continuing...
Generating platform-specific config.xml from defaults for android at C:\[...]\platforms\android\app\src\main\res\xml\config.xml
Cannot read property 'tag' of null
TypeError: Cannot read property 'tag' of null
    at Object.resolveParent (C:\[...]\node_modules\cordova-common\src\util\xml-helpers.js:192:58)
    at Object.graftXMLMerge (C:\[...]\node_modules\cordova-common\src\util\xml-helpers.js:92:37)
    at ConfigFile_graft_child [as graft_child] (C:\[...]\node_modules\cordova-common\src\ConfigChanges\ConfigFile.js:110:42)
    at PlatformMunger_apply_file_munge [as apply_file_munge] (C:\[...]\node_modules\cordova-common\src\ConfigChanges\ConfigChanges.js:81:34)
    at PlatformMunger.reapply_global_munge (C:\[...]\node_modules\cordova-common\src\ConfigChanges\ConfigChanges.js:268:14)
    at updateConfigFilesFrom (C:\[...]\platforms\android\cordova\lib\prepare.js:113:18)
    at Api.module.exports.prepare (C:\[...]\platforms\android\cordova\lib\prepare.js:44:20)
    at Api.prepare (C:\[...]\platforms\android\cordova\Api.js:177:45)
    at C:\[...]\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\src\cordova\prepare.js:105:36
    at _fulfilled (C:\[...]\AppData\Roaming\npm\node_modules\cordova\node_modules\q\q.js:854:54)

我的 config.xml:

<?xml version='1.0' encoding='utf-8'?>
<widget id="com.my.app" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <allow-navigation href="http://localhost/*" />
    <allow-navigation href="https://localhost/*" />
    <allow-navigation href="ionic://*" />
    <feature name="IonicWebView">
        <param name="android-package" value="com.ionicframework.cordova.webview.IonicWebView" />
    </feature>
    <feature name="File">
        <param name="android-package" value="org.apache.cordova.file.FileUtils" />
        <param name="onload" value="true" />
    </feature>
    <allow-navigation href="cdvfile:*" />
    <feature name="FileTransfer">
        <param name="android-package" value="org.apache.cordova.filetransfer.FileTransfer" />
    </feature>
    <feature name="Camera">
        <param name="android-package" value="org.apache.cordova.camera.CameraLauncher" />
    </feature>
    <feature name="StreamingMedia">
        <param name="android-package" value="com.hutchind.cordova.plugins.streamingmedia.StreamingMedia" />
    </feature>
    <feature name="Capture">
        <param name="android-package" value="org.apache.cordova.mediacapture.Capture" />
    </feature>
    <feature name="Base64">
        <param name="android-package" value="com.badrit.Base64.Base64Plugin" />
    </feature>
    <feature name="SocialSharing">
        <param name="android-package" value="nl.xservices.plugins.SocialSharing" />
    </feature>
    <feature name="FileChooser">
        <param name="android-package" value="com.megster.cordova.FileChooser" />
    </feature>
    <name>myapp</name>
    <description>super app</description>
    <author email="contact@contact.contact" href="http://contact.contact/">contact</author>
    <content src="index.html" />
    <access origin="*" />
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />
    <allow-intent href="tel:*" />
    <allow-intent href="sms:*" />
    <allow-intent href="mailto:*" />
    <allow-intent href="geo:*" />
    <edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application" xmlns:android="http://schemas.android.com/apk/res/android">
        <application android:networkSecurityConfig="@xml/network_security_config" />
    </edit-config>
    <resource-file src="resources/android/xml/network_security_config.xml" target="app/src/main/res/xml/network_security_config.xml" />
    <allow-intent href="market:*" />
    <icon density="ldpi" src="resources/android/icon/drawable-ldpi-icon.png" />
    <icon density="mdpi" src="resources/android/icon/drawable-mdpi-icon.png" />
    <icon density="hdpi" src="resources/android/icon/drawable-hdpi-icon.png" />
    <icon density="xhdpi" src="resources/android/icon/drawable-xhdpi-icon.png" />
    <icon density="xxhdpi" src="resources/android/icon/drawable-xxhdpi-icon.png" />
    <icon density="xxxhdpi" src="resources/android/icon/drawable-xxxhdpi-icon.png" />
    <splash density="land-ldpi" src="resources/android/splash/drawable-land-ldpi-screen.png" />
    <splash density="land-mdpi" src="resources/android/splash/drawable-land-mdpi-screen.png" />
    <splash density="land-hdpi" src="resources/android/splash/drawable-land-hdpi-screen.png" />
    <splash density="land-xhdpi" src="resources/android/splash/drawable-land-xhdpi-screen.png" />
    <splash density="land-xxhdpi" src="resources/android/splash/drawable-land-xxhdpi-screen.png" />
    <splash density="land-xxxhdpi" src="resources/android/splash/drawable-land-xxxhdpi-screen.png" />
    <splash density="port-ldpi" src="resources/android/splash/drawable-port-ldpi-screen.png" />
    <splash density="port-mdpi" src="resources/android/splash/drawable-port-mdpi-screen.png" />
    <splash density="port-hdpi" src="resources/android/splash/drawable-port-hdpi-screen.png" />
    <splash density="port-xhdpi" src="resources/android/splash/drawable-port-xhdpi-screen.png" />
    <splash density="port-xxhdpi" src="resources/android/splash/drawable-port-xxhdpi-screen.png" />
    <splash density="port-xxxhdpi" src="resources/android/splash/drawable-port-xxxhdpi-screen.png" />
    <preference name="loglevel" value="DEBUG" />
    <preference name="webView" value="com.ionicframework.cordova.webview.IonicWebViewEngine" />
    <preference name="ScrollEnabled" value="false" />
    <preference name="android-minSdkVersion" value="19" />
    <preference name="BackupWebStorage" value="none" />
    <preference name="SplashMaintainAspectRatio" value="true" />
    <preference name="FadeSplashScreenDuration" value="300" />
    <preference name="SplashShowOnlyFirstTime" value="false" />
    <preference name="SplashScreen" value="screen" />
    <preference name="SplashScreenDelay" value="3000" />
    <engine name="android" spec="^8.0.0" />
</widget>

感谢您的帮助!

【问题讨论】:

【参考方案1】:

移除android平台并重新添加

ionic cordova platform rm android
ionic cordova platform add android

【讨论】:

嗨!感谢您的帮助。这个我已经试过了,还是不行! 删除或保留 package.json 另一个文件夹,然后运行 ​​cordova prepare 并检查 越来越严重了!我现在有以下错误:发生未处理的异常:找不到模块“@ionic/angular-toolkit”

以上是关于Cordova 构建/运行 android 失败:无法读取 null 的属性“标签”的主要内容,如果未能解决你的问题,请参考以下文章

Cordova Android 构建失败

Cordova android 构建:app:processDebugResources 失败

在离子2处失败'离子cordova运行android'

Ionic Cordova 构建失败并出现错误无法应用插件

使用cordova构建apk失败

Ionic Cordova 7.1.4 Android 构建失败