iTextG Android Lint错误

时间:2015-09-17 07:04:04

标签: android itext lint itextg

:)

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

这是我的依赖:

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

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

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

1 个答案:

答案 0 :(得分:0)

您写道:

  

itext-pdfa是itext的android版本。

这是不正确的。

itext-pdfa是一个PDF / A(ISO-19005)实现,它依赖于itextpdf iText核心的Java ,而不是Android)。

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

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

iTextG 本质上是iText核心的精简版本,所有AWT和其他Android不友好的东西都被剥夺了。 iTextTest除外,它似乎已经过了,感谢您报告此问题!我们将在即将发布的5.5.7版本中修复它。) 但是,iTextG仍然使用相同的Maven名称itextpdf,以便像itext-pdfa这样的iText附加组件和其他人不需要更改任何内容。在Maven中,您不能拥有两个具有相同名称的不同工件。

目前Maven中没有iTextG(Android版iText),您需要下载itextg jar并手动将其添加到您的Android项目中,如本答案所述:Adding itextg to gradle

然而,由于似乎对Maven版本的iTextG感兴趣,我们会研究它。如果我们在Maven上发布iTextG,您仍然需要告诉您的构建工具(Maven,Gradle,...)排除itextpdf并明确包含itextg(或我们所做的任何事情)打算叫它。)

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

在加载项(pdfaxtraxmlworker)中,itextpdf已被声明为可选依赖项,因此{ {1}}可以作为替代品使用。

如果您的应用程序在其中一个加载项上声明显式依赖项而没有明确依赖itextg ,则表示itextpdf是一个传递依赖,那么您还必须明确添加itextpdfitextpdf作为依赖项,具体取决于您的应用是用于桌面/服务器还是用于Android / GAE 。这不应该成为一个问题,因为据我所知,大多数人总是会向itextgitextpdf添加明确的依赖关系。