-2

我正在使用Firebase身份驗證實施Google Signin。我使用了樣本代碼。我的應用程序在調試時工作得非常好,當我使用USB電纜將真實的Android設備連接到PC時,但當我共享簽名的APK時,應用程序未安裝。如何在Android中實現Firebase Google登錄?

權限

<uses-permission android:name="android.permission.INTERNET"/> 
<!-- USE_CREDENTIALS is necessary for Google+ login --> 
<uses-permission android:name="android.permission.USE_CREDENTIALS" /> 
<!-- GET_ACCOUNTS is necessary to display email address of logged in user. This permission is optional --> 
<uses-permission android:name="android.permission.GET_ACCOUNTS" /> 

安裝我的應用程序時,它是說這個應用程序並不需要特別的許可,但是。

主要活動

GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) 
      .requestIdToken(getString(R.string.default_web_client_id)) 
      .requestEmail() 
      .build(); 
    // [END config_signin] 

    mGoogleApiClient = new GoogleApiClient.Builder(this) 
      .enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */) 
      .addApi(Auth.GOOGLE_SIGN_IN_API, gso) 
      .build(); 

    // [START initialize_auth] 
    mAuth = FirebaseAuth.getInstance(); 
    // [END initialize_auth] 

    // [START auth_state_listener] 
    mAuthListener = new FirebaseAuth.AuthStateListener() { 
     @Override 
     public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) { 
      FirebaseUser user = firebaseAuth.getCurrentUser(); 
      if (user != null) { 
       // User is signed in 
       Log.d(TAG, "onAuthStateChanged:signed_in:" + user.getUid()); 
      } else { 
       // User is signed out 
       Log.d(TAG, "onAuthStateChanged:signed_out"); 
      } 
      // [START_EXCLUDE] 
      updateUI(user); 
      // [END_EXCLUDE] 
     } 
    }; 

public void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 

    // Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...); 
    if (requestCode == RC_SIGN_IN) { 
     GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data); 
     if (result.isSuccess()) { 
      // Google Sign In was successful, authenticate with Firebase 
      GoogleSignInAccount account = result.getSignInAccount(); 
      firebaseAuthWithGoogle(account); 
     } else { 
      // Google Sign In failed, update UI appropriately 
      // [START_EXCLUDE] 
      updateUI(null); 
      // [END_EXCLUDE] 
     } 
    } 
} 

private void firebaseAuthWithGoogle(GoogleSignInAccount acct) { 
    Log.d(TAG, "firebaseAuthWithGoogle:" + acct.getId()); 
    // [START_EXCLUDE silent] 
    showProgressDialog(); 
    // [END_EXCLUDE] 

    AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null); 
    mAuth.signInWithCredential(credential) 
      .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { 
       @Override 
       public void onComplete(@NonNull Task<AuthResult> task) { 
        Log.d(TAG, "signInWithCredential:onComplete:" + task.isSuccessful()); 

        // If sign in fails, display a message to the user. If sign in succeeds 
        // the auth state listener will be notified and logic to handle the 
        // signed in user can be handled in the listener. 
        if (!task.isSuccessful()) { 
         Log.w(TAG, "signInWithCredential", task.getException()); 
         Toast.makeText(getApplicationContext(), "Authentication failed.", 
           Toast.LENGTH_SHORT).show(); 
        } 
        // [START_EXCLUDE] 
        hideProgressDialog(); 
        // [END_EXCLUDE] 
       } 
      }); 
} 

private void signIn() { 
    Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient); 
    startActivityForResult(signInIntent, RC_SIGN_IN); 
} 
+0

你可以確認沒有調試安裝在你試圖安裝簽名的apk相同的設備? –

+0

@ChintanSoni是的,在生成apk後我已經卸載了應用程序。並郵寄我自己的apk。 –

回答

0

卸載從保持在手集中的所有用戶以前。當手機中有多個用戶帳戶時,即使您拖放應用程序圖標以將其卸載,它也不會從所有用戶中卸載該應用程序,也就是說爲什麼它可能不會安裝新的APK。

要卸載的應用

  1. 進入設置
  2. 轉到應用板塊
  3. 你會發現你的應用程序仍然存在於應用程序列表中,單擊它
  4. 點擊菜單和你會爲所有用戶找到一個卸載選項。點擊它並享受
+0

@Aniket no yaar。它沒有顯示在應用程序部分,這意味着它沒有安裝,我無法安裝新的apk。我認爲這不是問題 –

2

當您簽署APK時,請確保您同時勾選v1和v2簽名版本。

+0

感謝兄弟它解決了這個問題 –

+0

嗨兄弟,如果它幫助請接受並upvote我的答案。 –

2

您必須在創建簽名apk的同時選擇v1和v2簽名版本。 ,如果這不起作用,那麼你應該看到這個,parsing error in signed apk