2

:)

我有一个空的应用程序。我想添加依赖项。如果我运行 gradle build 任务一切都很好。如果我将 itextg(适用于 Android 的 itext)添加到列表中,lint 会引发错误。

这是我的依赖:

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

它在运行 gradles build 任务时抛出以下错误:

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

lint-results.html 告诉我:

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.

请帮我。我不想使用abortOnError = false来“修复”


我用

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

我将 itextg-5.5.4.jar 放在我的 libs 文件夹中。

新错误:

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.
4

1 回答 1

0

你写了:

itext-pdfa 是 itext 的 android 版本。

这是不正确的。

itext-pdfa是一个 PDF/A (ISO-19005) 实现,它依赖于itextpdfiText core for Java,而不是 Android)。

如果您的 Android 应用程序不需要 PDF/A 功能,那么您不需要依赖itext-pdfa.

正如 Bruno Lowagie 所写,itextpdf使用 AWT 和其他在 Android 上不可用的东西。因此,如果您itextpdf在 Android 应用程序中直接使用或通过传递依赖项使用,那么您确实会遇到构建错误。

iTextG本质上是 iText 核心的精简版,去掉了所有 AWT 和其他对 Android 不友好的东西。(除了iTextTest似乎漏掉的 ,感谢您报告此问题!我们将在即将发布的 5.5.7 版本中修复它。) 但是,iTextG 仍然使用相同的 Maven 名称itextpdf,以便 iText 附加组件itext-pdfa和其他不需要改变任何东西。在 Maven 中不能有两个同名的不同工件。

目前 Maven 中没有 iTextG (iText for Android),您需要下载itextgjar 并将其手动添加到您的 Android 项目中,如此 SO 答案中所述:将 itextg 添加到 gradle

但是,由于似乎对 iTextG 的 Maven 版本感兴趣,我们将对其进行研究。如果我们在 Maven 上发布 iTextG,您仍然需要告诉您的构建工具(Maven、Gradle、...)排除itextpdf和显式包含itextg(或我们将要调用的任何内容)。

从 开始5.5.9,iTextG 位于 Maven Central 上,因此可以在您首选的构建工具(如 Gradle)中使用。你需要com.itextpdf:itextg:5.5.9.

在附加组件 ( pdfa, xtra, xmlworker) 中,itextpdf已被声明为可选依赖项,因此itextg可以用作替代品。

如果您的应用程序声明了对其中一个附加组件的显式依赖,没有显式依赖itextpdf,这意味着itextpdf传递依赖,那么您将必须显式添加itextpdfitextg作为依赖,这取决于您的应用是否适用于桌面/服务器或 Android/GAE。这不应该是一个问题,因为据我所知,大多数人总是添加显式依赖项itextpdfitextg无论如何。

于 2015-09-17T12:42:34.710 回答