首页 > 解决方案 > Android Studio app.gradle 错误:程序类型已存在:android.support.v4.app.BackStackRecord$Op

问题描述

在执行我的项目的构建时,我收到此错误:

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

这是我的 app.gradle:

apply plugin: 'com.android.application'

android {
  compileSdkVersion 28
  defaultConfig {
    applicationId "mls.client"
    minSdkVersion 23
    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'
  implementation 'com.android.support.constraint:constraint-layout:1.1.3'
  implementation 'com.android.support:design: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'
  // VOLLEY
  implementation 'com.android.volley:volley:1.1.0'
  // GSON
  implementation 'com.google.code.gson:gson:2.4'
  // GMS
  implementation 'com.google.android.gms:play-services:8.3.0'
}

我的配置有什么问题?我认为版本有问题....我也有以下错误implementation 'com.android.support:appcompat-v7:28.0.0':所有 com.android.support 库必须使用完全相同的版本规范(混合版本可能导致运行时崩溃)。找到版本 28.0.0、22.2.0。示例包括 com.android.support:animated-vector-drawable:28.0.0 和 com.android.support:mediarouter-v7:22.2.0 less... (⌘F1) 有一些库的组合,或者工具和库,不兼容或可能导致错误。一种这样的不兼容性是使用不是最新版本的 Android 支持库版本(或者特别是低于您的 targetSdkVersion 的版本)进行编译。问题 ID:GradleCompatible

如果你能帮我解决这个问题,我会很高兴。谢谢

标签: androidgradle

解决方案


您需要在顶级 gradle 文件中添加 google() 存储库,并且它应该在 jcenter() 之前:

  buildscript {
      repositories {
              google()
              jcenter()
          }


    dependencies {
      classpath 'com.android.tools.build:gradle:3.2.1'
      classpath 'com.google.gms:google-services:4.0.2'
       }
    }

    allprojects {
         repositories {
                  google()
                 jcenter()
      }
    }

从您的 build.gradle 文件中删除它并再次同步

implementation 'com.google.android.gms:play-services:8.3.0'

推荐阅读