【问题标题】:Duplicate classes when building in Android Studio在 Android Studio 中构建时重复的类
【发布时间】:2019-04-17 07:07:20
【问题描述】:

我在构建 Android Studio 项目时遇到错误。

程序类型已存在:com.google.android.gms.internal.measurement.zzdz

这是我的 build.gradle

apply plugin: 'com.android.application'
apply plugin: 'com.github.ben-manes.versions'
apply plugin: 'com.jakewharton.hugo'
apply plugin: 'io.fabric'
apply plugin: 'com.getkeepsafe.dexcount'

buildscript {
repositories {
    google()
    jcenter()
    maven { url 'https://maven.fabric.io/public' }
}

dependencies {
    classpath 'com.github.ben-manes:gradle-versions-plugin:0.11.3'
    classpath 'com.jakewharton.hugo:hugo-plugin:1.2.1'
    classpath 'io.fabric.tools:gradle:1.+'
    classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.6.2'
    classpath 'com.google.gms:google-services:3.2.1'
}
}
android {
compileSdkVersion 28
buildToolsVersion '28.0.3'
useLibrary 'org.apache.http.legacy'
defaultConfig {
    minSdkVersion 16
    targetSdkVersion 28
    versionCode 202
    versionName "2.0.0"
    buildConfigField "boolean", "CRASHLYTICS_ENABLED", "false"
}

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_7
    targetCompatibility JavaVersion.VERSION_1_7
}

flavorDimensions "type", "name"

productFlavors {
    magazines {
        dimension "type"
    }
    magazine {
        dimension "name"
        // Remove next line to enable Crashlytics and change false to true in second line
        ext.enableCrashlytics = false
        buildConfigField "boolean", "CRASHLYTICS_ENABLED", "false"
    }
    wind {
        dimension "name"
        // Remove next line to enable Crashlytics and change false to true in second line
        ext.enableCrashlytics = false
        buildConfigField "boolean", "CRASHLYTICS_ENABLED", "false"
    }
    script {
        //// Use custom gradle file if it exists in script product flavor folder
        if (new File("./main/src/script/custom.gradle").exists()) {
            println 'custom.gradle script exists'
            apply from: "../main/src/script/custom.gradle";
        } else {
            throw new GradleException('No custom.gradle script exists')
        }
        //applicationId scriptApplicationId
        dimension "name"
        buildConfigField "boolean", "CRASHLYTICS_ENABLED", "true"
    }
}

lintOptions {
    abortOnError false
}

packagingOptions {
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/NOTICE.txt'
}
}

repositories {
maven { url 'https://maven.fabric.io/public' }
maven { url "https://jitpack.io" }
}

dependencies {
implementation fileTree(include: '*.jar', dir: 'libs')
//added here
implementation fileTree(include: '*.java', dir: 'libs')
implementation fileTree(include: '*.so', dir: 'libs')
//til here
implementation project(':appiraterAndroid')
implementation 'de.greenrobot:eventbus:2.4.0'
implementation 'com.squareup.okhttp:okhttp:2.7.5'
implementation 'com.squareup.okhttp:okhttp-urlconnection:2.4.0'
implementation 'com.squareup.picasso:picasso:2.5.2'
implementation 'commons-io:commons-io:2.4'
implementation 'io.reactivex:rxandroid:0.24.0'
implementation 'uk.co.chrisjenx:calligraphy:2.1.0'
implementation 'com.github.castorflex.smoothprogressbar:library:1.1.0'
implementation 'com.github.castorflex.smoothprogressbar:library-circular:1.1.0'
implementation 'com.anjlab.android.iab.v3:library:1.0.26@aar'
implementation 'com.rengwuxian.materialedittext:library:2.1.4'
implementation 'net.danlew:android.joda:2.8.1'
implementation('com.crashlytics.sdk.android:crashlytics:2.4.0@aar') {
    transitive = true;
}
implementation 'com.android.support:support-annotations:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support:support-core-utils:28.0.0'
implementation 'com.android.support:customtabs:28.0.0'
implementation('com.github.afollestad.material-dialogs:core:0.8.5.5@aar') {
    transitive = true
}
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.google.android.gms:play-services-analytics:16.0.5'
implementation 'com.google.android.gms:play-services-gcm:16.0.0'
implementation 'com.google.android.gms:play-services-ads:17.1.0'
implementation "com.google.android.gms:play-services-base:16.0.1"

}
apply plugin: 'com.google.gms.google-services'

我确定与依赖项和版本有关,但我找不到。

我尝试清理 gradle 缓存并重新启动 Android Studio,但我仍然收到上述错误。

【问题讨论】:

    标签: android android-studio gradle google-play-services


    【解决方案1】:

    将项目迁移到 androidx 支持

    点击 -> 重构 -> 迁移到 AndroidX

    并更新库

    【讨论】:

    • 遇到了同样的问题“程序类型已经存在:com.google.android.gms.internal.measurement.zzdz”并在更新时解决了同样的问题。
    • 更新你的库还不够吗?我看不出迁移到 AndroidX 会有什么帮助。如果这真的是解决方案,那么实际上每个应用程序都会被破坏,这是没有意义的。
    • 他可能会尝试更新库而不更新到 androidx。请尝试一下
    猜你喜欢
    • 1970-01-01
    • 2023-01-19
    • 2013-06-28
    • 1970-01-01
    • 1970-01-01
    • 2016-06-03
    • 1970-01-01
    • 2018-05-20
    • 2016-11-01
    相关资源
    最近更新 更多