firebase / firebase-admin-java

Firebase Admin Java SDK
https://firebase.google.com/docs/admin/setup
Apache License 2.0
545 stars 269 forks source link

Error when use Firebase Admin SDK with GraalVM Native Image #852

Open joaorodrigo opened 1 year ago

joaorodrigo commented 1 year ago

Hello, I'm getting the error below when using Firebase Admin SDK with GraalVM native image. When I run it with JVM it works perfectly.

Reference link: https://firebase.google.com/docs/auth/admin/manage-users#update_a_user

My code Example:

  if (FirebaseApp.getApps().isEmpty()) new FirebaseUtil().init(FIREBASE_AUTH_KEY);

  // Update User Firebase
  UpdateRequest request = new UpdateRequest(firebaseUid)
          .setPassword(user.getNewPassword());

  FirebaseAuth.getInstance(FirebaseApp.getInstance()).updateUser(request);

Error: java.lang.RuntimeException: java.lang.IllegalArgumentException: at br.com.healthmode.serviceapilogin.service.LoginService.saveNewPassword(LoginService.java:86) at br.com.healthmode.serviceapilogin.controller.LoginController.saveNewPassword(LoginController.java:60) at br.com.healthmode.serviceapilogin.controller.$LoginController$Definition$Exec.dispatch(Unknown Source) at io.micronaut.context.AbstractExecutableMethodsDefinition$DispatchedExecutableMethod.invoke(AbstractExecutableMethodsDefinition.java:371) at io.micronaut.context.DefaultBeanContext$4.invoke(DefaultBeanContext.java:594) at io.micronaut.web.router.AbstractRouteMatch.execute(AbstractRouteMatch.java:303) at io.micronaut.web.router.RouteMatch.execute(RouteMatch.java:111) at io.micronaut.http.context.ServerRequestContext.with(ServerRequestContext.java:103) at io.micronaut.http.server.RouteExecutor.lambda$executeRoute$14(RouteExecutor.java:659) at reactor.core.publisher.FluxDeferContextual.subscribe(FluxDeferContextual.java:49) at reactor.core.publisher.InternalFluxOperator.subscribe(InternalFluxOperator.java:62) at reactor.core.publisher.FluxSubscribeOn$SubscribeOnSubscriber.run(FluxSubscribeOn.java:194) at io.micronaut.reactive.reactor.instrument.ReactorInstrumentation.lambda$init$0(ReactorInstrumentation.java:62) at reactor.core.scheduler.WorkerTask.call(WorkerTask.java:84) at reactor.core.scheduler.WorkerTask.call(WorkerTask.java:37) at io.micronaut.scheduling.instrument.InvocationInstrumenterWrappedCallable.call(InvocationInstrumenterWrappedCallable.java:53) at java.base@17.0.6/java.util.concurrent.FutureTask.run(FutureTask.java:264) at java.base@17.0.6/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) at java.base@17.0.6/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) at java.base@17.0.6/java.lang.Thread.run(Thread.java:833) at org.graalvm.nativeimage.builder/com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine(PlatformThreads.java:775) at org.graalvm.nativeimage.builder/com.oracle.svm.core.posix.thread.PosixPlatformThreads.pthreadStartRoutine(PosixPlatformThreads.java:203) Caused by: java.lang.IllegalArgumentException: at com.google.api.client.json.JsonParser.parseValue(JsonParser.java:900) at com.google.api.client.json.JsonParser.parse(JsonParser.java:360) at com.google.api.client.json.JsonParser.parse(JsonParser.java:318) at com.google.api.client.json.JsonParser.parseAndClose(JsonParser.java:162) at com.google.api.client.json.JsonParser.parseAndClose(JsonParser.java:144) at com.google.firebase.internal.ErrorHandlingHttpClient.parse(ErrorHandlingHttpClient.java:120) at com.google.firebase.auth.internal.AuthHttpClient.parse(AuthHttpClient.java:79) at com.google.firebase.auth.FirebaseUserManager.lookupUserAccount(FirebaseUserManager.java:239) at com.google.firebase.auth.FirebaseUserManager.getUserById(FirebaseUserManager.java:121) at com.google.firebase.auth.AbstractFirebaseAuth$12.execute(AbstractFirebaseAuth.java:763) at com.google.firebase.auth.AbstractFirebaseAuth$12.execute(AbstractFirebaseAuth.java:759) at com.google.firebase.internal.CallableOperation.call(CallableOperation.java:36) at com.google.firebase.auth.AbstractFirebaseAuth.updateUser(AbstractFirebaseAuth.java:740) at br.com.healthmode.serviceapilogin.service.LoginService.saveNewPassword(LoginService.java:80) ... 21 more Caused by: java.lang.IllegalArgumentException: unable to create new instance of class com.google.firebase.auth.internal.GetAccountInfoResponse 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.json.JsonParser.parseValue(JsonParser.java:768) ... 34 more Caused by: java.lang.InstantiationException: com.google.firebase.auth.internal.GetAccountInfoResponse at java.base@17.0.6/java.lang.Class.newInstance(DynamicHub.java:639) at com.google.api.client.util.Types.newInstance(Types.java:113) ... 35 more Caused by: java.lang.NoSuchMethodException: com.google.firebase.auth.internal.GetAccountInfoResponse.() at java.base@17.0.6/java.lang.Class.getConstructor0(DynamicHub.java:3585) at java.base@17.0.6/java.lang.Class.newInstance(DynamicHub.java:626)

Is there any incompatibility between Firebase Admin SDK and Native Image?

iharsuvorau commented 3 months ago

+1 on this CC @lahirumaramba

iharsuvorau commented 3 months ago

https://graalvm.github.io/native-build-tools/latest/gradle-plugin.html#agent-support recording classes and resources with native agent and manually copying them to META-INF/native-image resolves the issue

oscarojeda commented 1 month ago

Any update on this?