0

I want to use Firebase Database in the my Gluon-mobile Project , after Reading the Firebase Docs.I tried to this make some modifications to the root level build.gradle and App level build.gradle files.
Am trying to use Firebase storge in my project and Here's what I Tried.

Controller class SignupController.java in package com.application.control.

 package com.application.control;
 public class SignupController implements Initializable
 {
@Override
public void initialize(URL location, ResourceBundle resources)
{

    if(Platform.isAndroid())
    {
        try {
          Firebase firebase = (Firebase) Class.forName("com.application.FirebaseInit").newInstance();
          firebase.startup();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
    System.out.println("Signup");
}
}

And the FirebaseInit.java which is in android/java/ dir and com.application package which performs Initialization of Firebase Storage.

   package com.application;
   public class FirebaseInit implements Firebase{
   public FirebaseInit()
   {
   }

 @Override
 public void startup()
 { 
    Context context=FXActivity.getInstance().getApplicationContext();
    FirebaseStorage storage =null;
    FirebaseApp.initializeApp(context);
    storage=FirebaseStorage.getInstance();
    if(storage!=null)
    {

         Toast.makeText(context,"Firebase Storage success",Toast.LENGTH_LONG).show();
    }
    else
        Toast.makeText(context,"Firebase Storage failed",Toast.LENGTH_LONG).show();
}
}

Firebase.java is just a Interface which is used to kick start Initialization in the controller.

package com.application;

public interface Firebase
{
public void startup();
 }

And on startup am getting these below Error on Android Device.

12-18 12:01:39.133  4279  4304 W javafx  : Loading FXML document with JavaFX API of version 8.0.102 by JavaFX runtime of version 8.0.72-ea
12-18 12:01:39.205  4279  4304 W System.err: Exception in Application start method
12-18 12:01:39.207  4279  4304 I System.out: QuantumRenderer: shutdown
12-18 12:01:39.208  4279  4299 W System.err: java.lang.reflect.InvocationTargetException
12-18 12:01:39.208  4279  4299 W System.err:    at java.lang.reflect.Method.invoke(Native Method)
12-18 12:01:39.208  4279  4299 W System.err:    at javafxports.android.DalvikLauncher$1.run(DalvikLauncher.java:188)
12-18 12:01:39.208  4279  4299 W System.err:    at java.lang.Thread.run(Thread.java:818)
12-18 12:01:39.208  4279  4299 W System.err: Caused by: java.lang.RuntimeException: Exception in Application start method
12-18 12:01:39.208  4279  4299 W System.err:    at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
12-18 12:01:39.208  4279  4299 W System.err:    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$138(LauncherImpl.java:182)
12-18 12:01:39.208  4279  4299 W System.err:    at com.sun.javafx.application.LauncherImpl.access$lambda$1(LauncherImpl.java)
12-18 12:01:39.208  4279  4299 W System.err:    at com.sun.javafx.application.LauncherImpl$$Lambda$2.run(Unknown Source)
12-18 12:01:39.208  4279  4299 W System.err:    ... 1 more
12-18 12:01:39.208  4279  4299 W System.err: Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/R$string;
12-18 12:01:39.209  4279  4299 W System.err:    at com.google.android.gms.common.internal.zzca.<init>(Unknown Source)
12-18 12:01:39.209  4279  4299 W System.err:    at com.google.firebase.FirebaseOptions.fromResource(Unknown Source)
12-18 12:01:39.209  4279  4299 W System.err:    at com.google.firebase.FirebaseApp.initializeApp(Unknown Source)
12-18 12:01:39.209  4279  4299 W System.err:    at com.application.FirebaseInit.startup(FirebaseInit.java:21)
12-18 12:01:39.209  4279  4299 W System.err:    at com.application.control.SignupController.initialize(SignupController.java:36)
12-18 12:01:39.209  4279  4299 W System.err:    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2548)
12-18 12:01:39.209  4279  4299 W System.err:    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
12-18 12:01:39.209  4279  4299 W System.err:    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3214)
12-18 12:01:39.209  4279  4299 W System.err:    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175)
12-18 12:01:39.209  4279  4299 W System.err:    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148)
12-18 12:01:39.209  4279  4299 W System.err:    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124)
12-18 12:01:39.209  4279  4299 W System.err:    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104)
12-18 12:01:39.209  4279  4299 W System.err:    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097)
12-18 12:01:39.209  4279  4299 W System.err:    at com.application.scenes.SignupPresenter.getView(SignupPresenter.java:17)
12-18 12:01:39.209  4279  4299 W System.err:    at com.application.Main.start(Main.java:40)
12-18 12:01:39.209  4279  4299 W System.err:    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$145(LauncherImpl.java:863)
12-18 12:01:39.209  4279  4299 W System.err:    at com.sun.javafx.application.LauncherImpl.access$lambda$8(LauncherImpl.java)
12-18 12:01:39.209  4279  4299 W System.err:    at com.sun.javafx.application.LauncherImpl$$Lambda$9.run(Unknown Source)
12-18 12:01:39.209  4279  4299 W System.err:    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$158(PlatformImpl.java:326)
12-18 12:01:39.209  4279  4299 W System.err:    at com.sun.javafx.application.PlatformImpl.access$lambda$6(PlatformImpl.java)
12-18 12:01:39.209  4279  4299 W System.err:    at com.sun.javafx.application.PlatformImpl$$Lambda$7.run(Unknown Source)
12-18 12:01:39.209  4279  4299 W System.err:    at com.sun.javafx.application.PlatformImpl.lambda$null$156(PlatformImpl.java:295)
12-18 12:01:39.210  4279  4299 W System.err:    at com.sun.javafx.application.PlatformImpl.access$lambda$18(PlatformImpl.java)
12-18 12:01:39.210  4279  4299 W System.err:    at com.sun.javafx.application.PlatformImpl$$Lambda$19.run(Unknown Source)
12-18 12:01:39.210  4279  4299 W System.err:    at java.security.AccessController.doPrivileged(AccessController.java:52)
12-18 12:01:39.210  4279  4299 W System.err:    at com.sun.javafx.application.PlatformImpl.lambda$runLater$157(PlatformImpl.java:294)

Please Enlighten me , how to use Firebase with Gluon-mobile.

guru_007
  • 473
  • 4
  • 16
  • You need to add the dependency to the build script class path: `classpath 'com.google.gms:google-services:3.1.0'`. – José Pereda Dec 15 '17 at 08:51
  • after adding the dependency to _app_ level build script am getting this error `Cause: android.compileSdkVersion is missing!` @JoséPereda – guru_007 Dec 15 '17 at 09:07
  • See the [documentation](http://docs.gluonhq.com/charm/4.4.1/#_android_2). – José Pereda Dec 15 '17 at 09:09
  • I have updated `compileSdkVersion` value (as in Updated Question),but Even after that am getting the same Error `Cause: android.compileSdkVersion is missing!`, @JoséPereda – guru_007 Dec 15 '17 at 10:03
  • When do you get that message? Running `android`/`androidInstall` tasks? If you use `./gradlew --info android` you will see more details of the exception. I can't reproduce your issue, with firebase 11.0.4 dependencies but without code. – José Pereda Dec 15 '17 at 17:18
  • Am using Intellji Idea for Development , and on Gradle sync am getting this Error. @JoséPereda – guru_007 Dec 15 '17 at 17:36
  • It works for me as well on IntelliJ (again, I don't have specific code, but I can run `build`, `run` or `android` tasks). Maybe you can try with a new project (make sure you have the latest Gluon plugin), and then add the Firebase dependencies? – José Pereda Dec 15 '17 at 17:40
  • I have added the firebase dependencies ,`gradle build` is sucessful,But all the Firebase dependencies are in `.aar format` ,so how do I convert it to `.jar format`.@JoséPereda – guru_007 Dec 16 '17 at 09:45
  • Look for `explodeAarDependencies` in this [question](https://stackoverflow.com/questions/43132046/gluon-mobile-cross-platform-adsview). Include `project.afterEvaluate` with it, and it will extract and include the jars from the `.aar` files. – José Pereda Dec 16 '17 at 16:56
  • Thanks @JoséPereda , it worked but am still getting this `java.lang.NoClassDefFoundError: android/os/Process` Exception on `gradle build` , Any Idea..and Here's my [project](https://guru001@bitbucket.org/guru001/firebase_javafx.git) – guru_007 Dec 17 '17 at 08:13
  • Are you running on Desktop? You need to deploy to Android and run it there. Once you do that, you'll face different problems, like you need the Android Context, and you will have to move your code to the Android package. See [Go Native](https://github.com/gluonhq/gluon-samples/tree/master/go-native) sample for that. – José Pereda Dec 17 '17 at 12:00
  • Yes you are Right ,@JoséPereda ,I've updated my Question with my new problem. – guru_007 Dec 18 '17 at 07:25
  • I think your `NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/R$string` is the same issue I was faced with several times. I already asked a question: https://stackoverflow.com/questions/46819138/generate-or-import-android-r-java-file-in-eclipse-gluon-project and filed an issue for this: https://bitbucket.org/javafxports/javafxmobile-plugin/issues/82/add-possibility-to-use-platformspecific, without any reaction so far – jns Dec 19 '17 at 02:33
  • So , what should i do .Is it another way possible to use `Firebase` in `Gluon-mobile` or it's not possible ? – guru_007 Dec 19 '17 at 05:19
  • 1
    I was able to use Firebase Realtime Database in a Gluon Mobile App via REST: https://firebase.google.com/docs/database/rest/start. But then you have to take care for user authentication yourself – jns Dec 19 '17 at 15:57

0 Answers0