Skip to content

How to use Firebase in NativeScript apps? #83

Closed

Description

@jay3dec

How to use Firebase in NativeScript mobile apps ?

Activity

  1. enchev commented on Apr 27, 2015

    @enchev
    Contributor

    If you have some native library for iOS and/or Android you can add it to NativeScript application using our CLI library add command.

  2. jay3dec commented on Apr 27, 2015

    @jay3dec
    Author

    @enchev firebase is a third party library. Is there any way we can include this in our native script app and use as we do in any web app?

  3. enchev commented on Apr 27, 2015

    @enchev
    Contributor

    Indeed you can include it using the add command. After that you have full access to the public API of the lib as everything else in the platform.

  4. jay3dec commented on Apr 27, 2015

    @jay3dec
    Author

    Here is what I did to include firebase into my native script app. I copied firebase.js file in the app/lib/ folder and from the project root folder, i ran the following command:

    tns library add android app/lib/firebase.js
    

    But I get the following error

    Warning: File /home/jay/NativeApp/app/lib/firebase.js/project.properties does not exist
    shell.js: internal error
    Error: ENOTDIR, not a directory '/home/jay/NativeApp/app/lib/firebase.js'
        at Object.fs.readdirSync (fs.js:665:18)
        at /home/jay/.nvm/v0.10.32/lib/node_modules/nativescript/node_modules/shelljs/src/ls.js:105:10
        at Array.forEach (native)
        at _ls (/home/jay/.nvm/v0.10.32/lib/node_modules/nativescript/node_modules/shelljs/src/ls.js:65:9)
        at /home/jay/.nvm/v0.10.32/lib/node_modules/nativescript/node_modules/shelljs/src/common.js:111:7
        at Array.forEach (native)
        at Object.expand (/home/jay/.nvm/v0.10.32/lib/node_modules/nativescript/node_modules/shelljs/src/common.js:94:8)
        at Object._cp (/home/jay/.nvm/v0.10.32/lib/node_modules/nativescript/node_modules/shelljs/src/cp.js:155:20)
        at Object.cp (/home/jay/.nvm/v0.10.32/lib/node_modules/nativescript/node_modules/shelljs/src/common.js:186:23)
        at /home/jay/.nvm/v0.10.32/lib/node_modules/nativescript/lib/services/androi
    
  5. enchev commented on Apr 27, 2015

    @enchev
    Contributor

    You are trying to add JavaScript library while library add is for native library. You can work with JavaScript libraries only if they do not depend on some DOM or other browser specific API.

  6. jay3dec commented on Apr 27, 2015

    @jay3dec
    Author

    No it doesn't depend on anything browser specific. How to include such libraries in native script app. An example would be appreciated .

  7. enchev commented on Apr 27, 2015

    @enchev
    Contributor

    In this case you simply need to place it inside the application and use require() when needed. You can check how we use our Everlive JavaScript SDK in TelerikNEXT app

  8. jay3dec commented on Apr 27, 2015

    @jay3dec
    Author

    Ok , i guess the firebase.js has some DOM stuff, so it's throwing some errors. I tried with the android SDK lib for firebase using tns library add android app/lib/ but still when I declare firebase

    var firebaseObj = new Firebase("https://blistering-heat-2473.firebaseio.com");
    

    It throws error Firebase not defined. I checked the folder lib/Android and the library has been included there. Do I need to require it some way into the main-page.js file? Can you show an example for including a .jar file into the native script app.

  9. leandroz commented on Apr 27, 2015

    @leandroz

    @jay3dec did you check this?
    https://www.firebase.com/docs/android/quickstart.html

    The Firebase.setAndroidContext(this); in the onCreate method.

  10. jay3dec commented on Apr 27, 2015

    @jay3dec
    Author

    @leandroz Ok, so I need to initialize it before using. But where should I do this when using in Native Script apps ? Any Idea ??

  11. leandroz commented on Apr 28, 2015

    @leandroz

    The onCreate method is in application.android.js in the application module. Try doing it there and check if it works. It should be a better way i think but try doing that to test.

  12. jay3dec commented on Apr 28, 2015

    @jay3dec
    Author

    I added the Firebase.setAndroidContext(this); in onCreate method but Reference Error: Firebase is not defined is what I'm getting on running the app.
    I checked the lib/Android folder and it has the firebase-client-android-2.2.3.jar file. Do I need to do anything else to get a reference?

  13. leandroz commented on Apr 28, 2015

    @leandroz

    You should use com.firebase.client.Firebase, check the docs of the API

  14. jay3dec commented on Apr 28, 2015

    @jay3dec
    Author

    @leandroz That's in a native android application that we include using com.firebase.client.Firebase. It doesn't work in NativeScript. It's some other way. If you have tried and were successful using Firebase in NativeScript, post some working code or something for me to follow. Thanks

  15. enchev commented on Apr 28, 2015

    @enchev
    Contributor

    You need to specify both class name and namespace in NativeScipt app. For example:
    com.firebase.client.Firebase.setAndroidContext(this)

  16. jay3dec commented on Apr 28, 2015

    @jay3dec
    Author

    @enchev Thanks that was it :)

  17. added a commit that references this issue on Mar 20, 2019
  18. lock commented on Aug 31, 2019

    @lock

    This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

  19. locked and limited conversation to collaborators on Aug 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions