【问题标题】:Gradle sync failed and ERROR: Failed to parse XML inGradle 同步失败并且 ERROR: Failed to parse XML in
【发布时间】:2020-02-01 09:40:11
【问题描述】:

我在使用 Gradle 时出错。我试图重新启动我的计算机和程序,但没有任何变化。我有同样的错误说ParseError at [row,col]:[17,9] Message: expected start or end tag

我试图在第 17 行找到一些不正常的东西,但对我来说一切都很正常。 在 build.gradle 文件中,当我单击某些行时,它会提出一些新版本,因此通常所有内容都是最新的。

我也在这个网站上查看它是否可以解决我的问题,但它没有帮助FAILURE: Gradle Build failed with an exception

build.gradle 应用程序

apply plugin: 'com.android.application'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"
    defaultConfig {
        applicationId "com.example.myapplication"
        minSdkVersion 18
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    implementation 'com.google.android.gms:play-services-ads:18.2.0'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'com.google.ads.mediation:facebook:5.5.0.0'
    implementation 'com.google.android.gms:play-services-ads:11.4.2'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.appcompat:appcompat:1.0.2'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'


}

build.gradle 信息

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        google()
        jcenter()

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.0'


    }

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }


allprojects {
    repositories {
        google()
        jcenter()
        maven{
            url "https://maven.google.com"
        }

    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

可能对你有帮助的 xml 代码

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">



    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        <com.google.android.gms.ads.AdView
            android:id="@+id/adView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:adSize="BANNER"
            app:adUnitId="ca-app-pub-2945227826409900/1799805283"></com.google.android.gms.ads.AdView>

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="96dp">

            <ScrollView
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical">

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:orientation="vertical">

                        <TableRow
                            android:layout_width="match_parent"
                            android:layout_height="match_parent">

                            <EditText
                                android:id="@+id/editText"
                                android:layout_width="wrap_content"
                                android:layout_height="99dp"
                                android:ems="10"
                                android:inputType="textPersonName" />

                            <Button
                                android:id="@+id/button3"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:text="search" />

                            <ProgressBar
                                android:id="@+id/progressBar"
                                style="?android:attr/progressBarStyle"
                                android:layout_width="102dp"
                                android:layout_height="83dp" />

                        </TableRow>

                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:orientation="horizontal">

                            <EditText
                                android:id="@+id/editText2"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:ems="10"
                                android:inputType="textPersonName"
                                android:text="add some text" />

                            <Button
                                android:id="@+id/button_send"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_weight="1"
                                android:text="Send" />
                        </LinearLayout>

                    </LinearLayout>

                </LinearLayout>
            </ScrollView>

            <androidx.constraintlayout.widget.Guideline
                android:id="@+id/guideline2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="vertical" />

        </TableRow>


        <WebView
            android:id="@+id/webview"
            android:layout_width="match_parent"
            android:layout_height="586dp" />

        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical" >

                <TextView
                    android:id="@+id/textView4"
                    android:layout_width="432dp"
                    android:layout_height="531dp"
                    android:text="TextView" />

            </LinearLayout>
        </ScrollView>


    </LinearLayout>


</androidx.constraintlayout.widget.ConstraintLayout>

android 清单

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.info">
    <uses-permission android:name="android.permission.INTERNET"></uses-permission>
    <uses-permission android:name="android.permission.BLUETOOTH"></uses-permission>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        android:launchMode="singleInstance"
        <meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="ca-app-pub-2945227826409900~3138961208"/>
        <activity android:name=".MainActivity">

            <intent-filter>

                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

【问题讨论】:

  • 请同时发布您的 AndroidManifest.xml 代码
  • 好的,我没想到它可以帮助你
  • 现在我更新它
  • 我也发现了错误,请检查我的回答并告诉我您的问题现在是否已解决

标签: android xml gradle


【解决方案1】:

正如您在AndroidManifest.xml 代码中看到的,以下行android:launchMode="singleInstance" 不在任何标记中

删除它然后错误就会消失

你的AndroidManifest.xml 应该是这样的

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.info">
    <uses-permission android:name="android.permission.INTERNET"></uses-permission>
    <uses-permission android:name="android.permission.BLUETOOTH"></uses-permission>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

        <meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="ca-app-pub-2945227826409900~3138961208"/>
        <activity android:name=".MainActivity">

            <intent-filter>

                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

额外:-启动模式配置android:launchMode="singleInstance"应用于activity

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-04-09
    • 2017-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-18
    • 2022-12-02
    相关资源
    最近更新 更多