android Studio 无法使用外部库启动应用程序
android studio fails to launch app with external libs
我想在我的 android 应用程序中使用 ftp 设施,所以我尝试添加 apache-commons-net:3.4 库。
构建已成功完成,但当我想 运行 或调试应用程序时它失败了。
所以我尝试使用 ivy-2-4-0 库和 Chilkat 库,对于它们我都得到了同样的错误。
除了 Chilkat 有点不同,我只复制了我的 libs
目录中的库,并在我的项目结构的 dependencies
选项卡中声明了 file
依赖项。
显示的错误是:
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.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
我的项目有什么问题?
此致,
阿兰
com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536","sources":[{}]}
你的方法太多了。 dex.
只能有65536个方法
可以使用multidex support。
只需在 build.gradle
中添加这些行:
android {
defaultConfig {
...
// Enabling multidex support.
multiDexEnabled true
}
...
}
dependencies {
compile 'com.android.support:multidex:1.0.0'
}
同样在您的 Manifest
中将 multidex 支持库中的 MultiDexApplication
class 添加到应用程序元素
<?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
class,请将父 class 从 Application
更改为 MultiDexApplication
。
我想在我的 android 应用程序中使用 ftp 设施,所以我尝试添加 apache-commons-net:3.4 库。
构建已成功完成,但当我想 运行 或调试应用程序时它失败了。
所以我尝试使用 ivy-2-4-0 库和 Chilkat 库,对于它们我都得到了同样的错误。
除了 Chilkat 有点不同,我只复制了我的 libs
目录中的库,并在我的项目结构的 dependencies
选项卡中声明了 file
依赖项。
显示的错误是:
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.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
我的项目有什么问题?
此致, 阿兰
com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536","sources":[{}]}
你的方法太多了。 dex.
只能有65536个方法可以使用multidex support。
只需在 build.gradle
中添加这些行:
android {
defaultConfig {
...
// Enabling multidex support.
multiDexEnabled true
}
...
}
dependencies {
compile 'com.android.support:multidex:1.0.0'
}
同样在您的 Manifest
中将 multidex 支持库中的 MultiDexApplication
class 添加到应用程序元素
<?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
class,请将父 class 从 Application
更改为 MultiDexApplication
。