2

:)

I got an empty app. I wanted to add the dependencies. If I run the gradle build task everything is fine. If I add itextg (itext for Android) to the list, lint throws an error.

This is my dependency:

compile 'com.itextpdf:itext-pdfa:5.5.6-1'

It throws the following error on running gradles build task:

:app:lint
Ran lint on variant debug: 16 issues found
Ran lint on variant release: 16 issues found
Wrote HTML report to file:/D:/Git%20Projekte/Umsatzerfassung/app/build/outputs/lint-results.html
Wrote XML report to D:\Git Projekte\Umsatzerfassung\app\build\outputs\lint-results.xml
:app:lint FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:lint'.
> Lint found errors in the project; aborting build.

Fix the issues identified by lint, or add the following to your build script to proceed with errors:
...
android {
    lintOptions {
        abortOnError false
    }
}
...

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 43.762 secs
Lint found errors in the project; aborting build.

Fix the issues identified by lint, or add the following to your build script to proceed with errors:
...
android {
    lintOptions {
        abortOnError false
    }
}
...
09:00:01: External task execution finished 'build'.

The lint-results.html tells me:

InvalidPackage: Package not included in Android
C:\Users\Dominic Fuchs\.gradle\caches\modules-2\files-2.1\com.itextpdf\itextpdf\5.5.6\19448fdba5df68602aed364b86fd14d89c07a66e\itextpdf-5.5.6.jar: Invalid package reference in library; not included in Android: java.awt.color. Referenced from com.itextpdf.awt.PdfGraphics2D.
C:\Users\Dominic Fuchs\.gradle\caches\modules-2\files-2.1\com.itextpdf\itextpdf\5.5.6\19448fdba5df68602aed364b86fd14d89c07a66e\itextpdf-5.5.6.jar: Invalid package reference in library; not included in Android: java.awt.geom. Referenced from com.itextpdf.awt.PdfGraphics2D.
C:\Users\Dominic Fuchs\.gradle\caches\modules-2\files-2.1\com.itextpdf\itextpdf\5.5.6\19448fdba5df68602aed364b86fd14d89c07a66e\itextpdf-5.5.6.jar: Invalid package reference in library; not included in Android: java.awt.image.renderable. Referenced from com.itextpdf.awt.PdfGraphics2D.
C:\Users\Dominic Fuchs\.gradle\caches\modules-2\files-2.1\com.itextpdf\itextpdf\5.5.6\19448fdba5df68602aed364b86fd14d89c07a66e\itextpdf-5.5.6.jar: Invalid package reference in library; not included in Android: java.awt.image. Referenced from com.itextpdf.awt.PdfGraphics2D.
C:\Users\Dominic Fuchs\.gradle\caches\modules-2\files-2.1\com.itextpdf\itextpdf\5.5.6\19448fdba5df68602aed364b86fd14d89c07a66e\itextpdf-5.5.6.jar: Invalid package reference in library; not included in Android: java.awt.print. Referenced from com.itextpdf.awt.PdfPrinterGraphics2D.
Priority: 6 / 10
Category: Correctness
Severity: Error
Explanation: Package not included in Android.
This check scans through libraries looking for calls to APIs that are not included in Android.

When you create Android projects, the classpath is set up such that you can only access classes in the API packages that are included in Android. However, if you add other projects to your libs/ folder, there is no guarantee that those .jar files were built with an Android specific classpath, and in particular, they could be accessing unsupported APIs such as java.applet.

This check scans through library jars and looks for references to API packages that are not included in Android and flags these. This is only an error if your code calls one of the library classes which wind up referencing the unsupported package.

More info:

To suppress this error, use the issue id "InvalidPackage" as explained in the Suppressing Warnings and Errors section.

Please help me. I dont want to use abortOnError = false for "fixing"


I replaced the dependency with

compile fileTree(dir: 'libs', include: ['*.jar'])

I put itextg-5.5.4.jar in my libs folder.

New Error:

InvalidPackage: Package not included in Android
../../libs/itextg-5.5.4.jar: Invalid package reference in library; not included in Android: javax.management. Referenced from com.itextpdf.testutils.ITextTest.
Priority: 6 / 10
Category: Correctness
Severity: Error
Explanation: Package not included in Android.
This check scans through libraries looking for calls to APIs that are not included in Android.

When you create Android projects, the classpath is set up such that you can only access classes in the API packages that are included in Android. However, if you add other projects to your libs/ folder, there is no guarantee that those .jar files were built with an Android specific classpath, and in particular, they could be accessing unsupported APIs such as java.applet.

This check scans through library jars and looks for references to API packages that are not included in Android and flags these. This is only an error if your code calls one of the library classes which wind up referencing the unsupported package.

More info:

To suppress this error, use the issue id "InvalidPackage" as explained in the Suppressing Warnings and Errors section.
Dominic Fuchs
  • 315
  • 1
  • 3
  • 10
  • You claim that you are using [iTextG](http://itextpdf.com/product/itextg), but your error message tells us that you are using iText. I have more trust in what your error message tells me than in what you tell me, so please switch to using iTextG instead of using iText. iTextG is the Android port of iText. The main difference is that all dependencies on classes such as `java.awt.Color` are removed from iTextG. There is no `PdfGraphics2D` class in iTextG (which also proves that your allegation that you're using iTextG is wrong). – Bruno Lowagie Sep 17 '15 at 07:17
  • itext-pdfa is the android version of itext. itext-pdfa got itext as compile dependency. Maybe this is the reason? – Dominic Fuchs Sep 17 '15 at 08:04
  • I will download the itextg-jar manually and will add it to my filetree. Lets have a try. :) – Dominic Fuchs Sep 17 '15 at 08:05
  • I edited my post above. – Dominic Fuchs Sep 17 '15 at 08:13
  • 1
    Aha, I see that `ITextTest` is included in iTextG. This should be removed. I'll inform the release engineer. We'll fix this in iText 5.5.7. – Bruno Lowagie Sep 17 '15 at 08:31
  • Super that would be great! :) But to use itextG is correct isnt it? Is there a difference to the itextpdfa provided by maven? – Dominic Fuchs Sep 17 '15 at 08:45
  • I'm not sure if iTextG is available on Maven, nor do I know if there's a separate Android port for the PDF/A jar. I'll ask the release technician to answer here directly. (He already informed me that iTextG 5.5.7 is due for tomorrow.) – Bruno Lowagie Sep 17 '15 at 09:03
  • Ok thanks alot! iTextG in maven would be great. – Dominic Fuchs Sep 17 '15 at 11:27
  • But it isn't going to happen as explained here: http://stackoverflow.com/questions/31892031/adding-itextg-to-gradle/31913864#31913864 I've received additional information about dependency conflicts that would be created if iTextG would be distributed over Maven. – Bruno Lowagie Sep 17 '15 at 12:22

1 Answers1

0

You wrote:

itext-pdfa is the android version of itext.

That is not correct.

itext-pdfa is a PDF/A (ISO-19005) implementation that has a dependency on itextpdf (iText core for Java, not Android).

If your Android application does not require PDF/A functionality, then you do not need a dependency on itext-pdfa.

As Bruno Lowagie wrote, itextpdf uses AWT and other stuff that isn't available on Android. So if you use itextpdf in your Android application, either directly or through a transitive dependency, then you will indeed get build errors.

iTextG is essentially a slimmed down version of iText core, with all the AWT and other Android-unfriendly stuff stripped away. (Except for iTextTest, which seems to have slipped through, thank you for reporting this! We'll have it fixed in the upcoming 5.5.7 release.) However, iTextG still uses the same Maven name itextpdf so that iText add-ons like itext-pdfa and others don't need to change anything. You can't have two different artifacts with the same name in Maven.

Currently there is no iTextG (iText for Android) in Maven, you need to download the itextg jar and add it manually to your Android project, as explained in this SO answer: Adding itextg to gradle

However since there appears to be an interest in a Maven version of iTextG, we'll look into it. If and when we release iTextG on Maven, you would still need to tell your build tool (Maven, Gradle,...) to exclude itextpdf and explicitly include itextg (or whatever we're going to call it).

As of 5.5.9, iTextG is on Maven Central so it can be used in your preferred build tools like Gradle. You need com.itextpdf:itextg:5.5.9.

In the add-ons (pdfa, xtra, xmlworker), itextpdf has been declared as an optional dependency, so itextg can be used as a drop-in replacement.

If your application declares an explicit dependency on one of the add-ons, without an explicit dependency on itextpdf, that means itextpdf is a transitive dependency, then you will have to explicitly add either itextpdf or itextg as a dependency too, depending if your app is for desktop/server or for Android/GAE. This shouldn't be an issue because as far as I can tell, most people always add an explicit dependency to itextpdf or itextg anyway.

Community
  • 1
  • 1
Amedee Van Gasse
  • 7,280
  • 5
  • 55
  • 101