-2

I'm implementing Google Signin using Firebase authentication. I have used code from samples. My app is working perfectly fine while debugging that is when I had connected my real Android device to PC using USB cable but when I am sharing my signed APK, the app is not getting installed.

Permission

<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" />

But when installing my app it is saying this app does not require special permission.

Main Activity

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);
}
halfer
  • 19,824
  • 17
  • 99
  • 186
vishal gupta
  • 377
  • 2
  • 5
  • 17

3 Answers3

3

When you are signing the APK , make sure you tick both v1 and v2 signature versions.

Dishonered
  • 8,449
  • 9
  • 37
  • 50
2

you have to select both v1 and v2 signature versions while creating a signed apk. and if that's not working then you should see this, parsing error in signed apk

Community
  • 1
  • 1
Sam
  • 171
  • 1
  • 11
0

Uninstall the previous from all users maintained in the hand set. When you have multiple user accounts in your phone, even if you drag and drop the app icon to uninstall it, it won't uninstall the app from all users, i.e. why it might not installing a fresh APK.

To uninstall the app

  1. Go to Settings
  2. Go to App Section
  3. you may find your app still present in the app list, click on it
  4. Click on menu and you will find an option to uninstall for all users. Click on it and Enjoy
Ankit Gupta
  • 674
  • 1
  • 6
  • 17
  • @Aniket no yaar. It is not showing in app section that means it is not installed and i m not able to install new apk. I think this is not a problem – vishal gupta May 01 '17 at 06:36