:)
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.
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.