The main goal of my project is to create a Unity plugin that can use the Google Fitness counter API. It should provide several functions, such as: daily number of steps, receiving general steps, saving the number of steps in a google account, and finally, the most important and most complicated sending notifications when the number of steps reaches the specified value.
I decided to create an android plugin with a running background service that will be able to send these notifications, as mentioned above, but I ran into a problem at the very beginning of this project. There is a problem with initializing Google services, which works fine when I use it in my own Android application, but when I try to use it as an 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 thought that the key to this problem could somehow be to provide data (appIds, SHA, etc.) from the "google-services.json" file generated in the Google Developers console in Unity, but the .aar library that was generated from Android studio contains this data in the res / values / strings file, as it seems to me.
I tested many possible solutions, including:
Export android project from unity and add my library module to it
providing my library as a .jar file and "google-services.json" separately
providing the necessary data directly to Unity in the res / values / string file
adding it to the exported project
Ended up with the same error that I mentioned above.
Am I doing something wrong, or maybe there is a completely 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>
android unity3d google-api google-fit
Łukasz Marecki
source share