Android Studio:错误:程序类型已存在:android.support.v4.app.BackStackRecord $ Op

时间:2018-10-21 11:25:38

标签: android android-gradle

我的gradle app.gradle文件:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.prutheus.se"
        minSdkVersion 24
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    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.google.android.gms:play-services:8.3.0'
}

当我想在调试器中运行我的应用程序时,出现错误:

Error: Program type already present: android.support.v4.app.BackStackRecord$Op

我已经了解到,com.google.android.gms的实现可能与它有关,但是我不知道如何解决该问题?

2 个答案:

答案 0 :(得分:0)

添加的implementation 'com.google.android.gms:play-services:8.3.0'看上去有点让人迷惑。

您使用的是更新后的SupportLibrary -> 28,但play-services似乎很旧。

在您的根build.gradle中添加:

dependencies {
    classpath 'com.android.tools.build:gradle:3.2.1' // and use the updated version
    classpath 'com.google.gms:google-services:4.1.0' // add this
    ..
    .

还请确保有关存储库:

  

确保您的顶级build.gradle包含对   google()回购或到maven { url "https://maven.google.com" }

阅读Setup Google Play Services

答案 1 :(得分:0)

    classpath "com.android.tools.build:gradle:3.4.2"
<块引用>

这是灵魂:

转到构建 Gradle 应用程序并执行此操作

buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:3.4.2"

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