已经添加了'尝试构建apk时出错:如何识别重复的依赖项?

时间:2017-12-22 17:52:26

标签: android android-gradle apk dependency-management

(对于任何格式化问题道歉,SO&#s解析逻辑充其量是可疑的,我做了我被迫做的事情,所以我可以提交这个问题)

所以我的应用程序运行正常,但是当我尝试生成一个已签名的apk时,我得到10个错误,都非常相似。

     Error:Uncaught translation error: java.lang.IllegalArgumentException: 
already added: Lcom/google/common/base/FinalizableReference;
     Error:Uncaught translation error: java.lang.IllegalArgumentException: 
already added: Lcom/google/common/base/FinalizableReferenceQueue;
     Error:Uncaught translation error: java.lang.IllegalArgumentException: 
already added: 
Lcom/google/common/base/FinalizableReferenceQueue$DecoupledLoader;
     (SNIP!)  errors end with this:
     Error:Execution failed for task 
':newAppVariable:transformClassesWithDexForRelease'.
     > com.android.build.api.transform.TransformException: 
com.android.ide.common.process.ProcessException: 
java.util.concurrent.ExecutionException: java.lang.RuntimeException: 
 Translation has been interrupted

从阅读SO,我收集到我有某种重复的依赖关系。这是我的顶级gradle(包括以下Eyad建议的更改):

buildscript {
    repositories {
        jcenter()
        google()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        classpath 'com.google.gms:google-services:3.1.2'
    }
}

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

这是我的模块级gradle(再次,这是v 2.0,其中包括Eyad推荐的更改):

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

    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
    }
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

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


android {
    compileSdkVersion 26
    buildToolsVersion '26.0.2'

    defaultConfig {
        applicationId "com.mogl"
        minSdkVersion 21
        targetSdkVersion 26
        multiDexEnabled true
    }

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

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles 'proguard.cfg'
        }
    }

    useLibrary 'org.apache.http.legacy'

    dexOptions {
        javaMaxHeapSize "4g"
        preDexLibraries = false
    }



    lintOptions {
        disable 'ValidFragment'
    }

}

dependencies {
    implementation 'org.greenrobot:eventbus:3.1.1'
    api files('libs/client-0.0.1-SNAPSHOT-jar-with-dependencies.jar')
    implementation 'com.android.support:multidex:1.0.2'
    implementation 'com.android.support:support-v4:26.1.0'
    implementation 'com.android.support:animated-vector-drawable:26.1.0'
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support:cardview-v7:26.1.0'
    implementation 'com.android.support:customtabs:26.1.0'
    implementation 'com.google.android.gms:play-services-maps:11.8.0'
    implementation 'com.google.android.gms:play-services-plus:11.8.0'
    implementation 'com.google.android.gms:play-services-auth:11.8.0'
    implementation 'com.google.android.gms:play-services-gcm:11.8.0'
    implementation 'com.google.android.gms:play-services-location:11.8.0'
    implementation ('com.crashlytics.sdk.android:crashlytics:2.8.0@aar') {
        transitive = true;
    }

}

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

我跑了gradlew -q dependencies myappname:dependencies > gradlew.txt

得到了很多我不明白的输出。我应该关注哪一节?我猜测,因为我的问题只出现在我试图构建已签名的APK以供发布时,我应该关心发布部分。我试着将它粘贴在这篇文章中,但SO认为它是不正确格式化的代码而不是文本输出,所以我必须链接到它:

https://gist.github.com/anonymous/e98adfd44e7aa9f15fe6e50539e42a29

让我们看看我是否可以将其粘贴为编辑:

releaseRuntimeClasspath - Resolved configuration for runtime for variant: release
+--- org.greenrobot:eventbus:3.1.1
+--- com.android.support:support-v4:26.1.0
|    +--- com.android.support:support-compat:26.1.0
|    |    +--- com.android.support:support-annotations:26.1.0
|    |    \--- android.arch.lifecycle:runtime:1.0.0
|    |         +--- android.arch.lifecycle:common:1.0.0
|    |         \--- android.arch.core:common:1.0.0
|    +--- com.android.support:support-media-compat:26.1.0
|    |    +--- com.android.support:support-annotations:26.1.0
|    |    \--- com.android.support:support-compat:26.1.0 (*)
|    +--- com.android.support:support-core-utils:26.1.0
|    |    +--- com.android.support:support-annotations:26.1.0
|    |    \--- com.android.support:support-compat:26.1.0 (*)
|    +--- com.android.support:support-core-ui:26.1.0
|    |    +--- com.android.support:support-annotations:26.1.0
|    |    \--- com.android.support:support-compat:26.1.0 (*)
|    \--- com.android.support:support-fragment:26.1.0
|         +--- com.android.support:support-compat:26.1.0 (*)
|         +--- com.android.support:support-core-ui:26.1.0 (*)
|         \--- com.android.support:support-core-utils:26.1.0 (*)
+--- com.android.support:animated-vector-drawable:26.1.0
|    +--- com.android.support:support-vector-drawable:26.1.0
|    |    +--- com.android.support:support-annotations:26.1.0
|    |    \--- com.android.support:support-compat:26.1.0 (*)
|    \--- com.android.support:support-core-ui:26.1.0 (*)
+--- com.android.support:appcompat-v7:26.1.0
|    +--- com.android.support:support-annotations:26.1.0
|    +--- com.android.support:support-v4:26.1.0 (*)
|    +--- com.android.support:support-vector-drawable:26.1.0 (*)
|    \--- com.android.support:animated-vector-drawable:26.1.0 (*)
+--- com.android.support:cardview-v7:26.1.0
|    \--- com.android.support:support-annotations:26.1.0
+--- com.android.support:customtabs:26.1.0
|    +--- com.android.support:support-compat:26.1.0 (*)
|    \--- com.android.support:support-annotations:26.1.0
+--- com.google.android.gms:play-services-maps:11.8.0
|    +--- com.google.android.gms:play-services-base:11.8.0
|    |    +--- com.google.android.gms:play-services-basement:11.8.0
|    |    |    +--- com.android.support:support-v4:25.2.0 -> 26.1.0 (*)
|    |    |    \--- com.google.android.gms:play-services-basement-license:11.8.0
|    |    +--- com.google.android.gms:play-services-tasks:11.8.0
|    |    |    +--- com.google.android.gms:play-services-basement:11.8.0 (*)
|    |    |    \--- com.google.android.gms:play-services-tasks-license:11.8.0
|    |    \--- com.google.android.gms:play-services-base-license:11.8.0
|    +--- com.google.android.gms:play-services-basement:11.8.0 (*)
|    \--- com.google.android.gms:play-services-maps-license:11.8.0
+--- com.google.android.gms:play-services-plus:11.8.0
|    +--- com.google.android.gms:play-services-base:11.8.0 (*)
|    +--- com.google.android.gms:play-services-basement:11.8.0 (*)
|    \--- com.google.android.gms:play-services-plus-license:11.8.0
+--- com.android.support:multidex:1.0.2
+--- com.google.android.gms:play-services-auth:11.8.0
|    +--- com.google.android.gms:play-services-auth-api-phone:11.8.0
|    |    +--- com.google.android.gms:play-services-base:11.8.0 (*)
|    |    +--- com.google.android.gms:play-services-basement:11.8.0 (*)
|    |    +--- com.google.android.gms:play-services-tasks:11.8.0 (*)
|    |    \--- com.google.android.gms:play-services-auth-api-phone-license:11.8.0
|    +--- com.google.android.gms:play-services-auth-base:11.8.0
|    |    +--- com.google.android.gms:play-services-base:11.8.0 (*)
|    |    +--- com.google.android.gms:play-services-basement:11.8.0 (*)
|    |    +--- com.google.android.gms:play-services-tasks:11.8.0 (*)
|    |    \--- com.google.android.gms:play-services-auth-base-license:11.8.0
|    +--- com.google.android.gms:play-services-base:11.8.0 (*)
|    +--- com.google.android.gms:play-services-basement:11.8.0 (*)
|    \--- com.google.android.gms:play-services-tasks:11.8.0 (*)
+--- com.google.android.gms:play-services-gcm:11.8.0
|    +--- com.google.android.gms:play-services-base:11.8.0 (*)
|    +--- com.google.android.gms:play-services-basement:11.8.0 (*)
|    +--- com.google.android.gms:play-services-iid:11.8.0
|    |    +--- com.google.android.gms:play-services-base:11.8.0 (*)
|    |    +--- com.google.android.gms:play-services-basement:11.8.0 (*)
|    |    \--- com.google.android.gms:play-services-iid-license:11.8.0
|    \--- com.google.android.gms:play-services-gcm-license:11.8.0
+--- com.google.android.gms:play-services-location:11.8.0
|    +--- com.google.android.gms:play-services-base:11.8.0 (*)
|    +--- com.google.android.gms:play-services-basement:11.8.0 (*)
|    +--- com.google.android.gms:play-services-tasks:11.8.0 (*)
|    \--- com.google.android.gms:play-services-location-license:11.8.0
+--- com.crashlytics.sdk.android:crashlytics:2.8.0
|    +--- com.crashlytics.sdk.android:crashlytics-core:2.5.0
|    |    +--- com.crashlytics.sdk.android:answers:1.4.1
|    |    |    \--- io.fabric.sdk.android:fabric:1.4.1
|    |    \--- io.fabric.sdk.android:fabric:1.4.1
|    +--- com.crashlytics.sdk.android:beta:1.2.7
|    |    \--- io.fabric.sdk.android:fabric:1.4.1
|    +--- com.crashlytics.sdk.android:answers:1.4.1 (*)
|    \--- io.fabric.sdk.android:fabric:1.4.1
\--- com.google.firebase:firebase-core:11.8.0
     \--- com.google.firebase:firebase-analytics:11.8.0
          +--- com.google.android.gms:play-services-basement:11.8.0 (*)
          +--- com.google.firebase:firebase-common:11.8.0
          |    +--- com.google.android.gms:play-services-basement:11.8.0 (*)
          |    +--- com.google.android.gms:play-services-tasks:11.8.0 (*)
          |    \--- com.google.firebase:firebase-common-license:11.8.0
          +--- com.google.firebase:firebase-analytics-impl:11.8.0
          |    +--- com.google.android.gms:play-services-basement:11.8.0 (*)
          |    +--- com.google.firebase:firebase-iid:11.8.0
          |    |    +--- com.google.android.gms:play-services-basement:11.8.0 (*)
          |    |    +--- com.google.firebase:firebase-common:11.8.0 (*)
          |    |    +--- com.google.android.gms:play-services-tasks:11.8.0 (*)
          |    |    \--- com.google.firebase:firebase-iid-license:11.8.0
          |    +--- com.google.firebase:firebase-common:11.8.0 (*)
          |    +--- com.google.android.gms:play-services-tasks:11.8.0 (*)
          |    \--- com.google.firebase:firebase-analytics-impl-license:11.8.0
          \--- com.google.firebase:firebase-analytics-license:11.8.0

因此,如果我的问题是重复的依赖关系,并且如果我应该查看"发布"部分,我不明白如何识别它们。例如,在support-v4库中查看dep树的顶部,它看起来好像它本身在支持compat库上有4或5个重复的依赖项。

但那可能不是问题,可以吗?它是谷歌最新的支持库,它似乎可以正确构建,而不是来自工厂,有4个左右的错误会阻止成千上万的开发者构建他们的APK。所以我相信我不知道我在寻找什么,我希望你能帮助我。

我尝试使用排除组来消除我使用的customtabs库的支持compat依赖性。 (抱歉,我无法发布;再次使用解析器),但是在gradle同步过程中出现了错误,所以我删除了排除组,然后我回到了方1,不知道如何接近这个问题。

非常感谢任何帮助,谢谢!

1 个答案:

答案 0 :(得分:0)

Fabric Crashlytics只应添加到模块gradle文件中,不应位于顶级gradle文件中。如果您使用Android Studio插件添加了Fabric crashlytics(建议使用它并且比手动添加它更好),您会看到它只将它添加到模块gradle文件中。 Fabric crashlytics的正确实现如下:

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

    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
    }
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

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


android {

    compileSdkVersion 27
    buildToolsVersion '27.0.2'

    defaultConfig {
        minSdkVersion 19
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

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

}

dependencies {
    //Other gradle dependencies here
    compile('com.crashlytics.sdk.android:crashlytics:2.8.0@aar') {
        transitive = true;
    }
}

希望这有帮助,快乐编码!