简体   繁体   English

Google Play 服务 (Unity) 无法在设备上运行

[英]Google Play Services (Unity) Not Working On Device

using System;
using System.Collections;
using System.Collections.Generic;
using GooglePlayGames;
using GooglePlayGames.BasicApi;
using UnityEngine;
using UnityEngine.SocialPlatforms;
using UnityEngine.EventSystems;

public class GooglePlayServicesController : MonoBehaviour
{
    public static GooglePlayServicesController googlePlayServicesController;
    public static bool hasInterent = false;
    public static PlayGamesPlatform platform;

    void Start()
    {
        if (googlePlayServicesController == null)
        {
            googlePlayServicesController = this;
        }
        DontDestroyOnLoad(this);

        if (Application.internetReachability != NetworkReachability.NotReachable)
        {
            hasInterent = true;
            SignInToGooglePlayServices();
        }
        else
        {
            hasInterent = false;
        }
        
    }

    public void AddScoreToLeaderBoard()
    {
        if (hasInterent)
        {
            PlayerController.playerController.player.LoadPlayer();
            if (Social.localUser.authenticated)
            {
                Social.ReportScore(PlayerController.playerController.player.statMoles, "YOUR ID", success => { });
            }
            else
            {
                SignInToGooglePlayServices();
            }
        }

    }
    public void ShowLeaderboard()
    {
        EventSystem.current.SetSelectedGameObject(null);

        if (hasInterent)
        {
            if (Social.localUser.authenticated)
            {
                Social.ShowLeaderboardUI();
            }
            else
            {
                SignInToGooglePlayServices();
            }
        }
    }

    public void SignInToGooglePlayServices()
    {
        if (hasInterent)
        {
            if (platform == null)
            {
                PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder().Build();
                PlayGamesPlatform.InitializeInstance(config);
                PlayGamesPlatform.DebugLogEnabled = false;
                platform = PlayGamesPlatform.Activate();
            }

            PlayGamesPlatform.Instance.Authenticate(SignInInteractivity.CanPromptOnce, (result) => { });

            Social.Active.localUser.Authenticate(success =>
            {
                if (success)
                {
                    Debug.Log("Logged in successfully");
                }
                else
                {
                    Debug.Log("Login Failed");
                }
            });
        }
    }
}

So I have one project working fine with the code i have and its been release but this project has been a bit more tricky.所以我有一个项目可以很好地使用我拥有的代码并且它已经发布但是这个项目有点棘手。 I cannot get GPGS to work on a device:我无法让 GPGS 在设备上运行:

  1. Its in internal and alpha test on the playstore它在 Playstore 的内部和 alpha 测试中

  2. I have the following in Progaurd我在 Progaurd 中有以下内容

     -keepnames class com.google.android.gms.** {*;} #GameService Rules -keep class com.google.android.gms.** { *; } -keep class com.google.games.bridge.** { *; } -keep class com.google.unity.** { *; } #Don't obfuscate. We only need dead code striping. -dontobfuscate

I Presume its something to do with this我认为这与此有关

AndroidJavaException:java.lang.ClassNotFoundException:com.google.android.gms.games.Games

but i still get this error in LogCat:但我仍然在 LogCat 中收到此错误:

0001/01/01 00:00:00.000 -1 -1 Info  --------- beginning of main
2022/05/10 21:23:53.109 6445 6445 Error ouse.HoleyMole Not starting debugger since process cannot load the jdwp agent.
2022/05/10 21:23:53.117 6445 6445 Debug CompatibilityChangeReporter Compat change id reported: 171979766; UID 10152; state: DISABLED
2022/05/10 21:23:53.122 6445 6445 Warn ouse.HoleyMole Entry not found
2022/05/10 21:23:53.123 6445 6445 Warn ouse.HoleyMole JIT profile information will not be recorded: profile file does not exist.
2022/05/10 21:23:53.125 6445 6445 Verbose GraphicsEnvironment ANGLE Developer option for 'com.DavincosWarehouse.HoleyMoley' set to: 'default'
2022/05/10 21:23:53.125 6445 6445 Verbose GraphicsEnvironment Neither updatable production driver nor prerelease driver is supported.
2022/05/10 21:23:53.126 6445 6445 Debug NetworkSecurityConfig No Network Security Config specified, using platform default
2022/05/10 21:23:53.126 6445 6445 Debug NetworkSecurityConfig No Network Security Config specified, using platform default
2022/05/10 21:23:53.158 6445 6445 Info IL2CPP JNI_OnLoad
2022/05/10 21:23:53.191 6445 6445 Info Gralloc4 mapper 4.x is not supported
2022/05/10 21:23:53.192 6445 6445 Debug HostConnection createUnique: call
2022/05/10 21:23:53.194 6445 6445 Debug HostConnection HostConnection::get() New Host Connection established 0xb4000078b23a9ed0, tid 6445
2022/05/10 21:23:53.194 6445 6445 Debug goldfish-address-space allocate: Ask for block of size 0x100
2022/05/10 21:23:53.194 6445 6445 Debug goldfish-address-space allocate: ioctl allocate returned offset 0x1efff8000 size 0x8000
2022/05/10 21:23:53.195 6445 6445 Warn Gralloc4 allocator 4.x is not supported
2022/05/10 21:23:53.220 6445 6445 Debug HostConnection HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_vulkan ANDROID_EMU_deferred_vulkan_commands ANDROID_EMU_vulkan_null_optional_strings ANDROID_EMU_vulkan_create_resources_with_requirements ANDROID_EMU_YUV_Cache ANDROID_EMU_vulkan_ignored_handles ANDROID_EMU_has_shared_slots_host_memory_allocator ANDROID_EMU_vulkan_free_memory_sync ANDROID_EMU_vulkan_shader_float16_int8 ANDROID_EMU_vulkan_async_queue_submit ANDROID_EMU_vulkan_queue_submit_with_commands ANDROID_EMU_sync_buffer_data ANDROID_EMU_read_color_buffer_dma GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_gles_max_version_3_0 
2022/05/10 21:23:53.239 6445 6463 Info Unity MemoryManager: Using 'Dynamic Heap' Allocator.
2022/05/10 21:23:53.255 6445 6463 Info Unity SystemInfo CPU = ARM64 FP ASIMD AES, Cores = 4, Memory = 1966mb
2022/05/10 21:23:53.255 6445 6463 Info Unity SystemInfo ARM big.LITTLE configuration: 4 big (mask: 0xf), 0 little (mask: 0x0)
2022/05/10 21:23:53.255 6445 6463 Info Unity ApplicationInfo com.DavincosWarehouse.HoleyMoley version 1.0.6
2022/05/10 21:23:53.255 6445 6463 Info Unity Built from '2021.3/staging' branch, Version '2021.3.2f1 (d6360bedb9a0)', Build type 'Release', Scripting Backend 'il2cpp', CPU 'arm64-v8a', Stripping 'Enabled'
2022/05/10 21:23:53.294 6445 6463 Error libprocessgroup set_timerslack_ns write failed: Operation not permitted
2022/05/10 21:23:53.294 6445 6463 Error libprocessgroup set_timerslack_ns write failed: Operation not permitted
2022/05/10 21:23:53.294 6445 6463 Error libprocessgroup set_timerslack_ns write failed: Operation not permitted
2022/05/10 21:23:53.294 6445 6463 Error libprocessgroup set_timerslack_ns write failed: Operation not permitted
2022/05/10 21:23:53.294 6445 6463 Error libprocessgroup set_timerslack_ns write failed: Operation not permitted
2022/05/10 21:23:53.294 6445 6463 Error libprocessgroup set_timerslack_ns write failed: Operation not permitted
2022/05/10 21:23:53.294 6445 6463 Error libprocessgroup set_timerslack_ns write failed: Operation not permitted
2022/05/10 21:23:53.294 6445 6463 Error libprocessgroup set_timerslack_ns write failed: Operation not permitted
2022/05/10 21:23:53.295 6445 6463 Error libprocessgroup set_timerslack_ns write failed: Operation not permitted
2022/05/10 21:23:53.295 6445 6463 Error libprocessgroup set_timerslack_ns write failed: Operation not permitted
2022/05/10 21:23:53.295 6445 6463 Error libprocessgroup set_timerslack_ns write failed: Operation not permitted
2022/05/10 21:23:53.295 6445 6463 Error libprocessgroup set_timerslack_ns write failed: Operation not permitted
2022/05/10 21:23:53.295 6445 6463 Error libprocessgroup set_timerslack_ns write failed: Operation not permitted
2022/05/10 21:23:53.295 6445 6463 Error libprocessgroup set_timerslack_ns write failed: Operation not permitted
2022/05/10 21:23:53.295 6445 6463 Error libprocessgroup set_timerslack_ns write failed: Operation not permitted
2022/05/10 21:23:53.295 6445 6463 Error libprocessgroup set_timerslack_ns write failed: Operation not permitted
2022/05/10 21:23:53.298 6445 6463 Info Unity Company Name: Davinco's Warehouse
2022/05/10 21:23:53.298 6445 6463 Info Unity Product Name: Holey Moley
2022/05/10 21:23:53.306 6445 6463 Debug libEGL loaded /vendor/lib64/egl/libEGL_emulation.so
2022/05/10 21:23:53.307 6445 6463 Debug libEGL loaded /vendor/lib64/egl/libGLESv1_CM_emulation.so
2022/05/10 21:23:53.308 6445 6463 Debug libEGL loaded /vendor/lib64/egl/libGLESv2_emulation.so
2022/05/10 21:23:53.315 6445 6463 Debug HostConnection createUnique: call
2022/05/10 21:23:53.315 6445 6463 Debug HostConnection HostConnection::get() New Host Connection established 0xb4000078b23a8850, tid 6463
2022/05/10 21:23:53.317 6445 6463 Debug HostConnection HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_vulkan ANDROID_EMU_deferred_vulkan_commands ANDROID_EMU_vulkan_null_optional_strings ANDROID_EMU_vulkan_create_resources_with_requirements ANDROID_EMU_YUV_Cache ANDROID_EMU_vulkan_ignored_handles ANDROID_EMU_has_shared_slots_host_memory_allocator ANDROID_EMU_vulkan_free_memory_sync ANDROID_EMU_vulkan_shader_float16_int8 ANDROID_EMU_vulkan_async_queue_submit ANDROID_EMU_vulkan_queue_submit_with_commands ANDROID_EMU_sync_buffer_data ANDROID_EMU_read_color_buffer_dma GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_gles_max_version_3_0 
2022/05/10 21:23:53.320 6445 6463 Error EGL_emulation eglCreateContext: EGL_BAD_CONFIG: no ES 3.2 support
2022/05/10 21:23:53.320 6445 6463 Error EGL_emulation tid 6463: eglCreateContext(1849): error 0x3005 (EGL_BAD_CONFIG)
2022/05/10 21:23:53.320 6445 6463 Error EGL_emulation eglCreateContext: EGL_BAD_CONFIG: no ES 3.1 support
2022/05/10 21:23:53.320 6445 6463 Error EGL_emulation tid 6463: eglCreateContext(1843): error 0x3005 (EGL_BAD_CONFIG)
2022/05/10 21:23:53.320 6445 6463 Error EGL_emulation [getAttribValue] Bad attribute idx
2022/05/10 21:23:53.320 6445 6463 Debug EGL_emulation eglGetConfigAttrib: bad attrib 0x1
2022/05/10 21:23:53.320 6445 6463 Error EGL_emulation tid 6463: eglGetConfigAttrib(1292): error 0x3004 (EGL_BAD_ATTRIBUTE)
2022/05/10 21:23:53.321 6445 6463 Debug EGL_emulation eglCreateContext: 0xb4000078b23a9f90: maj 3 min 0 rcv 3
2022/05/10 21:23:53.322 6445 6463 Debug EGL_emulation eglCreateContext: 0xb4000078b23a9f90: maj 3 min 0 rcv 3
2022/05/10 21:23:53.323 6445 6463 Debug EGL_emulation eglCreateContext: 0xb4000078b23a9f90: maj 3 min 0 rcv 3
2022/05/10 21:23:53.323 6445 6463 Debug EGL_emulation eglMakeCurrent: 0xb4000078b23a9f90: ver 3 0 (tinfo 0x7acbe70080) (first time)
2022/05/10 21:23:53.325 6445 6463 Debug Unity  GL_EXT_debug_marker GL_EXT_robustness GL_OES_EGL_sync GL_OES_EGL_image GL_OES_EGL_image_external GL_OES_depth24 GL_OES_depth32 GL_OES_element_index_uint GL_OES_texture_float GL_OES_texture_float_linear GL_OES_compressed_paletted_texture GL_OES_compressed_ETC1_RGB8_texture GL_OES_depth_texture GL_OES_texture_npot GL_OES_rgb8_rgba8 GL_EXT_color_buffer_float GL_EXT_color_buffer_half_float GL_EXT_texture_format_BGRA8888 GL_APPLE_texture_format_BGRA8888 ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_vulkan ANDROID_EMU_deferred_vulkan_commands ANDROID_EMU_vulkan_null_optional_strings ANDROID_EMU_vulkan_create_resources_with_requirements ANDROID_EMU_YUV_Cache ANDROID_EMU_vulkan_ignored_handles ANDROID_EMU_has_shared_slots_host_memory_allocator ANDROID_EMU_vulkan_free_memory_sync ANDROID_EMU_vulkan_shader_float16_int8 ANDROID_EMU_vulka
2022/05/10 21:23:53.325 6445 6463 Debug Unity n_async_queue_submit ANDROID_EMU_vulkan_queue_submit_with_commands ANDROID_EMU_sync_buffer_data ANDROID_EMU_read_color_buffer_dma GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_gles_max_version_3_0
2022/05/10 21:23:53.326 6445 6494 Debug HostConnection createUnique: call
2022/05/10 21:23:53.327 6445 6494 Debug HostConnection HostConnection::get() New Host Connection established 0xb4000078b23a9810, tid 6494
2022/05/10 21:23:53.328 6445 6494 Debug HostConnection HostComposition ext ANDROID_EMU_CHECKSUM_HELPER_v1 ANDROID_EMU_native_sync_v2 ANDROID_EMU_native_sync_v3 ANDROID_EMU_native_sync_v4 ANDROID_EMU_dma_v1 ANDROID_EMU_direct_mem ANDROID_EMU_host_composition_v1 ANDROID_EMU_host_composition_v2 ANDROID_EMU_vulkan ANDROID_EMU_deferred_vulkan_commands ANDROID_EMU_vulkan_null_optional_strings ANDROID_EMU_vulkan_create_resources_with_requirements ANDROID_EMU_YUV_Cache ANDROID_EMU_vulkan_ignored_handles ANDROID_EMU_has_shared_slots_host_memory_allocator ANDROID_EMU_vulkan_free_memory_sync ANDROID_EMU_vulkan_shader_float16_int8 ANDROID_EMU_vulkan_async_queue_submit ANDROID_EMU_vulkan_queue_submit_with_commands ANDROID_EMU_sync_buffer_data ANDROID_EMU_read_color_buffer_dma GL_OES_EGL_image_external_essl3 GL_OES_vertex_array_object GL_KHR_texture_compression_astc_ldr ANDROID_EMU_host_side_tracing ANDROID_EMU_gles_max_version_3_0 
2022/05/10 21:23:53.328 6445 6494 Debug EGL_emulation eglMakeCurrent: 0xb4000078b23a9f90: ver 3 0 (tinfo 0x7acbe70100) (first time)
2022/05/10 21:23:53.355 6445 6496 Warn AudioTrack Use of stream types is deprecated for operations other than volume control
2022/05/10 21:23:53.355 6445 6496 Warn AudioTrack See the documentation of AudioTrack() for what to use instead with android.media.AudioAttributes to qualify your playback use case
2022/05/10 21:23:53.376 6445 6463 Verbose MediaRouter Selecting route: RouteInfo{ name=Phone, description=null, status=null, category=RouteCategory{ name=System types=ROUTE_TYPE_LIVE_AUDIO ROUTE_TYPE_LIVE_VIDEO  groupable=false }, supportedTypes=ROUTE_TYPE_LIVE_AUDIO ROUTE_TYPE_LIVE_VIDEO , presentationDisplay=null }
2022/05/10 21:23:53.377 6445 6463 Info MediaRouter Skip setBluetoothA2dpOn(): types=8388615, isPlaybackActive()=true, BT route=null
2022/05/10 21:23:54.487 6445 6494 Debug EGL_emulation app_time_stats: avg=1.77ms min=1.21ms max=6.09ms count=61
2022/05/10 21:23:55.439 6445 6463 Debug CompatibilityChangeReporter Compat change id reported: 147600208; UID 10152; state: ENABLED
2022/05/10 21:23:55.474 6445 6463 Info IL2CPP Locale en-US
2022/05/10 21:23:55.501 6445 6463 Error Unity AndroidJavaException: java.lang.ClassNotFoundException: com.google.android.gms.games.Games
2022/05/10 21:23:55.501 6445 6463 Error Unity java.lang.ClassNotFoundException: com.google.android.gms.games.Games
2022/05/10 21:23:55.501 6445 6463 Error Unity   at java.lang.Class.classForName(Native Method)
2022/05/10 21:23:55.501 6445 6463 Error Unity   at java.lang.Class.forName(Class.java:454)
2022/05/10 21:23:55.501 6445 6463 Error Unity   at com.unity3d.player.UnityPlayer.nativeRender(Native Method)
2022/05/10 21:23:55.501 6445 6463 Error Unity   at com.unity3d.player.UnityPlayer.access$300(Unknown Source:0)
2022/05/10 21:23:55.501 6445 6463 Error Unity   at com.unity3d.player.UnityPlayer$e$1.handleMessage(Unknown Source:83)
2022/05/10 21:23:55.501 6445 6463 Error Unity   at android.os.Handler.dispatchMessage(Handler.java:102)
2022/05/10 21:23:55.501 6445 6463 Error Unity   at android.os.Looper.loopOnce(Looper.java:201)
2022/05/10 21:23:55.501 6445 6463 Error Unity   at android.os.Looper.loop(Looper.java:288)
2022/05/10 21:23:55.501 6445 6463 Error Unity   at com.unity3d.player.UnityPlayer$e.run(Unknown Source:20)
2022/05/10 21:23:55.501 6445 6463 Error Unity Caused by: java.lang.ClassNotFoundException: com.google.android.gms.games.Games
2022/05/10 21:23:55.501 6445 6463 Error Unity   ... 9 more
2022/05/10 21:23:55.501 6445 6463 Error Unity   at UnityEngine.AndroidJNISafe.CheckException () [0x00000] in <00000000000000000000000000000000>:0 
2022/05/10 21:23:55.501 6445 6463 Error Unity   at UnityEngine.AndroidJNISafe.FindClass (System.String name) [0x00000] in <00000000000000000000000000000000>:0 
2022/05/10 21:23:55.501 6445 6463 Error Unity   at UnityEngine.AndroidJavaClass._AndroidJavaClass (Sys
2022/05/10 21:23:55.542 6445 6494 Debug EGL_emulation app_time_stats: avg=3.84ms min=1.25ms max=103.36ms count=57
2022/05/10 21:23:56.567 6445 6494 Debug EGL_emulation app_time_stats: avg=32.75ms min=1.52ms max=39.50ms count=31
2022/05/10 21:23:57.589 6445 6494 Debug EGL_emulation app_time_stats: avg=34.08ms min=30.46ms max=37.20ms count=30
2022/05/10 21:23:58.608 6445 6494 Debug EGL_emulation app_time_stats: avg=33.93ms min=29.50ms max=37.12ms count=30
2022/05/10 21:23:59.610 6445 6494 Debug EGL_emulation app_time_stats: avg=34.56ms min=26.33ms max=39.56ms count=29
2022/05/10 21:24:00.629 6445 6494 Debug EGL_emulation app_time_stats: avg=33.95ms min=31.39ms max=36.52ms count=30
2022/05/10 21:24:01.662 6445 6494 Debug EGL_emulation app_time_stats: avg=34.41ms min=30.46ms max=38.45ms count=30

Found The Reason Seems that GPGS is very very specific in its setup process.找到原因 似乎 GPGS 在其设置过程中非常具体。

just because you have produce all the leaderboards etc you need to publish them... which is thought before it was still available to the testers仅仅因为您已经制作了所有排行榜等,您需要发布它们……这是在测试人员仍然可以使用之前就想到的

So Make sure you所以请确保你

  1. add client ID within Unity在 Unity 中添加客户端 ID
  2. add proguard添加混淆器
  3. Publish and Release the leaderboards in the GoogelPlay Console在 GoogelPlay 控制台中发布和发布排行榜

Then You Can Use Internal Testing and Works Like A Charm.然后您就可以使用内部测试并像魅力一样工作。

Sorry For A Stupidity But Might Help Someone In The Future for one of the many problems setting up GPGS抱歉我的愚蠢,但可能会帮助将来的人解决设置 GPGS 的众多问题之一

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM