Page 1 of 1

Gradle build fails on 2.8.0-SNAPSHOT on android 5.1

PostPosted: Wed Apr 06, 2016 5:08 pm
by digler99
I can't get gradle to build the apk using the 2.8.0 SNAPSHOT. I added all the libs from the docxToHTML for android page. When I googled the error, someone said if you disable serializer-2.7.1.jar it will fix the gradle build. but I need everything to work, as I'm embedding pictures in my documents.

Can someone please have a look and see if there is a way to fix it ? Thanks

Code: Select all
Warning:Ignoring InnerClasses attribute for an anonymous inner class
Warning:Ignoring InnerClasses attribute for an anonymous inner class
Warning:Ignoring InnerClasses attribute for an anonymous inner class
Warning:Ignoring InnerClasses attribute for an anonymous inner class
Error:com.android.dx.cf.iface.ParseException: bad utf-8 byte 9a at offset 00000002
Error:java.lang.IllegalArgumentException: bad utf-8 byte 9a at offset 00000002
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/usr/lib/jvm/java-8-oracle/bin/java'' finished with non-zero exit value 1
Information:BUILD FAILED
Information:Total time: 21.387 secs
Information:3 errors
Information:85 warnings
Information:See complete output in console


Code: Select all
warning: Ignoring InnerClasses attribute for an anonymous inner class
(org.apache.xml.serializer.dom3.LSSerializerImpl$1) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.

UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.RuntimeException: Exception parsing classes
   at com.android.dx.command.dexer.Main.processClass(Main.java:752)
   at com.android.dx.command.dexer.Main.processFileBytes(Main.java:718)
   at com.android.dx.command.dexer.Main.access$1200(Main.java:85)
   at com.android.dx.command.dexer.Main$FileBytesConsumer.processFileBytes(Main.java:1645)
   at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)
   at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
   at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
   at com.android.dx.command.dexer.Main.processOne(Main.java:672)
   at com.android.dx.command.dexer.Main.processAllFiles(Main.java:574)
   at com.android.dx.command.dexer.Main.runMultiDex(Main.java:366)
   at com.android.dx.command.dexer.Main.run(Main.java:275)
   at com.android.dx.command.dexer.Main.main(Main.java:245)
   at com.android.dx.command.Main.main(Main.java:106)
Caused by: com.android.dx.cf.iface.ParseException: bad utf-8 byte 9a at offset 00000002
   at com.android.dx.cf.cst.ConstantPoolParser.parseUtf8(ConstantPoolParser.java:374)
   at com.android.dx.cf.cst.ConstantPoolParser.parse0(ConstantPoolParser.java:262)
   at com.android.dx.cf.cst.ConstantPoolParser.parse0(ConstantPoolParser.java:294)
   at com.android.dx.cf.cst.ConstantPoolParser.parse(ConstantPoolParser.java:150)
   at com.android.dx.cf.cst.ConstantPoolParser.parseIfNecessary(ConstantPoolParser.java:124)
   at com.android.dx.cf.cst.ConstantPoolParser.getPool(ConstantPoolParser.java:115)
   at com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:482)
   at com.android.dx.cf.direct.DirectClassFile.parse(DirectClassFile.java:406)
   at com.android.dx.cf.direct.DirectClassFile.parseToInterfacesIfNecessary(DirectClassFile.java:388)
   at com.android.dx.cf.direct.DirectClassFile.getMagic(DirectClassFile.java:251)
   at com.android.dx.command.dexer.Main.parseClass(Main.java:764)
   at com.android.dx.command.dexer.Main.access$1500(Main.java:85)
   at com.android.dx.command.dexer.Main$ClassParserTask.call(Main.java:1684)
   at com.android.dx.command.dexer.Main.processClass(Main.java:749)
   ... 12 more
Caused by: java.lang.IllegalArgumentException: bad utf-8 byte 9a at offset 00000002
   at com.android.dx.rop.cst.CstString.throwBadUtf8(CstString.java:171)
   at com.android.dx.rop.cst.CstString.utf8BytesToString(CstString.java:143)
   at com.android.dx.rop.cst.CstString.<init>(CstString.java:200)
   at com.android.dx.cf.cst.ConstantPoolParser.parseUtf8(ConstantPoolParser.java:371)
   ... 25 more
1 error; aborting


FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/usr/lib/jvm/java-8-oracle/bin/java'' 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



here is my build.gradle file

Code: Select all
apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion '23.0.3'
    defaultConfig {
        applicationId "mcapps.InspectionReporter"
        minSdkVersion 22
        targetSdkVersion 22

        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
            debuggable true
        }
    }
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
    }
    productFlavors {
    }
}

dependencies {
    compile files('libs/ae-docx4j-2.8.0-SNAPSHOT.jar')
    compile files('libs/activation.jar')
    compile files('libs/ae-jaxb-2.2.5.jar')
    compile files('libs/istack-commons-runtime.jar')
    compile files('libs/log4j-1.2.15.jar')
    compile files('libs/additionnal.jar')
    compile files('libs/jaxp-datatype.jar')
    compile files('libs/commons-logging-1.1.1.jar')
    compile files('libs/ae-xmlgraphics-commons.jar')
    compile files('libs/ae-awt.jar')
    compile files('libs/JAXBNamespacePrefixMapper-2.2.4.jar')
    compile files('libs/avalon-framework-api-4.3.1.jar')
    compile files('libs/avalon-framework-impl-4.3.1.jar')
    compile 'com.google.android.gms:play-services-appindexing:8.1.0'
    compile files('libs/commons-codec-1.3.jar')
    compile files('libs/commons-io-1.3.1.jar')
    compile files('libs/commons-lang-2.4.jar')
    compile files('libs/serializer-2.7.1.jar')
    compile files('libs/stringtemplate-3.2.1.jar')
    compile files('libs/txw2-20110809.jar')
    compile files('libs/w3c-css.jar')
    compile files('libs/commons-io-1.3.1.jar')
    compile files('libs/serializer-2.7.1.jar')
    compile files('libs/commons-lang-2.4.jar')
}

Re: Gradle build fails on 2.8.0-SNAPSHOT on android 5.1

PostPosted: Sat Apr 09, 2016 3:34 pm
by digler99
Edit: I solved this guys,

First, I got serializer to work with android by adding its source, not using the jar files.

Second, my overall issue was getting docx4j to embed images, which Jason already said what the problem was in another thread (to auto-detect the images requires a "loader" that ultimately depends on some AWT or SWING or some other crap that isn't available on android.

So the way around this is to hack 3 files: BinaryPartAbstractImage.java and ImageManager.java and DefaultImagecontext.java

Just put these files in the appropriate path (org.apache.xmlgraphics.image.loader.impl.DefaultImageContext, org.apache.xmlgraphics.image.ImageManager, docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage ) in your Android Studio

I hacked them so they work with jpegs

BinaryPartAbstractImage.java : http://pastebin.com/NVt2JU25
ImageManager.java http://pastebin.com/S4ymiJch
DefaultImageContext.java http://pastebin.com/pdJjEGVd