Android plugin using play-services-nearby

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Coleim

Hello,

I am trying to create a new Android plugin that will use the play-services-nearby API.
I am working with the exe and export templates I found here: https://downloads.tuxfamily.org/godotengine/3.2/alpha0-unofficial/

When adding a simple class it works well. Then I just add the dependency to nearby api, by adding to gradle.conf:

[dependencies]
implementation 'com.google.android.gms:play-services-nearby:17.0.0'

I got then this error:

Looks like an incompatibility with the nearby api, using androidx.

So I tested several solutions, but none of them seems to works. (I’ll explain below)
Does anyone have an idea how can I fix it ?

Downgrade play-services-nearby

Looking on the internet, it seems that we can downgrade the api version to have it compatible with non x android.

So I used ‘play-services-nearby:16.0.0’.
Then the following error pop:

I then changed the gradle.conf to:

[dependencies]
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.google.android.gms:play-services-nearby:16.0.0'

This make gradle pass, however godot then completely crashes with the error:

ERROR: get: FATAL: Index p_index=-1 out of size (size()=62)
   At: ./core/cowdata.h:151

tools:replace

As suggested in the logs, I tried to use in the manifest:

<application
        tools:replace="android:appComponentFactory"
        android:appComponentFactory="android.support.v4.app.CoreComponentFactory">

But new error occur, and it seems that some libs are duplicated.

Use android X

I tried to migrate the build to androidx, by adding to gradle.properties:

android.useAndroidX=true
android.enableJetifier=true

Then needed some changes to migrate (looking at Asignaciones de clase  |  Desarrolladores de Android  |  Android Developers)

android.support.v4.app.NotificationCompat => androidx.core.app.NotificationCompat
android.support.v4.content.ContextCompat => androidx.core.content.ContextCompat
android.support.annotation.Keep => androidx.annotation.Keep

The gradle build works, but then godot crashes with the same error:

ERROR: get: FATAL: Index p_index=-1 out of size (size()=62)
   At: ./core/cowdata.h:151

So I am a little bit stuck and looking for ideas.
Also, if someone knows how to copy/paste the output of the gradle build in godot (or find the log file), it will help instead of pasting images :slight_smile:

If needed, I can provide the code example I am using.

Does anyone have any idea on how to use it ? Or already implement nearby plugin ?

Thanks a lot !

i have same error lol

le_maxy | 2020-02-01 12:55

:bust_in_silhouette: Reply From: sney

I was experiencing similar problems using a play services plugin with other plugins like Admob, Share and Vibration for Godot 3.2 after many modifications I managed to get everyone to work by migrating some codes to androidx. I don’t know if it helps you but I can tell you what worked in my case.

The plugin I used is this: GitHub - cgisca/PGSGP: Play Games Services plugin for Godot Game Engine - Android