导入Xerces库时无法构建应用程序(退出值1)

当我在Xerces库中导入时,我似乎无法构建我的应用程序。 由于之前的问题,我已经在使用multidex,因此我知道这一切都已正确设置。

我花了几天时间在线查看并尝试各种版本的Xerces并调整到我的build.gradle但无法解决问题。 我已经尝试过清理重建,重新设置Android Studio /我的PC,使用jar直接编译,现在正式出于想法。

下面是我的build.gradle设置:

android { compileSdkVersion 23 buildToolsVersion "23.0.2" defaultConfig { applicationId "#packageid#" minSdkVersion 18 targetSdkVersion 23 versionCode 1 versionName "0.8" multiDexEnabled true } buildTypes { debug { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } release { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { // compile fileTree(include: ['*.jar'], dir: 'libs') testCompile 'junit:junit:4.12' compile 'com.android.support:multidex:1.0.1' compile 'com.google.android.gms:play-services:8.4.0' compile 'com.android.support:appcompat-v7:23.1.1' compile 'com.android.support:support-v4:23.1.1' compile 'com.android.support:design:23.1.1' compile 'me.dm7.barcodescanner:zbar:1.8.4' compile project(':rangebar-1.3') compile('com.crashlytics.sdk.android:crashlytics:2.5.5@aar') { transitive = true; } compile 'com.batch.android:batch-sdk:1.5' compile 'xerces:xercesImpl:2.11.0' // compile files('libs/xercesImpl-2.9.1.jar') } 

我已经扩展了我的应用程序,因此在课堂上使用了以下内容:

 @Override protected void attachBaseContext(Context base) { super.attachBaseContext(base); MultiDex.install(this); } 

但是,每次我尝试构建时,我都会遇到以下错误:

 Error:Execution failed for task ':app:transformClassesWithMultidexlistForDebug'. > com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.7.0_79\bin\java.exe'' finished with non-zero exit value 1 

下面是我的gradle构建错误日志的结尾部分:

 Reading program jar [C:\Documents\MobileProjects\IA\Android\app\build\intermediates\transforms\jarMerging\debug\jars\1\1f\combined.jar] Reading library jar [C:\AppData\Local\Android\sdk\build-tools\23.0.2\lib\shrinkedAndroid.jar] Preparing output jar [C:\Documents\MobileProjects\IA\Android\app\build\intermediates\multi-dex\debug\componentClasses.jar] Copying resources from program jar [C:\Documents\MobileProjects\IA\Android\app\build\intermediates\transforms\jarMerging\debug\jars\1\1f\combined.jar] :app:transformClassesWithMultidexlistForDebug FAILED FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':app:transformClassesWithMultidexlistForDebug'. > com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.7.0_79\bin\java.exe'' finished with non-zero exit value 1 * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. BUILD FAILED 

正如您尝试清理重建,重新设置Android Studio /我的PC,直接使用jar进行编译,现在我想给您一些建议。 希望它可以帮到你。

在给出建议之前,我想告诉您首先阅读本文: 使用Gradle为Multidex配置应用程序 。 然后你可以按照建议。

建议1:

对于gradle bulid,必须遵循

  dev utilizes minSDKVersion = 21 to allow the Android gradle plugin to pre-dex each module and produce an APK that can be tested on Android Lollipop without time consuming dex merging processes. 

您已将minSdkVersion用作"minSdkVersion 18" 。 所以请更新它。

建议2:

注意:对于Gradle版本低于1.1的Android插件,您需要为multidex-instrumentation添加以下依赖项:

 dependencies { androidTestCompile('com.android.support:multidex-instrumentation:1.0.1') { exclude group: 'com.android.support', module: 'multidex' } } 

注意:目前不支持使用multidex创建测试APK。

建议-3:

您的输入jar包含多个具有相同名称的资源文件。 ProGuard像往常一样继续复制资源文件,跳过以前使用过的名称的所有文件。 此外,警告可能表示某些问题,因此建议删除重复项。 一种方便的方法是在输入jar上指定filter。 没有选项可以关闭这些警告。

标准的Android构建过程会自动为您指定输入jar。 可能没有简单的方法来过滤它们以删除这些警告。 您可以从输入和库中手动删除重复的资源文件。

ProGuard可能在遇到解析错误或I / O错误或一些更严重的警告时终止:

建议4:

问题RAM。 我的Messages Gradle Build中有类似的消息

错误:任务’:app:dexDebug’的执行失败。

com.android.ide.common.process.ProcessException:org.gradle.process.internal.ExecException:进程’命令’C:\ Program Files \ Java \ jdk1.8.0_45 \ bin \ java.exe”以非完成零退出值1我的笔记本电脑上没有OS Windows 8.1的可用内存。 我关闭了一些我不需要的程序。 在那之后,我有更多的免费RAM,我的项目是在android studio中构建的。

建议-5:

有人建议关闭Android Studio并杀死java进程,这个进程非常大(1.2 GB)。 然后你可以用gradle运行。 它有助于。

建议-6:

安装最新版本的构建工具。 调整build.gradle以使用

 `buildToolsVersion "22.0.1"` 

它有助于某些情况。

我从你的build.gradle中看到你的项目似乎包含不同的模块( compile project(':rangebar-1.3') )。

我在我的多模块项目中遇到了同样的问题。 根本原因是同一个库明确包含在多个模块中。

假设您的项目具有以下结构:

 Project +-Module1 (includes Module2, Module3) +-Module2 (includes Lib.jar) +-Module3 (includes Lib.jar) 

在这种配置中,我在尝试编译Module1时遇到了同样的错误。 解决方案是重新配置模块以仅在一个地方包含Lib.jar,例如:

 Project +-Module1 (includes Module2, Module3) +-Module2 (includes Module3) +-Module3 (includes Lib.jar)