我正在尝试在我的应用中使用 Google Play 游戏。我已经使用这个库https://github.com/isrmicha/react-native-google-play-game-services-workaround进行了登录
但是这个库没有实现检索播放器的方法只是为了检索 player.id 所以我尝试了以下两种方法
public void getUser(String id, final Promise promise) {
mPlayersClient. loadPlayer(id).addOnCompleteListener(getCurrentActivity(),
new OnCompleteListener<AnnotatedData<Player>>() {
@Override
public void onComplete(@NonNull Task<AnnotatedData<Player>> task) {
if (task.isSuccessful()) {
promise.resolve(task.getResult().get());
} else {
promise.reject("Get ID failed");
}
}
}
);
}
@ReactMethod
public void getUser(final Promise promise) {
mPlayersClient.getCurrentPlayer().addOnCompleteListener(getCurrentActivity(),
new OnCompleteListener<Player>() {
@Override
public void onComplete(@NonNull Task<Player> task) {
if (task.isSuccessful()) {
promise.resolve(task.getResult());
} else {
promise.reject("Get ID failed");
}
}
}
);
}
两者都不起作用,我收到以下错误
08-25 19:56:22.518 6805 6805 E AndroidRuntime: java.lang.RuntimeException: Cannot convert argument of type class com.google.android.gms.games.PlayerEntity
08-25 19:56:22.518 6805 6805 E AndroidRuntime: at com.facebook.react.bridge.Arguments.fromJavaArgs(Arguments.java:187)
08-25 19:56:22.518 6805 6805 E AndroidRuntime: at com.facebook.react.bridge.CallbackImpl.invoke(CallbackImpl.java:31)
08-25 19:56:22.518 6805 6805 E AndroidRuntime: at com.facebook.react.bridge.PromiseImpl.resolve(PromiseImpl.java:56)
08-25 19:56:22.518 6805 6805 E AndroidRuntime: at com.shokimble.rngoogleplaygameservices.RNGooglePlayGameServicesModule$5.onComplete(RNGooglePlayGameServicesModule.java:266)
08-25 19:56:22.518 6805 6805 E AndroidRuntime: at com.google.android.gms.tasks.zzj.run(com.google.android.gms:play-services-tasks@@17.2.0:4)
08-25 19:56:22.518 6805 6805 E AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:938)
08-25 19:56:22.518 6805 6805 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:99)
08-25 19:56:22.518 6805 6805 E AndroidRuntime: at android.os.Looper.loop(Looper.java:223)
08-25 19:56:22.518 6805 6805 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:7656)
08-25 19:56:22.518 6805 6805 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
08-25 19:56:22.518 6805 6805 E AndroidRuntime: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
08-25 19:56:22.518 6805 6805 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
我已经尝试过更改Task<Player>
和OnCompleteListener<Player>
for Task<PlayerEntity>
,OnCompleteListener<PlayerEntity>
但是当我这样做时它会停止编译。
我正在执行这些版本
implementation 'com.google.android.gms:play-services-games:17.+'
implementation 'com.google.android.gms:play-services-auth:19.+'