簡體   English   中英

如何解決“Failed to parse XML in AndroidManifest.xml”?

[英]How to solve "Failed to parse XML in AndroidManifest.xml"?

在 Android Studio 中我有一個同步錯誤:

ERROR: Failed to parse XML in C:\...\app\src\main\AndroidManifest.xml
ParseError at [row,col]:[70,1]
Message: expected start or end tag
Affected Modules: app

我將android:hardwareAccelerated ="true"添加到AndroidManifest.xml但這並沒有解決我的問題。 我應該如何解決這個問題?

AndroidManifest.xml

<!--android:hardwareAccelerated ="true"-->
<application
    android:name=".App"
    android:allowBackup="true"
    android:icon="@drawable/icon"
    android:label="@string/app_name"
    android:roundIcon="@drawable/icon_round"
    android:supportsRtl="true"
    android:theme="@style/Theme.MaterialComponents.Light.NoActionBar"
    android:hardwareAccelerated="true">
    <activity
        android:name=".SelectColor"
        android:screenOrientation="sensorPortrait"/>
    <activity
        android:name=".AddAimActivity"
        android:screenOrientation="sensorPortrait"/>
    <activity
        android:name=".MainActivity"
        android:screenOrientation="sensorPortrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".PopActivity"
        android:screenOrientation="sensorPortrait"/>
    <activity
        android:name=".AddActionAtivity"
        android:theme="@style/AppTheme"
        android:screenOrientation="sensorPortrait" />
    <activity
        android:name=".SelectIconActivity"
        android:screenOrientation="sensorPortrait"/>
    <activity
        android:name=".EditActionActivity"
        android:theme="@style/AppTheme"
        android:screenOrientation="sensorPortrait"/>
    <activity
        android:name=".EditRoutineActivity"
        android:theme="@style/AppTheme"
        android:screenOrientation="sensorPortrait"/>

    <activity
        android:name=".EditAimActivity"
        android:theme="@style/AppTheme"
        android:screenOrientation="sensorPortrait"/>
    <activity
        android:name=".AddReminder"
        android:screenOrientation="sensorPortrait"/>

    <receiver
        android:name=".AlarmReceiver"
        android:screenOrientation="sensorPortrait"/>

    <activity
        android:name=".AddRoutine"
        android:theme="@style/AppTheme"
        android:screenOrientation="sensorPortrait"/>
    <service android:name="net.eagledev.planner.BackgroundService" android:exported="false" />
    <service android:name=".NotificationService"/>

</application>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>

應用模塊

compileSdkVersion 28
defaultConfig {
    applicationId "net.eagledev.planner"
    minSdkVersion 23
    targetSdkVersion 28
    versionCode 5
    versionName "0.6"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
packagingOptions {
    exclude 'META-INF/proguard/androidx-annotations.pro'

}}

依賴關系

implementation fileTree(dir: 'libs', include: ['*.jar'])
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0-alpha'
implementation 'com.android.support:design:28.0.0'
implementation 'com.getbase:floatingactionbutton:1.10.1'
implementation 'com.github.clans:fab:1.6.2'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.android.support:recyclerview-v7:28'
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.android.support:recyclerview-selection:28.0.0'
def room_version = "1.1.1"
implementation "android.arch.persistence.room:runtime:$room_version"
annotationProcessor "android.arch.persistence.room:compiler:$room_version"
implementation 'com.android.support:gridlayout-v7:28.0.0'
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>

轉到項目文件夾,在 app ->> src ->> main 中,用記事本修改 AndroidManifest.xml。

你需要把 -uses permission- 放在

 <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.exemple">

<application>
</application>

只需轉到您的清單的第 70 行,您就會發現任何特殊字符,例如 - @、,、#.. 在我的例子中,它是一個點 (,)。 我剛剛刪除了點,錯誤就消失了。

原因是 [row,col]:[70,1] 處出現 ParseError

鑒於錯誤在第 70 行。

您的清單應采用以下格式:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.test">

    <uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>        
    <application 
        android:hardwareAccelerated="true">
        ...
    </application>

</manifest>

https://developer.android.com/guide/topics/manifest/manifest-intro

在處理舊項目並更新它時剛剛遇到了那個確切的錯誤。 我通過在文本編輯器 NotePadd++ 中打開清單文件並更正特殊字符問題來修復它。

在我的清單中,我在獲得 Internet 許可后有一個特殊字符。 說的是LS。 不確定它是什么,但我刪除了字符,保存了 XML,然后再次嘗試運行 Gradle Sync,它解決了問題。 從文本編輯器轉到 Manifest 文件的第 70 行並刪除特殊字符,然后嘗試查看 gradle 是否會在之后工作。

更新 gradle 后我遇到了類似的問題......在我的清單中我有......

<activity android:name=".motoController">
    android:screenOrientation="landscape"
</activity>

並將其更改為

<activity android:name=".motoController"
            android:screenOrientation="landscape"/>

問題消失了......

我有這個問題....

<application
    android:name=".data.ThisApplication"
    android:allowBackup="true"
    android:label="@string/app_name" />

<application
    android:name=".data.ThisApplication"
    android:allowBackup="true"
    android:label="@string/app_name" 

我只是刪除“/>”

在此之后沒有錯誤

  • 在我的情況下沒有什么只是刪除一個依賴項然后再次撤消它刷新gradle並刪除錯誤我的錯誤與上面相同希望它能幫助你

[row,col] 檢查 Manifest 文件中的確切行號和列號並刪除任何不需要的字符,然后您的問題就會解決。

如果錯誤沒有解決,那么嘗試清理、重建或構建項目。 有時重啟android studio會解決問題。 嘗試設置->無效並重新啟動->使緩存無效。

上述任何解決方案都可以解決此錯誤。 如果您有任何其他疑問,請在評論框中提問。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM