代码之家  ›  专栏  ›  技术社区  ›  0xC0DED00D

多个dex文件定义了Lcom/amazonaws/AmazonWebServiceClient;

  •  2
  • 0xC0DED00D  · 技术社区  · 9 年前

    我正在尝试在我的Android应用程序中使用Amazon AWS SDK。该应用程序已使用C2Call SDK。该应用程序正在运行,但我一添加AWS gradle库,它就开始给我提供Multiple Dex文件异常。我搜索了它,发现它与多次定义的单个库相关,但从日志中我不确定是哪个库。我尝试删除不同的gradle编译选项,每当我添加AWS库时,它都会出现Multiple Dex异常。

    这是我的应用程序等级文件-

    apply plugin: 'com.android.application'
    
    android {
        compileSdkVersion 22
        buildToolsVersion "21.1.2"
    
        defaultConfig {
            applicationId "com.test.test"
            minSdkVersion 14
            targetSdkVersion 22
            versionCode 1
            versionName "1.0"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    }
    repositories {
        flatDir {
            dirs 'libs'
        }
    }
    
    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        /*compile 'com.android.support:appcompat-v7:22.2.0'*/
        compile(name: 'lib-c2callsdk', ext: 'aar')
        compile 'com.amazonaws:aws-android-sdk-cognito:2.2.3'
        compile 'com.amazonaws:aws-android-sdk-ses:2.2.3'
        compile 'com.amazonaws:aws-android-sdk-ddb:2.2.3'
    }
    

    我也尝试了添加和删除appcompact。

    这是我得到的错误日志-

    Information:Gradle tasks [:app:assembleDebug]
    Warning:Dependency commons-logging:commons-logging:1.1.1 is ignored for debug as it may be conflicting with the internal version provided by Android.
             In case of problem, please repackage it with jarjar to change the class packages
    Warning:Dependency commons-logging:commons-logging:1.1.1 is ignored for release as it may be conflicting with the internal version provided by Android.
             In case of problem, please repackage it with jarjar to change the class packages
    :app:preBuild UP-TO-DATE
    :app:preDebugBuild UP-TO-DATE
    :app:checkDebugManifest
    :app:preReleaseBuild UP-TO-DATE
    :app:prepareLibC2callsdkLibrary UP-TO-DATE
    :app:prepareDebugDependencies
    :app:compileDebugAidl UP-TO-DATE
    :app:compileDebugRenderscript UP-TO-DATE
    :app:generateDebugBuildConfig UP-TO-DATE
    :app:generateDebugAssets UP-TO-DATE
    :app:mergeDebugAssets UP-TO-DATE
    :app:generateDebugResValues UP-TO-DATE
    :app:generateDebugResources UP-TO-DATE
    :app:mergeDebugResources UP-TO-DATE
    :app:processDebugManifest UP-TO-DATE
    :app:processDebugResources UP-TO-DATE
    :app:generateDebugSources UP-TO-DATE
    :app:processDebugJavaRes UP-TO-DATE
    :app:compileDebugJava
    :app:compileDebugNdk UP-TO-DATE
    :app:compileDebugSources
    :app:preDexDebug
    warning: Ignoring InnerClasses attribute for an anonymous inner class
    (org.apache.commons.logging.LogFactory$1) that doesn't come with an
    associated EnclosingMethod attribute. This class was probably produced by a
    compiler that did not target the modern .class file format. The recommended
    solution is to recompile the class from source, using an up-to-date compiler
    and without specifying any "-target" type options. The consequence of ignoring
    this warning is that reflective operations on this class will incorrectly
    indicate that it is *not* an inner class.
    warning: Ignoring InnerClasses attribute for an anonymous inner class
    (org.apache.commons.logging.LogFactory$2) that doesn't come with an
    associated EnclosingMethod attribute. This class was probably produced by a
    compiler that did not target the modern .class file format. The recommended
    solution is to recompile the class from source, using an up-to-date compiler
    and without specifying any "-target" type options. The consequence of ignoring
    this warning is that reflective operations on this class will incorrectly
    indicate that it is *not* an inner class.
    warning: Ignoring InnerClasses attribute for an anonymous inner class
    (org.apache.commons.logging.LogFactory$3) that doesn't come with an
    associated EnclosingMethod attribute. This class was probably produced by a
    compiler that did not target the modern .class file format. The recommended
    solution is to recompile the class from source, using an up-to-date compiler
    and without specifying any "-target" type options. The consequence of ignoring
    this warning is that reflective operations on this class will incorrectly
    indicate that it is *not* an inner class.
    warning: Ignoring InnerClasses attribute for an anonymous inner class
    (org.apache.commons.logging.LogFactory$4) that doesn't come with an
    associated EnclosingMethod attribute. This class was probably produced by a
    compiler that did not target the modern .class file format. The recommended
    solution is to recompile the class from source, using an up-to-date compiler
    and without specifying any "-target" type options. The consequence of ignoring
    this warning is that reflective operations on this class will incorrectly
    indicate that it is *not* an inner class.
    warning: Ignoring InnerClasses attribute for an anonymous inner class
    (org.apache.commons.logging.LogFactory$5) that doesn't come with an
    associated EnclosingMethod attribute. This class was probably produced by a
    compiler that did not target the modern .class file format. The recommended
    solution is to recompile the class from source, using an up-to-date compiler
    and without specifying any "-target" type options. The consequence of ignoring
    this warning is that reflective operations on this class will incorrectly
    indicate that it is *not* an inner class.
    warning: Ignoring InnerClasses attribute for an anonymous inner class
    (org.apache.commons.logging.LogFactory$6) that doesn't come with an
    associated EnclosingMethod attribute. This class was probably produced by a
    compiler that did not target the modern .class file format. The recommended
    solution is to recompile the class from source, using an up-to-date compiler
    and without specifying any "-target" type options. The consequence of ignoring
    this warning is that reflective operations on this class will incorrectly
    indicate that it is *not* an inner class.
    warning: Ignoring InnerClasses attribute for an anonymous inner class
    (org.apache.commons.logging.impl.LogFactoryImpl$1) that doesn't come with an
    associated EnclosingMethod attribute. This class was probably produced by a
    compiler that did not target the modern .class file format. The recommended
    solution is to recompile the class from source, using an up-to-date compiler
    and without specifying any "-target" type options. The consequence of ignoring
    this warning is that reflective operations on this class will incorrectly
    indicate that it is *not* an inner class.
    warning: Ignoring InnerClasses attribute for an anonymous inner class
    (org.apache.commons.logging.impl.LogFactoryImpl$2) that doesn't come with an
    associated EnclosingMethod attribute. This class was probably produced by a
    compiler that did not target the modern .class file format. The recommended
    solution is to recompile the class from source, using an up-to-date compiler
    and without specifying any "-target" type options. The consequence of ignoring
    this warning is that reflective operations on this class will incorrectly
    indicate that it is *not* an inner class.
    warning: Ignoring InnerClasses attribute for an anonymous inner class
    (org.apache.commons.logging.impl.LogFactoryImpl$3) that doesn't come with an
    associated EnclosingMethod attribute. This class was probably produced by a
    compiler that did not target the modern .class file format. The recommended
    solution is to recompile the class from source, using an up-to-date compiler
    and without specifying any "-target" type options. The consequence of ignoring
    this warning is that reflective operations on this class will incorrectly
    indicate that it is *not* an inner class.
    warning: Ignoring InnerClasses attribute for an anonymous inner class
    (org.apache.commons.logging.impl.SimpleLog$1) that doesn't come with an
    associated EnclosingMethod attribute. This class was probably produced by a
    compiler that did not target the modern .class file format. The recommended
    solution is to recompile the class from source, using an up-to-date compiler
    and without specifying any "-target" type options. The consequence of ignoring
    this warning is that reflective operations on this class will incorrectly
    indicate that it is *not* an inner class.
    warning: Ignoring InnerClasses attribute for an anonymous inner class
    (org.apache.commons.logging.impl.WeakHashtable$1) that doesn't come with an
    associated EnclosingMethod attribute. This class was probably produced by a
    compiler that did not target the modern .class file format. The recommended
    solution is to recompile the class from source, using an up-to-date compiler
    and without specifying any "-target" type options. The consequence of ignoring
    this warning is that reflective operations on this class will incorrectly
    indicate that it is *not* an inner class.
    warning: Ignoring InnerClasses attribute for an anonymous inner class
    (com.amazonaws.services.s3.model.a.d) that doesn't come with an
    associated EnclosingMethod attribute. This class was probably produced by a
    compiler that did not target the modern .class file format. The recommended
    solution is to recompile the class from source, using an up-to-date compiler
    and without specifying any "-target" type options. The consequence of ignoring
    this warning is that reflective operations on this class will incorrectly
    indicate that it is *not* an inner class.
    :app:dexDebug
    UNEXPECTED TOP-LEVEL EXCEPTION:
    com.android.dex.DexException: Multiple dex files define Lcom/amazonaws/AmazonWebServiceClient;
        at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
        at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
        at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
        at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
        at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
        at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
        at com.android.dx.command.dexer.Main.runMonoDex(Main.java:303)
        at com.android.dx.command.dexer.Main.run(Main.java:246)
        at com.android.dx.command.dexer.Main.main(Main.java:215)
        at com.android.dx.command.Main.main(Main.java:106)
    Error:Execution failed for task ':app:dexDebug'.
    > com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.7.0_75\bin\java.exe'' finished with non-zero exit value 2
    Information:BUILD FAILED
    Information:Total time: 25.398 secs
    Information:1 error
    Information:2 warnings
    Information:See complete output in console
    

    如果我只选择了一个AWS库,比如cognito,它会给出相同的异常,而不会发出长警告。

    知道我在这里做错了什么吗?我怎样才能找到确切的问题?

    更新:

    我已尝试将以下内容放入应用程序的等级中-

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        /*compile 'com.android.support:appcompat-v7:22.2.0'*/
        compile(name: 'lib-c2callsdk', ext: 'aar'){
            exclude group:'gson'
            exclude group:'commons-logging'
        }
        compile ('com.amazonaws:aws-android-sdk-core:2.+'){
            exclude group:'gson'
            exclude group:'commons-logging'
        }
        /*compile 'com.amazonaws:aws-android-sdk-cognito:2.+'
        compile 'com.amazonaws:aws-android-sdk-ses:2.+'
        compile 'com.amazonaws:aws-android-sdk-ddb:2.+'*/
        /*compile 'com.google.code.gson:gson:2.3'*/
    }
    

    现在错误减少到这个-

    Information:Gradle tasks [:app:assembleDebug]
    :app:preBuild UP-TO-DATE
    :app:preDebugBuild UP-TO-DATE
    :app:checkDebugManifest
    :app:preReleaseBuild UP-TO-DATE
    :app:prepareLibC2callsdkLibrary UP-TO-DATE
    :app:prepareDebugDependencies
    :app:compileDebugAidl UP-TO-DATE
    :app:compileDebugRenderscript UP-TO-DATE
    :app:generateDebugBuildConfig UP-TO-DATE
    :app:generateDebugAssets UP-TO-DATE
    :app:mergeDebugAssets UP-TO-DATE
    :app:generateDebugResValues UP-TO-DATE
    :app:generateDebugResources UP-TO-DATE
    :app:mergeDebugResources UP-TO-DATE
    :app:processDebugManifest UP-TO-DATE
    :app:processDebugResources UP-TO-DATE
    :app:generateDebugSources UP-TO-DATE
    :app:processDebugJavaRes UP-TO-DATE
    :app:compileDebugJava UP-TO-DATE
    :app:compileDebugNdk UP-TO-DATE
    :app:compileDebugSources UP-TO-DATE
    :app:preDexDebug UP-TO-DATE
    :app:dexDebug
    UNEXPECTED TOP-LEVEL EXCEPTION:
    com.android.dex.DexException: Multiple dex files define Lcom/amazonaws/AmazonWebServiceClient;
        at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
        at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
        at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
        at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
        at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
        at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
        at com.android.dx.command.dexer.Main.runMonoDex(Main.java:303)
        at com.android.dx.command.dexer.Main.run(Main.java:246)
        at com.android.dx.command.dexer.Main.main(Main.java:215)
        at com.android.dx.command.Main.main(Main.java:106)
    Error:Execution failed for task ':app:dexDebug'.
    > com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.7.0_75\bin\java.exe'' finished with non-zero exit value 2
    Information:BUILD FAILED
    Information:Total time: 2.804 secs
    Information:1 error
    Information:0 warnings
    Information:See complete output in console
    
    3 回复  |  直到 9 年前
        1
  •  4
  •   Yangfan    9 年前

    错误显示 com.amazonaws.AmazonWebServiceClient 被多次定义。很可能您的项目中引用了几个AWS Android SDK副本,其中一个显然来自Maven。请您仔细检查一下libs文件夹下没有另一个吗?我不熟悉c2call。不确定其中是否存在与AWS SDK冲突的内容。一种检查方法是解压缩jar并搜索特定的类。下面是一个示例:

    unzip -l *.jar | grep AmazonWebServiceClient
    

    至于警告,请随意忽略。AWS Android SDK依赖于使用JDK 1.5编译的apache commons logging 1.1.1。Android不喜欢它,但可以使用它。

        2
  •  1
  •   0xC0DED00D    9 年前

    以下是我为解决这一问题所做的努力(以帮助那些未来可能需要采取措施的人)-

    1. 将AAR文件扩展名更改为zip并解压缩。
    2. 打开Extracted文件夹以查找classes.jar
    3. 下载 JarJar.jar
    4. 创建一个规则文件,您可以在其中提到需要重构的包或类。这是我的规则文件-

      rule com.amazonaws.services.s3.a.* com.jarjar.@0
      rule com.amazonaws.services.s3.model.a.* com.jarjar.@0
      rule com.amazonaws.services.s3.model.* com.jarjar.@0
      rule com.amazonaws.services.s3.* com.jarjar.@0
      rule com.amazonaws.sdk.* com.jarjar.@0
      rule com.amazonaws.regions.* com.jarjar.@0
      rule com.amazonaws.javax.xml.stream.xerces.impl.msg.* com.jarjar.@0
      rule com.amazonaws.http.* com.jarjar.@0
      rule com.amazonaws.e.* com.jarjar.@0
      rule com.amazonaws.d.* com.jarjar.@0
      rule com.amazonaws.c.* com.jarjar.@0
      rule com.amazonaws.b.* com.jarjar.@0
      rule com.amazonaws.a.* com.jarjar.@0
      rule com.amazonaws.auth.* com.jarjar.@0
      rule com.amazonaws.* com.jarjar.@0
      rule com.amazon.device.messaging.development.* com.jarjar.@0
      rule com.amazon.device.messaging.* com.jarjar.@0
      rule com.amazon.* com.jarjar.@0
      rule com.google.gson.stream.* com.jarjar.@0
      rule com.google.gson.reflect.* com.jarjar.@0
      rule com.google.gson.internal.bind.* com.jarjar.@0
      rule com.google.gson.internal.* com.jarjar.@0
      rule com.google.gson.annotations.* com.jarjar.@0
      rule com.google.gson.* com.jarjar.@0
      
    5. 运行jarjar.jar。下面是一个示例命令-

      java -jar "D:\Android\Dev Tools\jarjar-1.4.jar" process jarjarrules.txt lib-c2callsdk\classes.jar classes.jar
      
    6. 复制生成的类。jar并将副本转换为zip。提取它以验证重构。

    7. 现在复制生成的类。jar并替换旧类。jar,并将其保存在解压缩的库文件夹中。
    8. 将文件夹压缩到zip(记住在根目录上有classes.jar)。
    9. 将zip重命名为aar扩展名。
    10. 在项目中使用新的aar库。

    PS:当然,感谢扬帆提出了解决方案。

        3
  •  0
  •   Suresh Maidaragi    7 年前

    我正在使用AWS重新识别库进行图像识别

    我在使用

    implementation 'com.amazonaws:aws-java-sdk-rekognition:1.11.66
    implementation 'com.amazonaws:aws-android-sdk-core:2.4.4
    

    在android studio中,我通过替换依赖项来解决 implementation 'com.amazonaws:aws-android-sdk-core:2.4.4 通过 jar file .

    dependencies {
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    
    implementation 'com.amazonaws:aws-android-sdk-core:2.2.+'
    implementation files('yourJarFileLocation/AmazonRekognition/lib/aws-android-sdk-rekognition-2.6.9.jar')
    

    }

    接下来就是清理、重建、运行。它奏效了