使用适用于 Unity3D 的 Google Fitness API 的 Android 插件

标签 android unity3d google-api google-fit google-play-services

我项目的主要目标是创建一个能够使用 Google Fitness 计步器 API 的 Unity 插件。它必须提供多种功能,例如:获取每日步数、获取总步数、在 google 帐户上保存步数,最后在步数达到指定值时发送最重要和最困难的通知。

我决定制作一个运行后台服务的 android 插件,它将能够如上所述发送那些通知,但是我在这个项目的一开始就遇到了一个问题。谷歌服务初始化有一个问题,当我在原生 android 应用程序中使用它时,它工作得很好,但当我试图在 Unity 中将它用作 android 库时,它总是失败。

日志错误:

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

我认为这个问题的关键可能是以某种方式将 Google Developers 控制台“google-services.json”文件中生成的数据(appId、SHA 等)提供给 Unity,但是 .aar 库是从android studio 在 res/values/strings 文件中包含我认为应该包含的这些信息。

我正在测试许多可能的解决方案,包括:

  • 从 unity 中导出 android 项目并将我的库模块添加到其中

  • 将我的库作为 .jar 文件和“google-services.json”分别提供

  • 直接在 Unity 中的 res/values/strings 文件中提供必要的数据

  • 将其添加到导出的项目

最终出现了与我上面提到的相同的错误。

我是不是做错了什么,或者可能有一种完全不同的方法来解决这个问题?

编辑:

Unity 的 Android list (插件/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>

最佳答案

在不同设备上进行更多测试后,我发现了如何遇到这个问题。在我的两个主要测试设备上,每次安装任何应用程序时,logcat 都会显示此错误。包括直接从 Unity 或 Android Studio 构建的以及来自 Google Play Store 的构建。这个错误似乎与我的问题完全无关。

问题是我必须在我的插件中扩展 UnityPlayerActivity 以允许显示 Google 登录窗口弹出窗口。

关于使用适用于 Unity3D 的 Google Fitness API 的 Android 插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44370531/

相关文章:

android - 如何使用命令行在 Android Studio 之外安装 android 约束布局工具?

c# - GetComponent 返回 null

c# - Unity 3D VR (5.6),如何使用 GVR Pointer Physic Raycaster 检测物体?

android - Facebook Android 3.0 所有示例中的空白登录页面

android - 使用调试构建作为调试符号源

php - 如何从 Google PHP API 负载获取额外的范围信息?

java - map 就绪回调返回 null

python - Google+ 登录 Python 服务器 - "invalid_client - The OAuth client was not found"

android - 每个 ListView 行中的按钮按下状态问题

android - 没有找到 void com.unity3d.player.UnityPlayer.nativeRestartActivityIndi​​cator() 的实现