android - Unity 3D 插件的 Google Drive 授权错误

标签 android unity-game-engine google-oauth google-drive-api

我的 Android 应用程序的 Google Drive 服务有问题。 这是一个 Unity 3D 项目,其中包含一个使用 Google Drive API 的插件 https://github.com/midworld/unity-googledrive

我已经在 PC 版本上使用了该插件,并且运行良好。 Oauth2 授权有效,我得到一个有效的 token ,我可以从登录的谷歌用户帐户的谷歌驱动器写入、删除、下载等文件。在 PC 上,插件使用网络请求与谷歌驱动器通信。

但是当我尝试在 Android 设备上使用该插件时,我无法授权并从谷歌服务获取 Oauth2 token 。在 Android 设备上,插件使用 google drive API。 我认为错误源于我的 Manifest.xml,因为我仍然不确定它究竟应该包含什么。

错误信息:

I/Unity   (17269): Start Authorization
D/Unity-GoogleDrivePlugin(17269): setUnityActivity: com.unity3d.player.UnityPlayerNativeActivity@423bbdd0
D/Unity-GoogleDrivePlugin(17269): auth with accountName: dino******@******.com
W/AbstractGoogleClient(17269): Application name is not set. Call Builder#setApplicationName.
D/Unity-GoogleDrivePlugin(17269): google drive service: com.google.api.services.drive.Drive@423aa280
W/dalvikvm(17269): VFY: unable to resolve static field 634 (auth_client_play_services_err_notification_msg) in Lcom/google/android/gms/R$string;
D/dalvikvm(17269): VFY: replacing opcode 0x60 at 0x001a
I/dalvikvm(17269): DexOpt: unable to optimize static field ref 0x027b at 0x42 in Lcom/google/android/gms/auth/GoogleAuthUtil;.a
I/dalvikvm(17269): DexOpt: unable to optimize static field ref 0x0279 at 0x4d in Lcom/google/android/gms/auth/GoogleAuthUtil;.a
W/dalvikvm(17269): VFY: unable to resolve static field 642 (common_google_play_services_install_title) in Lcom/google/android/gms/R$string;
D/dalvikvm(17269): VFY: replacing opcode 0x60 at 0x0041
W/dalvikvm(17269): VFY: unable to resolve static field 638 (common_google_play_services_enable_title) in Lcom/google/android/gms/R$string;
D/dalvikvm(17269): VFY: replacing opcode 0x60 at 0x004c
W/dalvikvm(17269): VFY: unable to resolve static field 648 (common_google_play_services_update_title) in Lcom/google/android/gms/R$string;
D/dalvikvm(17269): VFY: replacing opcode 0x60 at 0x0057
W/dalvikvm(17269): VFY: unable to resolve static field 645 (common_google_play_services_unsupported_title) in Lcom/google/android/gms/R$string;
D/dalvikvm(17269): VFY: replacing opcode 0x60 at 0x0069
W/dalvikvm(17269): VFY: unable to resolve static field 639 (common_google_play_services_install_button) in Lcom/google/android/gms/R$string;
D/dalvikvm(17269): VFY: replacing opcode 0x60 at 0x0009
W/dalvikvm(17269): VFY: unable to resolve static field 636 (common_google_play_services_enable_button) in Lcom/google/android/gms/R$string;
D/dalvikvm(17269): VFY: replacing opcode 0x60 at 0x0010
W/dalvikvm(17269): VFY: unable to resolve static field 646 (common_google_play_services_update_button) in Lcom/google/android/gms/R$string;
D/dalvikvm(17269): VFY: replacing opcode 0x60 at 0x0017
W/dalvikvm(17269): VFY: unable to resolve static field 643 (common_google_play_services_unknown_issue) in Lcom/google/android/gms/R$string;
D/dalvikvm(17269): VFY: replacing opcode 0x60 at 0x0004
I/dalvikvm(17269): DexOpt: unable to optimize static field ref 0x0281 at 0x18 in Lcom/google/android/gms/common/GooglePlayServicesUtil;.c
I/dalvikvm(17269): DexOpt: unable to optimize static field ref 0x0280 at 0x38 in Lcom/google/android/gms/common/GooglePlayServicesUtil;.c
I/dalvikvm(17269): DexOpt: unable to optimize static field ref 0x027d at 0x3f in Lcom/google/android/gms/common/GooglePlayServicesUtil;.c
I/dalvikvm(17269): DexOpt: unable to optimize static field ref 0x0287 at 0x46 in Lcom/google/android/gms/common/GooglePlayServicesUtil;.c
I/dalvikvm(17269): DexOpt: unable to optimize static field ref 0x0284 at 0x66 in Lcom/google/android/gms/common/GooglePlayServicesUtil;.c
W/GLSUser ( 5447): GoogleAccountDataService.getToken()
W/GLSActivity( 5447): [art] Status from wire: INVALID_KEY status: null
W/GLSActivity( 5447): [art] Status from wire: INVALID_KEY status: null
I/GLSUser ( 5447): GLS error: INVALID_KEY dino******@******.com oauth2:https://www.googleapis.com/auth/drive.file https://www.googleapis.com/auth/drive.appdata
W/GLSActivity( 5447): [art] Status from wire: Unknown status: UNKNOWN
E/Unity-GoogleDrivePlugin(17269): checkAuthorized: com.google.android.gms.auth.GoogleAuthException: Unknown
I/Unity   (17269): GoogleDrive+Exception: Authorization failed.

我的 list :

<?xml version="1.0" encoding="utf-8"?>
<manifest 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:installLocation="preferExternal"
    package="com.studio272.unitydrivetest" 
    android:versionName="1.0" 
    android:versionCode="1">

  <supports-screens 
    android:smallScreens="true" 
    android:normalScreens="true" 
    android:largeScreens="true" 
    android:xlargeScreens="true" 
    android:anyDensity="true" />

  <application 
    android:icon="@drawable/app_icon" 
    android:label="@string/app_name" 
    android:debuggable="false">

    <activity 
        android:name="com.unity3d.player.UnityPlayerProxyActivity" 
        android:label="@string/app_name" 
        android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" 
        android:screenOrientation="portrait">

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

    <activity 
        android:name="com.unity3d.player.UnityPlayerActivity" 
        android:label="@string/app_name" 
        android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" 
        android:screenOrientation="portrait">
    </activity>

    <activity 
        android:name="com.unity3d.player.UnityPlayerNativeActivity" 
        android:label="@string/app_name" 
        android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen" 
        android:screenOrientation="portrait">
      <meta-data android:name="android.app.lib_name" android:value="unity" />
      <meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="false" />
    </activity>

    <activity 
        android:name="com.unity3d.player.VideoPlayer" 
        android:label="@string/app_name" 
        android:screenOrientation="behind" 
        android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
    </activity>

    <activity 
        android:name="com.studio272.googledriveplugin.GoogleDrivePluginActivity" 
        android:theme="@android:style/Theme.Translucent.NoTitleBar">
        <meta-data android:name="com.google.android.apps.drive.APP_ID" android:value="id=318737920467" />
    </activity>
  </application>

  <uses-feature android:glEsVersion="0x00020000" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.USE_CREDENTIALS" />
    <uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
    <uses-permission android:name="android.permission.INTERNET" />
  <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" />
</manifest>

最佳答案

我找到了解决方案。 在 unity 3D 中,我还必须说明 Unity 应该使用什么 keystore 和 Bundle 来签署我的 apk 文件。

因此,在“编辑 -> 项目设置 -> 播放器”下,然后在“Android -> 发布设置”部分,我必须浏览到我正在使用的 keystore 并输入 keystore 的密码。同样选择“别名”并再次输入密码

此外,在“Android 部分 -> 其他设置”中,我必须将“Bundle Identifier”设置为来自 Google 开发者控制台的包名称。

现在可以使用 OAuth2 token 进行身份验证,我可以使用谷歌驱动器了。

关于android - Unity 3D 插件的 Google Drive 授权错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23992457/

相关文章:

c# - 如何在netcore1.1项目上集成Google OAuth2 MVC?

android - padding和android :gravity的区别

android - Unity在Android上播放视频

memory - 从unity3d中的url异步获取图像

file-io - 从文件加载图像并设置到 UnityEngine.UI.Image Unity

java - 使用 Google OAuth2 以编程方式登录网站

android - 使用 Android 的 Gmail API 访问

android - Cordova 构建 |运行失败 - compileDebugJavaWithJavac

android - 如何处理 fb sdk 4.18.0 中的注销按钮单击?

c# - 通过 Unity 启动时,Visual Studio Code .NET 框架无法工作