【问题标题】:Android plugin using Google Fitness API for Unity3D使用 Google Fitness API for Unity3D 的 Android 插件
【发布时间】:2017-06-05 13:51:14
【问题描述】:

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

我决定制作一个运行后台服务的 android 插件,该插件将能够发送上述通知,但我在这个项目的一开始就遇到了问题。 Google 服务初始化存在问题,当我在原生 android 应用程序中使用它时,它可以正常工作,但是当我尝试将它用作 Unity 中的 android 库时,它总是失败。

logcat 错误:

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”文件中生成的数据(appIds、SHA 等)提供到 Unity 中,但 .aar 库是从android studio 在 res/values/strings 文件中包含我认为应该的这些信息。

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

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

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

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

  • 将其添加到导出的项目中

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

是我做错了什么,还是有完全不同的方法来解决这个问题?

编辑:

来自 Unity 的 Android 清单(插件/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>

【问题讨论】:

  • 你提供给Unity的res/values/strings文件的数据是什么?你的android manifest 是什么样的?

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


【解决方案1】:

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

问题是我必须在插件中扩展 UnityPlayerActivity 才能显示 Google 登录窗口弹出窗口。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-05-03
  • 2017-04-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多