How to access Google Play Services in NativeScript

前端 未结 1 1899
名媛妹妹
名媛妹妹 2021-02-10 14:50

I am currently starting with NativeScript. I am trying to include certain Google Play Services to the android project. I put the relevant .aar files into the node_modules/ fold

相关标签:
1条回答
  • 2021-02-10 15:19

    In NativeScript when developing for Angular if a library/plugin is available in Jcenter/Maven Repository (Repositories for Android plugins, much like npmjs for all things JavaScript), or in your local Android SDK installation, then you can reference that dependency in your App_Resources/Android/app.gradle file.

    Example:

    dependencies {
        compile 'com.google.android.gms:play-services:9.0.0'
    }
    
    android {  
      defaultConfig {  
        generatedDensities = []
        applicationId = "org.nativescript.myApp"  
      }  
      aaptOptions {  
        additionalParameters "--no-version-vectors"  
      }  
    } 
    

    Build-time those dependencies will be downloaded and properly added to the project, so that you may consume them in your app.

    As the next step you may want to read up on the usage of the library that you want to use. That will most likely be API Docs site, or Android/Java code samples. In NativeScript you are able to access Native API as you would if you were writing a native application. That means that "translating" the code you find in samples should be almost effortless. You can find sufficient information in the official docs site to get you started.

    https://docs.nativescript.org/runtimes/android/marshalling/java-to-js https://docs.nativescript.org/runtimes/android/metadata/accessing-packages.html

    Having said all that - back to your code sample - the class that you are attempting to instantiate is abstract, meaning you can only create instances of a non-abstract non-static descendant of that class (https://developers.google.com/android/reference/com/google/android/gms/common/api/GoogleApiClient).

    If you were to write that in NativeScript however, for the sake of the example, let's assume we CAN create instances, we would write it like this -> var apiClient = new com.google.android.gms.common.api.GoogleApiClient();

    Good luck!

    0 讨论(0)
提交回复
热议问题