错误:应该在运行时初始化的类在映像构建期间被初始化:org.conscrypt.conscrypt被意外初始化

o0lyfsai  于 2021-06-29  发布在  Java
关注(0)|答案(1)|浏览(1024)

使用java 11.0.9(graalvm ce 20.3.0)和micronaut 2.2.1应用程序(使用firebase admin 7.1.0),根据micronaut文档将我的应用程序打包为本机映像时,出现以下错误:

$ ./gradlew nativeImage 
> Task :nativeImage
[application:15026]    classlist:   4,054.46 ms,  1.19 GB
[application:15026]        (cap):     504.32 ms,  1.19 GB
[application:15026]        setup:   1,827.02 ms,  1.19 GB
To see how the classes got initialized, use --trace-class-initialization=org.conscrypt.Conscrypt,org.conscrypt.OpenSSLProvider
[application:15026]     analysis:  29,787.52 ms,  3.90 GB
Error: Classes that should be initialized at run time got initialized during image building:
 org.conscrypt.Conscrypt was unintentionally initialized at build time. To see why org.conscrypt.Conscrypt got initialized use --trace-class-initialization=org.conscrypt.Conscrypt
org.conscrypt.OpenSSLProvider was unintentionally initialized at build time. To see why org.conscrypt.OpenSSLProvider got initialized use --trace-class-initialization=org.conscrypt.OpenSSLProvider

Error: Use -H:+ReportExceptionStackTraces to print stacktrace of underlying exception
Error: Image build request failed with exit status 1

> Task :nativeImage FAILED

FAILURE: Build failed with an exception.

问题是由包中的类引起的 org.conscrypt . 相关依赖项来自 com.google.cloud:google-cloud-firestore:1.35.0 这很吸引人 org.conscrypt:conscrypt-openjdk-uber:2.2.1 .
我对graalvm还很陌生,还远远不了解这个问题的起因。不过,我注意到应该可以传递给 native-image 一些参数,例如 --initialize-at-build-time .
我的问题是如何解决这个问题?是否有要创建的配置文件,micronaut从选项中读取并转发到 native-image 可执行文件?

wixjitnu

wixjitnu1#

问题是由 com.google.cloud:google-cloud-firestore:1.35.0 以及它如何使用依赖关系。此依赖项不支持现成的本机映像。
目前正在努力在这个官方存储库中添加对graalvm的支持:https://github.com/googlecloudplatform/google-cloud-graalvm-support
不幸的是,gradle用法似乎不起作用:https://github.com/googlecloudplatform/google-cloud-graalvm-support/issues/58
关于micronaut的本机映像配置,您可以通过配置文件传递选项。假设你的groupid是 com.acme 你的人工智能是 acme-module1 ,则需要在项目中创建文件 src/main/resources/META-INF/native-image/com/acme/acme-module1/native-image.properties 作为内容:

Args = --initialize-at-build-time=org.conscrypt

一旦创建,本地的形象建设和基本的执行工作。但是,一旦可执行文件调用使用 com.google.cloud:google-cloud-firestore 由于缺少某些本机映像配置,将出现运行时错误:

Caused by: java.lang.IllegalArgumentException: unable to create new instance of class com.google.api.client.json.GenericJson because it has no accessible default constructor
    at com.google.api.client.util.Types.handleExceptionForNewInstance(Types.java:162)
    at com.google.api.client.util.Types.newInstance(Types.java:117)
    at com.google.api.client.util.Data.newMapInstance(Data.java:539)
    at com.google.api.client.json.JsonParser.parseValue(JsonParser.java:766)
    ... 126 common frames omitted
Caused by: java.lang.InstantiationException: Type `com.google.api.client.json.GenericJson` can not be instantiated reflectively as it does not have a no-parameter constructor or the no-parameter constructor has not been added explicitly to the native image.
    at java.lang.Class.newInstance(DynamicHub.java:915)
    at com.google.api.client.util.Types.newInstance(Types.java:113)
    ... 128 common frames omitted

相关问题