我在Android应用程序的Google云端硬盘服务中遇到问题。这是一个Unity 3D项目,其中包括一个可使用Google Drive API https://github.com/midworld/unity-googledrive
的插件我已经在PC版本上使用了该插件,并且可以正常工作。 Oauth2授权有效,我得到了有效的令牌,并且可以从登录的Google用户帐户的Google云端硬盘中写入,删除,下载等文件。在PC上,该插件使用网络请求与Google驱动器进行通信。
但是当我尝试在Android设备上使用该插件时,我无法授权并从Google服务获取Oauth2令牌。在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.
我的清单:
<?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中,我还必须说出应使用什么密钥库和Bundle Unity来签名我的apk文件。
因此在“编辑->项目设置->播放器”下,然后在“ Android->发布设置”部分中,浏览了我正在使用的密钥库,并输入了密钥库的密码。也选择“别名”,然后再次输入密码
此外,在“ Android部分->其他设置”中,我必须从Google开发人员控制台中将“捆绑包标识符”设置为我的软件包名称。
现在使用OAuth2令牌进行身份验证就可以了,我可以使用Google驱动器了。
您可以检查我的文章以使用Google登录Unity3D。
https://medium.com/@capcomin/unity3d-google-signin-for-android-ios-games-fd59e4b6f027