android - Android Studio-Gradle同步失败

标签 android android-studio gradle synchronization

您好,我是Android编程的新手,目前我已经终止了Gradle Sync的一些问题。
我尝试了很多类似重建/清理项目的方法,但似乎没有任何办法解决问题。

这是产生同步问题的Gradle文件:

   apply plugin: 'com.android.application'
    apply plugin: 'com.google.gms.google-services'

    android {
        compileSdkVersion 29
        buildToolsVersion "29.0.2"
        defaultConfig {
            applicationId "com.example.fragment"
            minSdkVersion 21
            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.1.0'
        implementation 'androidx.appcompat:appcompat:1.1.0'
        implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
        implementation 'com.google.firebase:firebase-database:19.2.1'
        testImplementation 'junit:junit:4.12'
        androidTestImplementation 'androidx.test:runner:1.2.0'
        androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
        implementation 'com.google.android.material:material:1.1.0'
        implementation 'com.firebase:firebase-client-android:2.5.2'
        implementation 'com.google.android.gms:play-services-auth:17.0.0'
        implementation 'me.dm7.barcodescanner:zxing:1.9'
        //noinspection GradleCompatible
        implementation 'com.android.support:appcompat-v7:22.0.0'
        implementation 'com.google.code.gson:gson:2.8.6'

    }

这是我同步Gradle时收到的错误消息:
Failed to parse XML in C:\Users\cbuch\AndroidProjects\FoodGentApp\app\src\main\AndroidManifest.xml
ParseError at [row,col]:[19,13]
Message: expected start or end tag
Affected Modules: <a href="openFile:C:/Users/cbuch/AndroidProjects/FoodGentApp/app/build.gradle">app</a>

最后但并非最不重要的一点是:
<?xml version="1.0" encoding="UTF-8"?>

-<manifest android:versionName="0.5" android:versionCode="1" package="com.example.fragment" xmlns:android="http://schemas.android.com/apk/res/android">

<uses-sdk android:targetSdkVersion="29" android:minSdkVersion="21"/>

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

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

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

<!-- Although the *SdkVersion is captured in gradle build files, this is required for non gradle builds -->


<!-- <uses-sdk android:minSdkVersion="14"/> -->


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

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


-<application android:theme="@style/AppTheme" android:supportsRtl="true" android:label="@string/app_name" android:icon="@drawable/kuehli" android:debuggable="true" android:appComponentFactory="androidx.core.app.CoreComponentFactory" android:allowBackup="true">


-<activity android:name="com.example.foodgent.UserInterface.MainActivity" android:windowSoftInputMode="adjustResize">
android:windowSoftInputMode="adjustResize" 

-<intent-filter>

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

<category android:name="android.intent.category.LAUNCHER"/>

</intent-filter>

</activity>

<activity android:name="com.example.foodgent.UserInterface.SecondActivity"/>

<activity android:name="com.example.foodgent.UserInterface.AddItem"/>

<activity android:name="com.example.foodgent.UserInterface.AddCooking"/>

<activity android:name="com.example.foodgent.UserInterface.AddShop"/>

<activity android:name="com.example.foodgent.Logic.ScanCodeActivity"/>

<meta-data android:name="preloaded_fonts" android:resource="@array/preloaded_fonts"/>


-<service android:name="com.google.firebase.components.ComponentDiscoveryService" android:exported="false" android:directBootAware="true">

<meta-data android:name="com.google.firebase.components:com.google.firebase.database.DatabaseRegistrar" android:value="com.google.firebase.components.ComponentRegistrar"/>

</service>

<activity android:name="com.google.android.gms.auth.api.signin.internal.SignInHubActivity" android:theme="@android:style/Theme.Translucent.NoTitleBar" android:exported="false" android:excludeFromRecents="true"/>

<!--Service handling Google Sign-In user revocation. For apps that do not integrate withGoogle Sign-In, this service will never be started. -->


<service android:name="com.google.android.gms.auth.api.signin.RevocationBoundService" android:exported="true" android:permission="com.google.android.gms.auth.api.signin.permission.REVOCATION_NOTIFICATION"/>

<activity android:name="com.google.android.gms.common.api.GoogleApiActivity" android:theme="@android:style/Theme.Translucent.NoTitleBar" android:exported="false"/>

<provider android:name="com.google.firebase.provider.FirebaseInitProvider" android:exported="false" android:initOrder="100" android:authorities="com.example.fragment.firebaseinitprovider"/>

<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"/>

</application>

</manifest> 

最佳答案

您正在android.Manifest文件中添加无效 token 。我已经删除了这些标记。请立即尝试:

    <?xml version="1.0" encoding="UTF-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.fragment"
    android:versionCode="1"
    android:versionName="0.5">

    <uses-sdk
        android:minSdkVersion="21"
        android:targetSdkVersion="29" />

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

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

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

    <!-- Although the *SdkVersion is captured in gradle build files, this is required for non gradle builds -->


    <!-- <uses-sdk android:minSdkVersion="14"/> -->


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

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


    <application
        android:allowBackup="true"
        android:appComponentFactory="androidx.core.app.CoreComponentFactory"
        android:debuggable="true"
        android:icon="@drawable/kuehli"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">


        <activity
            android:name="com.example.foodgent.UserInterface.MainActivity"
            android:windowSoftInputMode="adjustResize">

            <intent-filter>

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

                <category android:name="android.intent.category.LAUNCHER" />

            </intent-filter>

        </activity>

        <activity android:name="com.example.foodgent.UserInterface.SecondActivity" />

        <activity android:name="com.example.foodgent.UserInterface.AddItem" />

        <activity android:name="com.example.foodgent.UserInterface.AddCooking" />

        <activity android:name="com.example.foodgent.UserInterface.AddShop" />

        <activity android:name="com.example.foodgent.Logic.ScanCodeActivity" />

        <meta-data
            android:name="preloaded_fonts"
            android:resource="@array/preloaded_fonts" />


        <service
            android:name="com.google.firebase.components.ComponentDiscoveryService"
            android:directBootAware="true"
            android:exported="false">

            <meta-data
                android:name="com.google.firebase.components:com.google.firebase.database.DatabaseRegistrar"
                android:value="com.google.firebase.components.ComponentRegistrar" />

        </service>

        <activity
            android:name="com.google.android.gms.auth.api.signin.internal.SignInHubActivity"
            android:excludeFromRecents="true"
            android:exported="false"
            android:theme="@android:style/Theme.Translucent.NoTitleBar" />

        <!--Service handling Google Sign-In user revocation. For apps that do not integrate withGoogle Sign-In, this service will never be started. -->


        <service
            android:name="com.google.android.gms.auth.api.signin.RevocationBoundService"
            android:exported="true"
            android:permission="com.google.android.gms.auth.api.signin.permission.REVOCATION_NOTIFICATION" />

        <activity
            android:name="com.google.android.gms.common.api.GoogleApiActivity"
            android:exported="false"
            android:theme="@android:style/Theme.Translucent.NoTitleBar" />

        <provider
            android:name="com.google.firebase.provider.FirebaseInitProvider"
            android:authorities="com.example.fragment.firebaseinitprovider"
            android:exported="false"
            android:initOrder="100" />

        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />

    </application>

</manifest> 

关于android - Android Studio-Gradle同步失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60596832/

相关文章:

android - JQuery 不适用于 android 浏览器

android - 从堆栈调用 Activity 而不是启动新实例

Android Studio 调试器查看位图

android - 上传我的应用程序时出现此错误 : Upload failed You need to use a different version code for your APK than version code 1

Android Studio 无法识别 wav 文件

android - 如何将Crosswalk项目添加到Android studio?

java - FindViewById 在类类型 Service 中?

java - 如何将 Canvas 绘图转换为图像然后在屏幕上拖动它?

java - Gradle Android "Duplicate class foo found in module bar"错误

java - 如何在构建期间仅列出 Gradle 中的 runtimeClasspath 解析依赖项?