Page 1 of 1

Problems adding Firebase SDK to an extension

Posted: 07 Feb 2020, 18:13
by matiasini
Hi,
I am trying to add firebase sdk to an extension.
I have added the .jar that I need in /Applications/SmartFoxServer_2X/SFS2X/lib
The problem is that Smartfox apparently does not recognize these libraries.
I have opened the .bash_profile file and added this:

Code: Select all

export CLASSPATH="/Applications/SmartFoxServer_2X/SFS2X/lib/"

What am I doing wrong?
In the log I have this error:

Code: Select all

07 Feb 2020 | 14:38:07,882 | ERROR | Thread-9 | entities.managers.SFSExtensionManager |     | java.lang.NoClassDefFoundError:
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Exception: java.lang.NoClassDefFoundError
Message: com/google/firebase/FirebaseOptions$Builder
Description: An error occurred while reloading extension: MyHomeExtension in { Zone: Home }
The new extension might not function properly.
+--- --- ---+
Stack Trace:
+--- --- ---+
tv.ingames.myHomeExtension.MyHomeExtension.init(MyHomeExtension.java:29)
com.smartfoxserver.v2.entities.managers.SFSExtensionManager.createExtension(SFSExtensionManager.java:303)
com.smartfoxserver.v2.entities.managers.SFSExtensionManager.reloadExtension(SFSExtensionManager.java:534)
com.smartfoxserver.v2.entities.managers.SFSExtensionManager$ExtensionFileChangeListener.fileChanged(SFSExtensionManager.java:111)
org.apache.commons.vfs.events.ChangedEvent.notify(ChangedEvent.java:34)
org.apache.commons.vfs.provider.AbstractFileSystem.fireEvent(AbstractFileSystem.java:519)
org.apache.commons.vfs.provider.AbstractFileSystem.fireFileChanged(AbstractFileSystem.java:487)
org.apache.commons.vfs.impl.DefaultFileMonitor$FileMonitorAgent.check(DefaultFileMonitor.java:647)
org.apache.commons.vfs.impl.DefaultFileMonitor$FileMonitorAgent.access$200(DefaultFileMonitor.java:418)
org.apache.commons.vfs.impl.DefaultFileMonitor.run(DefaultFileMonitor.java:373)
java.lang.Thread.run(Thread.java:748)
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::


This post comments on opening the file conf/wrapper.conf , but where can I find this file?
viewtopic.php?f=4&t=1878

Please, HELP :)

Re: Problems adding Firebase SDK to an extension

Posted: 08 Feb 2020, 15:13
by Lapo
[ Thread was moved in the correct section ]
There seem to be some confusion here. You posted under the SFS1.x section but you're talking about SFS2X.

As regards copying the library under SFS2X/lib/ it is correct. Make sure you're not also bundling the library in your Extension jar file. Also you don't need to add anything else, including editing your bash profile.

I've tried adding the firabese jar found here:
https://mvnrepository.com/artifact/com. ... min/6.12.1
And I don't see any problems loading the FirebaseOptions class.

This post comments on opening the file conf/wrapper.conf , but where can I find this file?

Nowhere. This is stuff related to SFS1.x not 2X

Cheers

Re: Problems adding Firebase SDK to an extension

Posted: 11 Feb 2020, 01:50
by matiasini
Hi Lapo, thanks for you answer.
I'm new with smartfox and I was reading things from SFS1 by mistake.
It's really easy to add jars :)
I have already been able to run firebase.
Many Thanks!

Re: Problems adding Firebase SDK to an extension

Posted: 27 Jul 2021, 15:24
by CitaTo
hi Matiasini, Lapo. I am trying to use firebase sdk to an game.
I follow the guide but do not know how to add GoogleCredentials to my SmartFoxServer

Code: Select all

FirebaseOptions options = FirebaseOptions.builder()
    .setCredentials(GoogleCredentials.getApplicationDefault())
    .setDatabaseUrl("https://<DATABASE_NAME>.firebaseio.com/")
    .build();

FirebaseApp.initializeApp(options);


Please give me some tip about it.

Thank you a lot.

Re: Problems adding Firebase SDK to an extension

Posted: 27 Jul 2021, 16:18
by Lapo
Hi,
I am not familiar with FireBase. Can you explain what GoogleCredentials is?
Is it some kind of config file? Is it expected to be located in a specific path? Or maybe in the default classpath?

Cheers

Re: Problems adding Firebase SDK to an extension

Posted: 30 Jul 2021, 03:13
by CitaTo
Hi Lapo,
Thank you for your reply.

GoogleCredentials is a class to help us authentication to access to Google Cloud Platform product. It defined in `google-auth-library-oauth2-http-0.26.0.jar`
I follow your guild to put the firebase jar file to SFX/lib/ but when I use other dependencies jar show NoClassDefFoundError error. And I have to search, download and put required jar file to SFX/lib/. I have to do this loop (got error - search - download - add to SFX/lib - retry) a lot of times.

In firebase's tutorial. They said if we use Gradle or Maven, we just edit the config file.
https://firebase.google.com/docs/admin/ ... ce-account

The Firebase Admin Java SDK is published to the Maven central repository. To install the library, declare it as a dependency in your build.gradle file:

Code: Select all

dependencies {
  implementation 'com.google.firebase:firebase-admin:8.0.0'
}


If you use Maven to build your application, you can add the following dependency to your pom.xml:

Code: Select all

<dependency>
  <groupId>com.google.firebase</groupId>
  <artifactId>firebase-admin</artifactId>
  <version>8.0.0</version>
</dependency>



So, I wonder if SmartFox have any simple way like that to install a external SDK.

Thank you a lot.

Re: Problems adding Firebase SDK to an extension

Posted: 30 Jul 2021, 06:29
by Lapo
Hi,
the problem with the "loop" you have described is simply due to the fact that you need all dependencies required by Firebase.
This is a step that is necessary regardless of what platform you're working with (i.e. SFS2X in your case).

Gradle and Maven are two dependency tools that have nothing to do with SFS2X. They are useful to manage your dependencies in your development environment (i.e your Java IDE).

If you're not familiar with neither (Gradle or Maven) I'd recommend googling them and learn the basics of one of them. Maybe start with something simple like setting up a Firebase project without SFS2X, first. Then apply the same knowledge to building an SFS2X Extension that uses those libraries as well.

Hope it helps

Re: Problems adding Firebase SDK to an extension

Posted: 31 Jul 2021, 04:49
by CitaTo
Thank you a lot.

I convert my project to Maven and can get all dependencies jar files.