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

时间:2018-11-14 09:29:17

标签: android gradle

执行项目构建时,出现此错误:

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

如果您能帮助我解决该问题,我将非常高兴。 谢谢

2 个答案:

答案 0 :(得分:0)

请验证您所有的库都是最新的,因为您使用的是较旧的播放服务版本,应为17.x.x或类似版本。因为该lib也具有传递依赖关系,所以可能导致冲突。因此,我假设play-services库需要支持库v 22.X.X,但是您需要28.0.0,否则将失败。

因此,更新所有依赖项就可以了。

答案 1 :(得分:0)

您需要在顶级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'