6

I cannot seem to get my app to build when I import in the Xerces library. I am already using the multidex due to previous issues and therefore I know this is all setup properly.

I have spend a couple of days now looking online and trying all sorts of versions of Xerces and tweaks to my build.gradle but cannot work out the issue. I have tried cleaning re-building, re-setting Android Studio/my PC, using a jar directly compiling and now officially out of ideas.

Below is my build.gradle setup:

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')
}

I have also extended my Application already and therefore have used the following within the class:

@Override
protected void attachBaseContext(Context base) {
    super.attachBaseContext(base);

    MultiDex.install(this);
}

However, every time I try to build I keep getting the following error:

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

Below is the end part of my gradle build error log:

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
BSMP
  • 4,596
  • 8
  • 33
  • 44
SingleWave Games
  • 2,618
  • 9
  • 36
  • 52
  • Could you take a look at [this answer](http://stackoverflow.com/a/33026958/1424875) and the answers to [this question](http://stackoverflow.com/questions/33007289/com-android-build-transform-api-transformexception-with-android-google-play-serv) and see if they help you? – nanofarad Apr 27 '16 at 14:34
  • I tried that, but got exactly the same issue. It also only appears to be with xerces, as was already hitting the dex 65k limit which I resolved using multidex – SingleWave Games Apr 27 '16 at 14:42
  • OK, thanks for clarifying. I'm not familiar with the Xerces library unfortunately, but it's possible that some odd class structure inside is causing problems. – nanofarad Apr 27 '16 at 14:43
  • please show your gradle console log, it's in the bottom right of Android studio – Mounir Elfassi Apr 27 '16 at 17:09
  • @MounirElfassi sorry for the delay, I have added my gradle error message into my question. – SingleWave Games May 09 '16 at 09:58

2 Answers2

3

As you have tried cleaning re-building, re-setting Android Studio/my PC, using a jar directly for compiling, now I want to give you some suggestions. Hope it can help you.

Before giving suggestion, I want to tell you to go through this article first: Configuring Your App for Multidex with Gradle. Then you can follow the suggestions.

Suggestion-1:

For gradle bulid, it must be followed

         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.

You have used minSdkVersion as "minSdkVersion 18". So plase update it.

Suggestion-2:

Note: With Android Plugin for Gradle versions lower than 1.1, you need to add the following dependency for multidex-instrumentation:

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

Note: Use of multidex for creating a test APK is not currently supported.

Suggestion-3:

Your input jars contain multiple resource files with the same name. ProGuard continues copying the resource files as usual, skipping any files with previously used names. Once more, the warning may be an indication of some problem though, so it's advisable to remove the duplicates. A convenient way to do so is by specifying filters on the input jars. There is no option to switch off these warnings.

The standard Android build process automatically specifies the input jars for you. There may not be an easy way to filter them to remove these warnings. You could remove the duplicate resource files manually from the input and the libraries.

ProGuard may terminate when it encounters parsing errors or I/O errors, or some more serious warnings:

Suggestion-4:

Problem RAM. I had similar message in my Messages Gradle Build

Error:Execution failed for task ':app:dexDebug'.

com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_45\bin\java.exe'' finished with non-zero exit value 1 I didn't have free RAM on my laptop with the OS windows 8.1. I closed a few programs that I don't need. After that, I had more free RAM and my project was built in android studio.

Suggestion-5:

Some people suggested to close Android Studio and kill the java processs, which was very big (1.2 GB). Then you can run with gradle. It helps.

Suggestion-6:

Install the latest version of the build tools. Adjust your build.gradle to use

`buildToolsVersion "22.0.1"`

It helps some cases.

SkyWalker
  • 28,384
  • 14
  • 74
  • 132
  • Tried suggestion 1, 2, 5,6 to no success. Suggestion 3 & 4 are not an issue due to me having 32gb of RAM and having ProGuard switched off. Any other suggestions or good alternatives to validating xml on the fly. – SingleWave Games May 31 '16 at 11:21
2

I see from your build.gradle that your project seems containing different modules (compile project(':rangebar-1.3')).

I had your same issue in a multi-module project of mine. The root cause was that the same library was explicitly included in more than one module.

Let's say that your project has the following strucuture:

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

In this configuration I was getting your same error trying to compile Module1. The solution was to reconfigure modules to include Lib.jar in only one single place, like for example:

Project
+-Module1 (includes Module2, Module3)
+-Module2 (includes Module3)
+-Module3 (includes Lib.jar)
Carlo
  • 1,539
  • 1
  • 11
  • 25
  • I did think something like that may have been an issue therefore I created a new blank project with only support design & multidex dependencies, but still get the same error. It only seems to be with the compiling with xerces. I can send my test project if that helps to debug it? – SingleWave Games May 12 '16 at 13:03