Android 添加少量依赖项会在构建项目时导致错误

Android 添加少量依赖项会在构建项目时导致错误,android,firebase,google-cloud-firestore,Android,Firebase,Google Cloud Firestore,最近,我添加了一些依赖项,并且我可能弄乱了其中的一些依赖项,这些依赖项在构建项目时会导致错误。我尝试了许多版本组合,但都失败了 错误: Information:Gradle tasks [:app:assembleDebug] Error:Program type already present: com.google.android.material.internal.package-info Information:BUILD FAILED in 8s Information:1 error

最近,我添加了一些依赖项,并且我可能弄乱了其中的一些依赖项,这些依赖项在构建项目时会导致错误。我尝试了许多版本组合,但都失败了

错误:

Information:Gradle tasks [:app:assembleDebug]
Error:Program type already present: com.google.android.material.internal.package-info
Information:BUILD FAILED in 8s
Information:1 error
Information:0 warnings
Information:See complete output in console
日志:

这是我的
AndroidManifest.xml
代码:

    <?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.msuraksha.suraksha">

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

    <application
        tools:replace="android:appComponentFactory"
        android:appComponentFactory="whateverString"
        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">
        <activity android:name=".LoginActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".RegisterActivity" />
        <activity android:name=".HomeActivity" />
        <activity
            android:name=".Home"
            android:label="@string/title_activity_home"
            android:theme="@style/AppTheme.NoActionBar" />
        <activity android:name=".ReportActivity" />
        <activity android:name=".MonitorReportsActivity" />
        <activity android:name=".Report_Item" />
        <activity android:name=".declare_emergency" />
        <activity android:name=".alerts"></activity>
    </application>

    </manifest>
build.gradle
(应用程序级)


我尝试了许多解决方案,但都失败了,每个解决方案都给我带来了一个新问题。

自从您添加
实现'com.google.android.material:material:1.0.0'
依赖项和使用支持库后,您出现了此错误

因此,您应该使用所有的
androidx
依赖项

而不是这些依赖项:

     implementation 'com.android.support:support-v4:28.0.0'
     androidTestImplementation 'com.android.support.test:runner:1.0.2'
     androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
     implementation 'com.android.support:support-annotations:28.0.0'
     implementation 'com.google.android.material:material:1.0.0'
     implementation 'com.android.support:design:28.0.0-alpha1'
使用这些:

     implementation 'androidx.legacy:legacy-support-v4:1.0.0'
     androidTestImplementation 'androidx.test:runner:1.1.0'
     androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
     implementation 'androidx.annotation:annotation:1.0.0'
     implementation 'com.google.android.material:material:1.1.0-alpha02'
我们删除了
设计:28.0.0-alpha1
,因为它包含在
材料:1.0.0-alpha02

然后您应该将这些行添加到
gradle.properties
文件中

     android.useAndroidX = true
     android.enableJetifier = false
最后,您应该删除旧的导入,并从androidx包中再次导入,如下所示:

     import androidx.appcompat.app.AppCompatActivity;

请帮帮我。。。我在Dependencies中尝试了许多版本更改,但都不起作用。错误:任务“”的执行失败:应用程序:transformDexArchiveWithExternalLibsDexMergerForDebug'>java.lang.RuntimeException:com.android.builder.dexing.DexArchiveMergerException:无法合并dex@SuyashToRescue我的答案更新了。请再查一下。
     implementation 'androidx.legacy:legacy-support-v4:1.0.0'
     androidTestImplementation 'androidx.test:runner:1.1.0'
     androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
     implementation 'androidx.annotation:annotation:1.0.0'
     implementation 'com.google.android.material:material:1.1.0-alpha02'
     android.useAndroidX = true
     android.enableJetifier = false
     import androidx.appcompat.app.AppCompatActivity;