androidflashairair-native-extension

How to use GooglePlayServices libs in Native Extension of Android AIR app?


I am trying to use some features of Google Play Services lib but I could not make it work. I have added the reference to the google play service libs to the manifest file (from Flash Builder)

<application android:enabled="true">
<meta-data  android:name="com.google.android.gms.version"
                android:value="@integer/google_play_services_version" />
<activity android:excludeFromRecents="false">
    <intent-filter>
        <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
    </intent-filter>
</activity>
</application>

In my ANE, I have added the reference to the source of google-play-services_lib, but when I tried to call the FREFunction to check the availability of Google Play Service

@Override
public FREObject call(FREContext context, FREObject[] args){
     boolean result = false;
     try{
      Activity activitiy = context.getActivity();
      activityContext = activitiy.getBaseContext();
          result = isGooglePlayServiceExists();

     }catch(IllegalStateException e){
      Log.e(AneUtils.TAG, "Failed to get AIR current activity", e);
 }

     FREObject obj = null;
    try{
        obj = FREObject.newObject(result);
    }catch(FREWrongThreadException e){
        Log.e(AneUtils.TAG, "Failed to create FREObject from [" + result + "]");
    }


    return obj;
}

private boolean isGooglePlayServiceExists(Context activityContext){
    int googlePlayServicesCheck = -1;
    try{
        googlePlayServicesCheck = GooglePlayServicesUtil.isGooglePlayServicesAvailable(activityContext);
    }catch(Exception e){
        Log.e(AneUtils.TAG, "Error getting googlePlayService state",e);
    }

    if(googlePlayServicesCheck == ConnectionResult.SUCCESS){
         return true;
    }
    return false;
}

The ANE crashed at the line GooglePlayServicesUtil.isGooglePlayServicesAvailable(activityContext) so I really doubted the Google Play Service libs was not added.

Has anyone successfully imported the Google Play Serivce libs into Adobe AIR Android app?

Any advice or help will be appreciated. Thank you.


Solution

  • For anyone looking for the answer, hope this helps: In order for us to use any Google Android library (or 3rd party Android library) in our ANE, you have to find out the real version number of your Android library then insert that number into your manifest file. For example, instead of

    <meta-data  android:name="com.google.android.gms.version"
                android:value="@integer/google_play_services_version" />    
    

    We have to find out the real version number and your manifest data should be :

    <meta-data  android:name="com.google.android.gms.version"
                android:value="4432145" />
    

    In this case, the number 4432145 is the version number of the GooglePlayService library that we want to use. You can find out this number in the Resource of the Android library project. In the future if you want to upgrade to use the latest version of GooglePlayService library, you have to rebuild your ANE file and correct the version number to the new version number of the library in your manifest file.