简体   繁体   中英

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>

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM