Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android plugin using Google Fitness API for Unity3D

The main goal of my project is to create a Unity plugin that will be able to use Google Fitness step counter API. It have to provide several features like: getting daily steps count, getting total steps, saving steps amount on the google account and finally the most important and the most difficult sending notifications when steps amount have reached a specified value.

I decided to make an android plugin with running background service that will be able to send those notifications as mentioned above, but I encountered a problem on the very beginning of this project. There is a problem with Google Services initialization, which working perfectly when I’m using it in native android app, but when I’m trying to use it as android library in Unity it always fails.

logcat error:

06-05 13:49:27.991 15144-15144/? E/GMPM: GoogleService failed to initialize, status: 10, Missing an expected resource: 'R.string.google_app_id' for initializing Google services.  Possible causes are missing google-services.json or com.google.gms.google-services gradle plugin.
06-05 13:49:27.991 15144-15144/? E/GMPM: Scheduler not set. Not logging error/warn.
06-05 13:49:28.005 15144-15158/? E/GMPM: Uploading is not possible. App measurement disabled

I was thinking that key to this problem may be to somehow provide data (appIds, SHAs etc.) from generated in the Google Developers console “google-services.json” file into Unity, but .aar library which was generated from android studio contains those informations in res/values/strings file as I think it should.

I was testing many probable solutions including:

  • exporting android project from unity and adding my library module to it

  • providing my library as .jar file and “google-services.json” separately

  • providing necessary data directly in Unity in res/values/strings file

  • adding it to exported project

Ended up with the same error as I mentioned above.

Am I doing something wrong, or maybe there is an entirely different approach to this problem?

Edit:

Android Manifest from Unity (Plugins/Android):

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="<UNITY APP PACKAGE NAME>" android:versionName="1.0" android:versionCode="1" android:installLocation="preferExternal">
  <supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:xlargeScreens="true" android:anyDensity="true" />

  <uses-permission android:name="android.permission.INTERNET" />
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>


  <application android:theme="@style/UnityThemeSelector" android:icon="@drawable/app_icon" android:label="@string/app_name" android:debuggable="true" android:isGame="true" android:banner="@drawable/app_banner">

    <activity android:name="<PLUGIN PACKAGE NAME + CLASS NAME>" android:label="@string/app_name" android:screenOrientation="fullSensor" android:launchMode="singleTask" android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale">

      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
        <category android:name="android.intent.category.LEANBACK_LAUNCHER" />
      </intent-filter>

      <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
    </activity>

  </application>

  <uses-sdk android:minSdkVersion="19" android:targetSdkVersion="23" />
  <uses-feature android:glEsVersion="0x00020000" />

  <uses-feature android:name="android.hardware.touchscreen" android:required="false" />
  <uses-feature android:name="android.hardware.touchscreen.multitouch" android:required="false" />
  <uses-feature android:name="android.hardware.touchscreen.multitouch.distinct" android:required="false" />
</manifest>
like image 921
Łukasz Marecki Avatar asked Jun 05 '17 13:06

Łukasz Marecki


People also ask

Is Google fit available on Android?

The Google Fit APIs for Android are part of Google Play services. The Google Fit APIs are supported on Android 4.1 (API level 16) and higher.

How Google Fit works?

Google Fit uses sensors on your device to collect data about your physical activity, like distance and steps, even when the app is closed. You can find that data in your daily and weekly activity stats or your journal.

How do I publish a Unity game on Google Play?

Upload Your Application to Google Play ConsoleHead over to the Google Play Console, click on “Create app”, and fill in all the necessary details for the app on the first page. Before publishing, we'll release our application for internal testing (you can test it with up to 100 internal testers).


1 Answers

After a little more testing on different devices I have discovered how to encounter this problem. On both of my primary testing devices logcat shows this error each time any application got installed. Including directly builded from Unity or Android Studio and those from Google Play Store. This error seems to have no relation to my problem at all.

The problem was that I had to extend UnityPlayerActivity in my plugin to allow the Google login window pop-up to show up.

like image 137
Łukasz Marecki Avatar answered Sep 23 '22 05:09

Łukasz Marecki