android studio无法使用外部库启动应用程序

时间:2016-01-10 09:06:36

标签: android android-studio gradle apache-commons chilkat

我想在我的android应用程序中使用ftp工具,所以我尝试添加apache-commons-net:3.4库。
构建成功完成但在我想运行或调试应用程序时失败 所以我尝试使用ivy-2-4-0库和Chilkat库,对于所有这些我都得到了同样的错误 除了与它有点不同的Chilkat之外,我只在我的libs目录中复制了库,并在我的项目结构的file选项卡中声明了dependencies依赖项。

显示的错误是:

Executing tasks: [:app:assembleDebug]

Configuration on demand is an incubating feature.
:MapsForgeForOsmdroid:compileLint
:MapsForgeForOsmdroid:copyReleaseLint UP-TO-DATE
:MapsForgeForOsmdroid:preBuild UP-TO-DATE
:MapsForgeForOsmdroid:preReleaseBuild UP-TO-DATE
:MapsForgeForOsmdroid:checkReleaseManifest
:MapsForgeForOsmdroid:preDebugAndroidTestBuild UP-TO-DATE
:MapsForgeForOsmdroid:preDebugBuild UP-TO-DATE
:MapsForgeForOsmdroid:preDebugUnitTestBuild UP-TO-DATE
:MapsForgeForOsmdroid:preReleaseUnitTestBuild UP-TO-DATE
:MapsForgeForOsmdroid:prepareComAndroidSupportAppcompatV72311Library UP-TO-DATE
:MapsForgeForOsmdroid:prepareComAndroidSupportSupportV42311Library UP-TO-DATE
:MapsForgeForOsmdroid:prepareOrgOsmdroidOsmdroidAndroid501Library UP-TO-DATE
:MapsForgeForOsmdroid:prepareReleaseDependencies
:MapsForgeForOsmdroid:compileReleaseAidl UP-TO-DATE
:MapsForgeForOsmdroid:compileReleaseRenderscript UP-TO-DATE
:MapsForgeForOsmdroid:generateReleaseBuildConfig UP-TO-DATE
:MapsForgeForOsmdroid:generateReleaseAssets UP-TO-DATE
:MapsForgeForOsmdroid:mergeReleaseAssets UP-TO-DATE
:MapsForgeForOsmdroid:generateReleaseResValues UP-TO-DATE
:MapsForgeForOsmdroid:generateReleaseResources UP-TO-DATE
:MapsForgeForOsmdroid:mergeReleaseResources UP-TO-DATE
:MapsForgeForOsmdroid:processReleaseManifest UP-TO-DATE
:MapsForgeForOsmdroid:processReleaseResources UP-TO-DATE
:MapsForgeForOsmdroid:generateReleaseSources UP-TO-DATE
:MapsForgeForOsmdroid:processReleaseJavaRes UP-TO-DATE
:MapsForgeForOsmdroid:compileReleaseJavaWithJavac UP-TO-DATE
:MapsForgeForOsmdroid:extractReleaseAnnotations UP-TO-DATE
:MapsForgeForOsmdroid:mergeReleaseProguardFiles UP-TO-DATE
:MapsForgeForOsmdroid:packageReleaseJar UP-TO-DATE
:MapsForgeForOsmdroid:compileReleaseNdk UP-TO-DATE
:MapsForgeForOsmdroid:packageReleaseJniLibs UP-TO-DATE
:MapsForgeForOsmdroid:packageReleaseLocalJar UP-TO-DATE
:MapsForgeForOsmdroid:packageReleaseRenderscript UP-TO-DATE
:MapsForgeForOsmdroid:packageReleaseResources UP-TO-DATE
:MapsForgeForOsmdroid:bundleRelease UP-TO-DATE
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:googleplayservices_lib:compileJava UP-TO-DATE
:googleplayservices_lib:processResources UP-TO-DATE
:googleplayservices_lib:classes UP-TO-DATE
:googleplayservices_lib:jar UP-TO-DATE
:app:prepare2ndGuideMapsForgeForOsmdroidUnspecifiedLibrary UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72311Library UP-TO-DATE
:app:prepareComAndroidSupportMediarouterV72300Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42311Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServices840Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesAds840Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesAnalytics840Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesAppindexing840Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesAppinvite840Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesAppstate840Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesAuth840Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesBase840Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesBasement840Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesCast840Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesDrive840Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesFitness840Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesGames840Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesGcm840Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesIdentity840Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesLocation840Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesMaps840Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesMeasurement840Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesNearby840Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesPanorama840Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesPlus840Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesSafetynet840Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesVision840Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesWallet840Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesWearable840Library UP-TO-DATE
:app:prepareOrgOsmdroidOsmdroidAndroid501Library UP-TO-DATE
:app:prepareOsmbonuspack_v55Library 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:compileDebugJavaWithJavac UP-TO-DATE
:app:compileDebugNdk UP-TO-DATE
:app:compileDebugSources UP-TO-DATE
:app:preDexDebug UP-TO-DATE
:app:dexDebug
AGPBI: {"kind":"simple","text":"UNEXPECTED TOP-LEVEL EXCEPTION:","sources":[{}]}
AGPBI: {"kind":"simple","text":"com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536","sources":[{}]}
AGPBI: {"kind":"simple","text":"\tat com.android.dx.merge.DexMerger$6.updateIndex(DexMerger.java:502)","sources":[{}]}
AGPBI: {"kind":"simple","text":"\tat com.android.dx.merge.DexMerger$IdMerger.mergeSorted(DexMerger.java:283)","sources":[{}]}
AGPBI: {"kind":"simple","text":"\tat com.android.dx.merge.DexMerger.mergeMethodIds(DexMerger.java:491)","sources":[{}]}
AGPBI: {"kind":"simple","text":"\tat com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:168)","sources":[{}]}
AGPBI: {"kind":"simple","text":"\tat com.android.dx.merge.DexMerger.merge(DexMerger.java:189)","sources":[{}]}
AGPBI: {"kind":"simple","text":"\tat com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:502)","sources":[{}]}
AGPBI: {"kind":"simple","text":"\tat com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)","sources":[{}]}
AGPBI: {"kind":"simple","text":"\tat com.android.dx.command.dexer.Main.run(Main.java:277)","sources":[{}]}
AGPBI: {"kind":"simple","text":"\tat com.android.dx.command.dexer.Main.main(Main.java:245)","sources":[{}]}
AGPBI: {"kind":"simple","text":"\tat com.android.dx.command.Main.main(Main.java:106)","sources":[{}]}


 FAILED

FAILURE: Build failed with an exception.

* What went wrong:
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_71\bin\java.exe'' finished with non-zero exit value 2

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

我的项目出了什么问题?

的问候, 阿兰

1 个答案:

答案 0 :(得分:1)

  

com.android.dex.DexIndexOverflowException:方法ID不在[0,0xffff]中:65536","来源":[{}]}

你有太多的方法。 dex 只能有 65536种方法。

您可以使用multidex support

只需在build.gradle

中添加这些行
android {

    defaultConfig {
        ...

        // Enabling multidex support.
        multiDexEnabled true
    }
    ...
}

dependencies {
  compile 'com.android.support:multidex:1.0.0'
}

同样在您的Manifest中,将多索引支持库中的MultiDexApplication类添加到应用程序元素

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.android.multidex.myapplication">
    <application
        ...
        android:name="android.support.multidex.MultiDexApplication">
        ...
    </application>
</manifest>

如果您使用的是自己的Application课程,请将父课程从Application更改为MultiDexApplication