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

标签 android android-gradle-plugin

我连接了一个库compile 'com.balanced payments:balanced payments: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

我读了一篇文章(俄语),说是因为库冲突 enter link description here

解决我正在尝试的问题

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 ...

您的exludedependencies没有帮助,所以清理它们。

最后添加

configurations {
   all*.exclude group: 'org.apache.httpcomponents'
   all*.exclude group: 'org.apache.commons'
}

Synk gradle 并点击“运行”来检查我是否正确。

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

关于android - 启动项目时出现无法理解的错误(gradle),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28021936/

相关文章:

android - 寻找适用于 Android 的 ANPR/LPR(自动车牌识别/车牌识别)SDK

android - 在保留异步任务 fragment 的屏幕旋转后, fragment 的目标不在 fragment 管理器中

java - reprojectImageTo3D - 我从哪里得到 Q

android - 尝试构建应用> 65K(65536)方法时,Android构建项目错误

android - 如何使用Android Studio在Android L或4.4上运行应用程序?

android - onclick Canvas android

android - 从最近的应用程序列表/任务管理器中排除广播接收器

android - 无法解析 ':app@releaseUnitTest/compileClasspath' : Could not resolve com. android.support :appcompat-v7:27. 1.1 的依赖项

android - 为版本 : Proguard config 生成签名的 apk 时出错

android - Phimp.me 项目的外部 native 构建问题