本文介绍了Android的工作室摇篮错误"多DEX文件定义..."的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目是工作的罚款,当我加入Facebook的SDK到我的项目我有这样的错误,我已经试了很多方法来解决这个问题,但我没有。我应该怎么办?

 错误:执行失败的任务:应用程序:packageAllDebugClassesForMultiDex。
> java.util.zip.ZipException:重复的条目:螺栓/ AggregateException.class

我的gradle应用低于

 应用插件:'com.android.application安卓{
    compileSdkVersion 21
    buildToolsVersion '21 .1.2    defaultConfig {
        的applicationIDcom.example.myproject
        9的minSdkVersion
        targetSdkVersion 21
        版本code 1
        的versionName1.0
        multiDexEnabled =真
    }
    buildTypes {
        发布 {
            minifyEnabled假
            proguardFiles getDefaultProguardFile('proguard的-android.txt'),'proguard-rules.pro
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
}依赖{
    编译文件树(导演:'库',包括:['的* .jar'])
    编译com.android.support:appcompat-v7:21.0.3    编制项目(:Facebook的)
}

这里是Facebook的的build.gradle

 应用插件:'com.android.library库{
  mavenCentral()
}project.group ='com.facebook.android依赖{
    编译com.android.support:support-v4:[21,22)
    编译com.parse.bolts:螺栓,安卓1.1.4
}安卓{
    compileSdkVersion 21
    buildToolsVersion '21 .1.2    defaultConfig {
        9的minSdkVersion
        targetSdkVersion 21
    }    lintOptions {
        abortOnError假
    }    sourceSets {
        主要{
            manifest.srcFile'的Andr​​oidManifest.xml
            java.srcDirs = ['src'中]
            res.srcDirs = ['水库']
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
}应用插件:'行家'
应用插件:'签约'高清isSnapshot = version.endsWith(' - 快照)
高清ossrhUsername = hasProperty('NEXUS_USERNAME')? NEXUS_USERNAME:
高清ossrhPassword = hasProperty('NEXUS_PASSWORD')? NEXUS_PASSWORD:任务setVersion {
    //版本将从来源衍生
    project.version = NULL
    高清sdkVersionFile =文件(SRC / COM / Facebook的/ FacebookSdkVersion.java')
    sdkVersionFile.eachLine {
        高清匹配器=(它=〜/(?:.*BUILD = \\)(*)(?:\\。*)/)
        如果(matcher.matches()){
          project.version =匹配[0] [1]
          返回
        }
    }
    如果(project.version.is(未指定)){
      抛出新GradleScriptException(版本找不到。',NULL)
    }
}uploadArchives {
    repositories.mavenDeployer {
        beforeDeployment {MavenDeployment部署 - > signing.signPom(部署)}        库(URL:https://oss.sonatype.org/service/local/staging/deploy/maven2/){
            认证(用户名:ossrhUsername,密码:ossrhPassword)
        }        snapshotRepository(URL:https://oss.sonatype.org/content/repositories/snapshots/){
            认证(用户名:ossrhUsername,密码:ossrhPassword)
        }        pom.project {
            名称的Facebook,Android的SDK
            的artifactId ='Facebook的Andr​​oid的SDK
            包装AAR
            描述的Facebook Android SDK中'
            URL'https://github.com/facebook/facebook-android-sdk            SCM {
                连接SCM:[email protected]:Facebook的/ Facebook的Andr​​oid的sdk.git
                developerConnection'SCM:[email protected]:Facebook的/ Facebook的Andr​​oid的sdk.git
                URL'https://github.com/facebook/facebook-android-sdk
            }            许可证{
                执照 {
                    名称Apache软件许可证,版本2.0
                    URL'https://github.com/facebook/facebook-android-sdk/blob/master/LICENSE.txt
                    分配'回购'
                }
            }            开发商{
                开发商{
                    ID的Facebook
                    命名的Facebook
                }
            }
        }
    }
}uploadArchives.dependsOn(setVersion)签约{
    需要{isSnapshot和放大器;!&安培; gradle.taskGraph.hasTask(uploadArchives)}
    签署configurations.archives
}任务androidJavadocs(型号:的Javadoc){
    来源= android.sourceSets.main.java.srcDirs
    类路径+ = project.files(android.getBootClasspath()。加入(File.pathSeparator))
}任务androidJavadocsJar(类型:罐,dependsOn:androidJavadocs){
    分类='的javadoc'
    从androidJavadocs.destinationDir
}任务androidSourcesJar(类型:罐){
    分类='源'
    从android.sourceSets.main.java.sourceFiles
}文物{
    档案androidSourcesJar
    档案androidJavadocsJar
}afterEvaluate {
    androidJavadocs.classpath + = project.android.libraryVariants.toList()。第一个()。javaCompile.classpath
}


解决方案

对于我来说,我在Facebook上添加SDK作为一个项目,并将其设置为依赖关系。

然而,当我切换到使用Maven源排除工作。

我觉得这不仅是对Maven,而不是项目依赖? (请提供正确的信息,如果有人知道这件事)

在换句话说,你现在可以删除Facebook的SDK的项目和文件。

记得添加

  {库
    mavenCentral()
}

如果你不使用Maven。

所以看起来的build.gradle这样,我注释掉这个项目的方式。

  {库
    mavenCentral()
}
依赖{
    编译文件树(导演:'库',包括:的* .jar)
    编制项目(:谷歌播放services_lib')
    编译('com.facebook.android:facebook-android-sdk:3.23.0'){
        排除模块:螺栓,Android的
        排除模块:支持-V4
    }
//编译(项目(':FacebookSDK')){
//排除模块:螺栓,Android的
//排除模块:支持-V4
//}
    编译(项目(':UserVoiceSDK')){排除模块:支持-V4'}
}

My Project was working fine, when I have added facebook sdk into my project I have an error like this, I have tried so many ways to fix this, but I didn't. What should I do?

  Error:Execution failed for task ':app:packageAllDebugClassesForMultiDex'.
> java.util.zip.ZipException: duplicate entry: bolts/AggregateException.class

My App gradle is below

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion '21.1.2'

    defaultConfig {
        applicationId "com.example.myproject"
        minSdkVersion 9
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
        multiDexEnabled = true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.3'

    compile project(':facebook')
}

And here is the facebook build.gradle

apply plugin: 'com.android.library'

repositories {
  mavenCentral()
}

project.group = 'com.facebook.android'

dependencies {
    compile 'com.android.support:support-v4:[21,22)'
    compile 'com.parse.bolts:bolts-android:1.1.4'
}

android {
    compileSdkVersion 21
    buildToolsVersion '21.1.2'

    defaultConfig {
        minSdkVersion 9
        targetSdkVersion 21
    }

    lintOptions {
        abortOnError false
    }

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            res.srcDirs = ['res']
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
}

apply plugin: 'maven'
apply plugin: 'signing'

def isSnapshot = version.endsWith('-SNAPSHOT')
def ossrhUsername = hasProperty('NEXUS_USERNAME') ? NEXUS_USERNAME : ""
def ossrhPassword = hasProperty('NEXUS_PASSWORD') ? NEXUS_PASSWORD : ""

task setVersion {
    // The version will be derived from source
    project.version = null
    def sdkVersionFile = file('src/com/facebook/FacebookSdkVersion.java')
    sdkVersionFile.eachLine{
        def matcher = (it =~ /(?:.*BUILD = \")(.*)(?:\".*)/)
        if (matcher.matches()) {
          project.version = matcher[0][1]
          return
        }
    }
    if (project.version.is('unspecified')) {
      throw new GradleScriptException('Version could not be found.', null)
    }
}

uploadArchives {
    repositories.mavenDeployer {
        beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }

        repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
            authentication(userName: ossrhUsername, password: ossrhPassword)
        }

        snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
            authentication(userName: ossrhUsername, password: ossrhPassword)
        }

        pom.project {
            name 'Facebook-Android-SDK'
            artifactId = 'facebook-android-sdk'
            packaging 'aar'
            description 'Facebook Android SDK'
            url 'https://github.com/facebook/facebook-android-sdk'

            scm {
                connection 'scm:[email protected]:facebook/facebook-android-sdk.git'
                developerConnection 'scm:[email protected]:facebook/facebook-android-sdk.git'
                url 'https://github.com/facebook/facebook-android-sdk'
            }

            licenses {
                license {
                    name 'The Apache Software License, Version 2.0'
                    url 'https://github.com/facebook/facebook-android-sdk/blob/master/LICENSE.txt'
                    distribution 'repo'
                }
            }

            developers {
                developer {
                    id 'facebook'
                    name 'Facebook'
                }
            }
        }
    }
}

uploadArchives.dependsOn(setVersion)

signing {
    required { !isSnapshot && gradle.taskGraph.hasTask("uploadArchives") }
    sign configurations.archives
}

task androidJavadocs(type: Javadoc) {
    source = android.sourceSets.main.java.srcDirs
    classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
}

task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
    classifier = 'javadoc'
    from androidJavadocs.destinationDir
}

task androidSourcesJar(type: Jar) {
    classifier = 'sources'
    from android.sourceSets.main.java.sourceFiles
}

artifacts {
    archives androidSourcesJar
    archives androidJavadocsJar
}

afterEvaluate {
    androidJavadocs.classpath += project.android.libraryVariants.toList().first().javaCompile.classpath
}
解决方案

For me, I was adding Facebook SDK as a project, and set it as dependencies.

However, the exclude work after i switching to use the maven source.

I think it is for maven only, not for project dependencies? (please provide correct info if someone know about this)

In other word, you can now delete the Facebook SDK project and files.

remember to add

repositories {
    mavenCentral()
}

if you weren't using maven.

So the build.gradle look like this, I commented out the project way.

repositories {
    mavenCentral()
}
dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile project(':google-play-services_lib')
    compile ('com.facebook.android:facebook-android-sdk:3.23.0'){
        exclude module: 'bolts-android'
        exclude module: 'support-v4'
    }
//    compile (project(':FacebookSDK')){
//        exclude module: 'bolts-android'
//        exclude module: 'support-v4'
//    }
    compile (project(':UserVoiceSDK')){ exclude module: 'support-v4' }
}

这篇关于Android的工作室摇篮错误"多DEX文件定义..."的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 01:07