Android 启动项目时出现无法理解的错误(gradle)

Android 启动项目时出现无法理解的错误(gradle),android,android-gradle-plugin,Android,Android Gradle Plugin,我连接了一个库编译'com.balancedpayments:balancedpayments:1.4' 执行项目时没有错误。但当我尝试运行时,我看到了错误: Executing tasks: [:app:assembleDebug] Configuration on demand is an incubating feature. WARNING: Dependency org.apache.httpcomponents:httpclient:4.2.1 is ignored for deb

我连接了一个库
编译'com.balancedpayments:balancedpayments:1.4'
执行项目时没有错误。但当我尝试运行时,我看到了错误:

Executing tasks: [:app:assembleDebug]

Configuration on demand is an incubating feature.
WARNING: Dependency org.apache.httpcomponents:httpclient:4.2.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 org.apache.httpcomponents:httpclient:4.2.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 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 org.apache.httpcomponents:httpclient:4.2.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 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 org.apache.httpcomponents:httpclient:4.2.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
WARNING: Dependency org.apache.httpcomponents:httpclient:4.2.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
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
WARNING: Dependency org.apache.httpcomponents:httpclient:4.2.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
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
:app:compileDebugNdk UP-TO-DATE
:app:preDebugBuild
:app:checkDebugManifest
:app:preReleaseBuild
:app:prepareComAndroidSupportAppcompatV72102Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42102Library 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:compileDebugJava UP-TO-DATE
:app:preDexDebug UP-TO-DATE
:app:dexDebug
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lorg/apache/commons/codec/Decoder;
    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:302)
    at com.android.dx.command.dexer.Main.run(Main.java:245)
    at com.android.dx.command.dexer.Main.main(Main.java:214)
    at com.android.dx.command.Main.main(Main.java:106)


 FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:dexDebug'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
    D:\AndroidSDK\build-tools\21.0.2\dx.bat --dex --no-optimize --output D:\skip\Customer\app\build\intermediates\dex\debug --input-list=D:\skip\Customer\app\build\intermediates\tmp\dex\debug\inputList.txt
Error Code:
    2
Output:

    UNEXPECTED TOP-LEVEL EXCEPTION:
    com.android.dex.DexException: Multiple dex files define Lorg/apache/commons/codec/Decoder;
        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:302)
        at com.android.dx.command.dexer.Main.run(Main.java:245)
        at com.android.dx.command.dexer.Main.main(Main.java:214)
        at com.android.dx.command.Main.main(Main.java:106)
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 6.611 secs
我读了一篇文章(俄语),上面说这是因为图书馆之间的冲突

为了解决这个问题,我正在努力

configurations {
    all*.exclude module: 'httpclient'
    all*.exclude module: 'commons-logging'
}

我得到了库排除,但错误没有丢失

为了调查您的问题,我创建了一个空项目并添加了您的依赖项

compile 'com.balancedpayments:balancedpayments:1.4'
到app/gradle.build

我知道你的错误。因此,我最终构建并运行项目时没有出现错误:

在同一gradle.build中添加以下内容:

packagingOptions{
     exclude 'META-INF/LICENSE.txt'
     exclude 'META-INF/NOTICE.txt'
}
缺少此条目将导致以后出现错误

Duplicate files written in ...
您的
排除
依赖项中的
不会有帮助,所以请清除它们

最后加上

configurations {
   all*.exclude group: 'org.apache.httpcomponents'
   all*.exclude group: 'org.apache.commons'
}
Synk gradle和Run检查我是否正确


请注意,
org.apache
由于某些原因,可以将可传递依赖项添加到基本依赖项中,例如与Android stock org.apache组件不兼容。因此,由您检查
com.balancedpayments
是否有效

“请注意,由于某些原因,org.apache可传递依赖项可以添加到基本依赖项中,例如与Android stock org.apache组件不兼容”,这是什么意思。org.apache.*代码可以作为依赖项添加应该有一些重要的原因,因为HTTPCOMPONENTS已经存在于Android系统中,所以乍一看不需要依赖项。其中一个原因是Android操作系统中的org.apache.*代码可能有点旧,因此与库中要求新版本apache http libs.Tor_Gash的新功能不兼容。如果依赖项使用最新版本的HTTPCOMPONENTS,并且您需要新版本,您会怎么办,与Android提供的旧版本不同?请询问主题库的开发人员他们为什么这样做,我甚至一行代码都没读过。但我只是猜测,如果一个简单的“导入”足够好,就不需要依赖关系了