-1

I'm getting the following error when including iTextG in Android Studio,

com.android.dex.DexException: Multiple dex files define Lcom/itextpdf/awt/geom/AffineTransform;
    at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
    at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
    at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
    at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
    at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
    at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
    at com.android.dx.command.dexer.Main.runMonoDex(Main.java:303)
    at com.android.dx.command.dexer.Main.run(Main.java:246)
    at com.android.dx.command.dexer.Main.main(Main.java:215)
    at com.android.dx.command.Main.main(Main.java:106)

I don't know why but seems that there is awt in this library too. This is how i'm including it:

  1. Download itextg from http://sourceforge.net/projects/itextg/
  2. Extract the jar file
  3. Copy itextg-5.5.4.jar to the libs folder in the app directory
  4. Gradle clean

Why is the awt still in the library ?

Noor
  • 19,638
  • 38
  • 136
  • 254
  • http://stackoverflow.com/questions/21102598/android-studio-unexpected-top-level-exception – Anil Meenugu Jun 28 '15 at 10:43
  • 1
    the issue is that no library is being duplicated, i've further explained the issue in this thread, http://stackoverflow.com/questions/31100860/unexpected-top-level-exception/31100884?noredirect=1#comment50217187_31100884 – Noor Jun 28 '15 at 15:30

1 Answers1

1

Please read the exception carefully. It talks about com.itextpdf.awt. That is not the same as the forbidden java.awt.

Your allegation that awt is still in the library is wrong. The com.itextpdf.awt package is there to replace the forbidden AWT classes. Those replacement classes as such are perfectly valid and can be used on Android.

The problem you are experiencing is explained in the error message: the class com.itextpdf.awt.geom.AffineTransform is defined in different DEX files. This means that you are using more than just iTextG 5.5.x. You have more than one iTextG on your device. Remove them all and make sure you add only a single instance of iTextG.

Bruno Lowagie
  • 75,994
  • 9
  • 109
  • 165
  • is there any sample project for android which uses itexg & xmlworker ? – Noor Jun 28 '15 at 16:06
  • I know that engineering at iText Group has tested it and it worked from the first try. What's the problem? – Bruno Lowagie Jun 28 '15 at 16:13
  • In fact, I just realised that the problem is only with com.itextpdf.tool:xmlworker:5.5.6, when using it, there is an error: com.android.dex.DexException: Multiple dex files define Lcom/itextpdf/awt/geom/AffineTransform; do you have any idea why this problem ? – Noor Jun 28 '15 at 16:27
  • No, `AffineTransform` isn't part of XML Worker. The only problem I can think of, is using a different version of iTextG. For instance: using iTextG 5.5.0 with XML Worker 5.5.6. – Bruno Lowagie Jun 28 '15 at 16:52
  • I tried using both the same version yet the same problem – Noor Jun 29 '15 at 16:54
  • If you read the answers provided by other people, you should understand that the solution is simple: you are using too many iText versions. Throw everything away and start anew with *a single version of iTextG*. **That will solve your problem!** If not, you didn't throw everything away. – Bruno Lowagie Jun 29 '15 at 17:02
  • I started a completely new project, added two dependencies itextg-5.5.4.jar and com.itextpdf.tool:xmlworker:5.5.4 of the very same version, yet the same problem – Noor Jun 30 '15 at 14:21