java 登录失败。请检查您的网络连接,然后重试
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26804929/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Failed to sign in. Please check your network connection and try again
提问by Zookey
I am trying to make simple game with Google Play Games Services, but I failed to sign in to Google Play Games.
我正在尝试使用 Google Play 游戏服务制作简单的游戏,但我无法登录 Google Play 游戏。
I get this error:
我收到此错误:
Failed to sign in. Please check your network connection and try again.
登录失败。请检查您的网络连接,然后重试。
I have MainActivity, and three fragmenets (MainFragment, GameFragment and ResultFragment).
我有 MainActivity 和三个片段(MainFragment、GameFragment 和 ResultFragment)。
MainFragment is fragment for main menu, where use have button to click to start the game.
MainFragment 是主菜单的片段,使用有按钮点击开始游戏。
Authorization?
授权?
I have linked and authorized my game with SHA-1 in Google Play Developer Console.
我已在 Google Play Developer Console 中将我的游戏与 SHA-1 关联并授权。
As I use Android Studio my package name looks something like: aplikacijezaandroid.thebuttonchallenge, and I added two app version in linked apps on Google Play Developer Console.
当我使用 Android Studio 时,我的包名称类似于:aplikacijezaandroid.thebuttonchallenge,并且我在 Google Play Developer Console 上的链接应用程序中添加了两个应用程序版本。
So I have com.aplikacijezaandroid.thebuttonchallenge, and aplikacijezaandorid.thebuttonchallenge
所以我有 com.aplikacijezaandroid.thebuttonchallenge 和 aplikacijezaandorid.thebuttonchallenge
App ID?
应用程序标识?
I added app id, and leaderboard id into strings.xml and I added meta tag to Android Manifest.
我将应用程序 ID 和排行榜 ID 添加到 strings.xml 中,并将元标记添加到 Android Manifest。
I have added Internet permission in AndroidManifest.xml
我在 AndroidManifest.xml 中添加了 Internet 权限
Testing?
测试?
I test and debug app from Android Studio with physical device and ofc there is my own gmail added as test user in Google Play Developer Console.
我使用物理设备从 Android Studio 测试和调试应用程序,并且在 Google Play Developer Console 中添加了我自己的 gmail 作为测试用户。
Here is my AndroidManifest.xml
这是我的AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="aplikacijezaandroid.thebuttonchallenge" >
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data android:name="com.google.android.gms.games.APP_ID" android:value="@string/app_id"/>
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version"/>
</application>
Here is MainActivityclass:
这是MainActivity类:
public class MainActivity extends Activity implements MainMenuFragment.Listener,
GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener,
GameFragment.Listener, ResultFragment.Listener {
//Fragments
MainMenuFragment mMainFragment;
GameFragment mGameFragment;
ResultFragment mResultFragment;
// Client used to interact with Google APIs
private GoogleApiClient mGoogleApiClient;
// Are we currently resolving a connection failure?
private boolean mResolvingConnectionFailure = false;
// Has the user clicked the sign-in button?
private boolean mSignInClicked = false;
// Automatically start the sign-in flow when the Activity starts
private boolean mAutoStartSignInFlow = true;
// request codes we use when invoking an external activity
private static final int RC_RESOLVE = 5000;
private static final int RC_UNUSED = 5001;
private static final int RC_SIGN_IN = 9001;
//Debug
private String TAG = "IGRA";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Create the Google API Client with access to Plus and Games
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Plus.API).addScope(Plus.SCOPE_PLUS_LOGIN)
.addApi(Games.API).addScope(Games.SCOPE_GAMES)
.build();
//Fragments
mMainFragment = new MainMenuFragment();
mGameFragment = new GameFragment();
mResultFragment = new ResultFragment();
// listen to fragment events
mMainFragment.setListener(this);
mGameFragment.setListener(this);
mResultFragment.setListener(this);
//Treba dodati listenere
// add initial fragment (welcome fragment)
if (savedInstanceState == null) {
getFragmentManager().beginTransaction().add(R.id.container, mMainFragment).commit();
}
}
// Switch UI to the given fragment
void switchToFragment(Fragment newFrag) {
getFragmentManager().beginTransaction().replace(R.id.container, newFrag)
.commit();
}
private boolean isSignedIn() {
return (mGoogleApiClient != null && mGoogleApiClient.isConnected());
}
@Override
protected void onStart() {
super.onStart();
Log.d(TAG, "onStart(): connecting");
mGoogleApiClient.connect();
}
@Override
protected void onStop() {
super.onStop();
Log.d(TAG, "onStop(): disconnecting");
if (mGoogleApiClient.isConnected()) {
mGoogleApiClient.disconnect();
}
}
@Override
public void onStartGameRequested() {
startGame();
}
@Override
public void onShowAchievementsRequested() {
}
@Override
public void onShowLeaderboardsRequested() {
}
void startGame(){
switchToFragment(mGameFragment);
}
public void onEnteredScore(int finalScore){
mResultFragment.setFinalScore(finalScore);
// push those accomplishments to the cloud, if signed in
pushAccomplishments(finalScore);
// switch to the exciting "you won" screen
switchToFragment(mResultFragment);
}
private void pushAccomplishments(int finalScore) {
if (!isSignedIn()) {
// can't push to the cloud, so save locally
// mOutbox.saveLocal(this);
Log.d(TAG, "can't push to the cloud, so save locally");
return;
}
Games.Leaderboards.submitScore(mGoogleApiClient, getString(R.string.number_guesses_leaderboard),
finalScore);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onConnected(Bundle bundle) {
Log.d(TAG, "onConnected(): connected to Google APIs");
// Show sign-out button on main menu
//mMainFragment.setShowSignInButton(false);
// Show "you are signed in" message on win screen, with no sign in button.
//mWinFragment.setShowSignInButton(false);
// Set the greeting appropriately on main menu
Player p = Games.Players.getCurrentPlayer(mGoogleApiClient);
String displayName;
if (p == null) {
Log.w(TAG, "mGamesClient.getCurrentPlayer() is NULL!");
displayName = "???";
} else {
displayName = p.getDisplayName();
}
mMainFragment.setGreeting("Hello, " + displayName);
// if we have accomplishments to push, push them
/*if (!mOutbox.isEmpty()) {
pushAccomplishments();
Toast.makeText(this, getString(R.string.your_progress_will_be_uploaded),
Toast.LENGTH_LONG).show();
}*/
}
@Override
public void onWinScreenDismissed() {
switchToFragment(mMainFragment);
}
@Override
public void onWinScreenSignInClicked() {
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
if (requestCode == RC_SIGN_IN) {
mSignInClicked = false;
mResolvingConnectionFailure = false;
if (resultCode == RESULT_OK) {
mGoogleApiClient.connect();
} else {
BaseGameUtils.showActivityResultError(this, requestCode, resultCode,
R.string.signin_failure, R.string.signin_other_error);
}
}
}
@Override
public void onConnectionSuspended(int i) {
Log.d(TAG, "onConnectionSuspended(): attempting to connect");
mGoogleApiClient.connect();
}
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
Log.d(TAG, "onConnectionFailed(): attempting to resolve");
if (mResolvingConnectionFailure) {
Log.d(TAG, "onConnectionFailed(): already resolving");
return;
}
if (mSignInClicked || mAutoStartSignInFlow) {
mAutoStartSignInFlow = false;
mSignInClicked = false;
mResolvingConnectionFailure = true;
if (!BaseGameUtils.resolveConnectionFailure(this, mGoogleApiClient, connectionResult,
RC_SIGN_IN, getString(R.string.signin_other_error))) {
mResolvingConnectionFailure = false;
}
}
// Sign-in failed, so show sign-in button on main menu
mMainFragment.setGreeting(getString(R.string.signed_out_greeting));
//mMainMenuFragment.setShowSignInButton(true);
// mWinFragment.setShowSignInButton(true);
}
采纳答案by Zookey
I have solved this problem, so I will post the answer.
我已经解决了这个问题,所以我会发布答案。
I have moved app id and leaderboard id from strings.xml to ids.xml in values folder.
我已将应用程序 id 和排行榜 id 从 strings.xml 移动到 values 文件夹中的 ids.xml。
I have deleted all client ids and add again client ids for debug keystore and release keystore.
我已经删除了所有客户端 ID,并再次添加了用于调试密钥库和发布密钥库的客户端 ID。
回答by AnEnthusiast
If you haven't published your app/game: After you done every usual step, make sure you test your app/game with a device has only the test account/s. I checked every step a few times and ended with this weird problem. Lastly i tested my app with a device has only test account i added on Developer Console. It worked. Hope, this helps someone else.
如果您尚未发布您的应用/游戏:在您完成所有常规步骤后,请确保您使用只有测试帐户的设备测试您的应用/游戏。我检查了每一步几次,并以这个奇怪的问题结束。最后,我使用设备测试了我的应用程序,该设备只有我在开发人员控制台上添加的测试帐户。有效。希望,这对其他人有帮助。
回答by Mohammad Khan
In my case the problem was one of gmail accounts (out of two) was not added to the testers accounts at the play store and was the default account for my device.
在我的情况下,问题是其中一个 gmail 帐户(两个)没有添加到 Play 商店的测试人员帐户中,并且是我设备的默认帐户。
I removed the account to make the other account (testers account at playstore) default and added it back again, and it started working
我删除了该帐户以使另一个帐户(Playstore 的测试人员帐户)成为默认帐户,然后重新添加它,然后它开始工作
回答by user8355469
In my case,I only add a release client ID in Google Play Console. When I run my app by click button RUN in AS,the network connection error show.But when I run the apk generated by the signed,it work well. So, add a debug client id if you want to run your app inside AS.
就我而言,我只在 Google Play 控制台中添加了一个发布客户端 ID。当我通过在 AS 中单击按钮 RUN 运行我的应用程序时,显示网络连接错误。但是当我运行签名生成的 apk 时,它运行良好。因此,如果您想在 AS 内运行您的应用程序,请添加调试客户端 ID。
回答by Chee Jit Lim
For me its that my project SHA1 is not the same as what is in the API console.
1. I've checked mine through this.
2. Went to https://console.developers.google.comand into the "Credentials" page of my project.
3. Clicked on the edit button (the pencil icon) and pasted over the SHA1
4. Worked within <2 minutes
对我来说,我的项目 SHA1 与 API 控制台中的项目不同。
1. 我已经通过这个检查了我的。
2. 转到https://console.developers.google.com并进入我项目的“凭据”页面。
3. 单击编辑按钮(铅笔图标)并粘贴到 SHA1 上
4. 在 <2 分钟内完成
回答by Yongjiang Geng
In my case.I setted one test account,but my device has an default account which is another,that's why I got this error.My mistake but Why can't google gives us an more obvious error report?
就我而言。我设置了一个测试帐户,但我的设备有一个默认帐户,这是另一个,这就是我收到此错误的原因。我的错误,但为什么谷歌不能给我们更明显的错误报告?
Here is how I worked this out.All my test was under debug version using test account. I delete the project, both in google play develper console and google Api console.And recreate one as mentioned by others on stackoverflow.But this does't help.I redo this and ends up in vane.
这是我如何解决这个问题的。我的所有测试都是使用测试帐户在调试版本下进行的。我在 google play develper 控制台和 google Api 控制台中删除了该项目。并按照其他人在 stackoverflow 上提到的方式重新创建了一个项目。但这没有帮助。我重做此操作并以风向标告终。
I cheked found in log these same words:
我在日志中发现了这些相同的词:
03-09 16:15:39.897: E/GameAgent(1225): Unable to retrieve application xxxxxxx from network 03-09 16:15:39.902: E/GameAgent(1225): Application ID xxxxxxx is not associated with package com.gyj.pub.gpgsDemo. Check the application ID in your manifest. 03-09 16:15:39.906: E/CheckGameplayAcl(23917): Unable to load metadata for game 03-09 16:15:39.906: W/SignInActivity(23917): onSignInFailed()...
03-09 16:15:39.897:E/GameAgent(1225):无法从网络检索应用程序 xxxxxxx 03-09 16:15:39.902:E/GameAgent(1225):应用程序 ID xxxxxxx 与包 com.gyj 无关.pub.gpgsDemo。检查清单中的应用程序 ID。03-09 16:15:39.906: E/CheckGameplayAcl(23917): 无法加载游戏的元数据 03-09 16:15:39.906: W/SignInActivity(23917): onSignInFailed()...
one more,I checked all the 3 elements below ,decide whether the client apk is conform with Google Play Deverloper Console's configuration. 1.package name .It is all the same. 2.Certification SHA1 fingerprint.(debug and release). 3.test Account.
另外,我检查了以下所有 3 个元素,确定客户端 apk 是否符合 Google Play Deverloper Console 的配置。1.包名。都是一样的。2.认证SHA1指纹。(调试和发布)。3.测试账户。
Even at that time I did not realize that I haven't input an account during my tests,How does the device know which account is attend to sign in? I tried an other account.I added this account which has setted in sonsole as Test Account to the device,relaughched the TypeANumber app.It showed me a view to choose one from the two accounts.Suddently I got it.
即使当时我也没有意识到我在测试时没有输入帐户,设备如何知道是哪个帐户正在登录?我尝试了另一个帐户。我将这个在sonsole中设置为测试帐户的帐户添加到设备中,重新启动TypeANumber应用程序。它向我展示了从两个帐户中选择一个的视图。突然我得到了它。