Gradle同步失败,并出现错误:无法解析XML

时间:2020-02-01 09:40:11

标签: android xml gradle

我对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 manifester

<?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>

1 个答案:

答案 0 :(得分:0)

在您的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"适用于活动