0

When I disable the proguard in Android, Firebase Google Sign in works properly, but when I enable it, it won't works only when I signed bundle apk. In normal debug, it works. My Google Sign in code is here

package com.example.dhop.Activity; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity; import android.content.DialogInterface; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.util.Log; import android.view.View;

import android.widget.Button; import android.widget.ImageView; import android.widget.ProgressBar;

import android.widget.TextView; import android.widget.Toast; import com.example.dhop.ModelClass.UpdateHelper; import com.example.dhop.R; import com.google.android.gms.auth.api.signin.GoogleSignIn; import com.google.android.gms.auth.api.signin.GoogleSignInAccount; import com.google.android.gms.auth.api.signin.GoogleSignInClient; import com.google.android.gms.auth.api.signin.GoogleSignInOptions; import com.google.android.gms.common.api.ApiException;

import com.google.android.gms.tasks.Task; import com.google.firebase.auth.AuthCredential; import com.google.firebase.auth.FirebaseAuth;

import com.google.firebase.auth.FirebaseUser; import com.google.firebase.auth.GoogleAuthProvider; import com.squareup.picasso.Picasso;

public class MainActivity extends AppCompatActivity { static final int GOOGLE_SIGN_IN = 123; FirebaseAuth mAuth;

Button btn_login, btn_logout; TextView text; ImageView image;

ProgressBar progressBar; GoogleSignInClient mGoogleSignInClient; @Override

protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);

btn_login = findViewById(R.id.login); btn_logout = findViewById(R.id.logout); text = findViewById(R.id.text); image = findViewById(R.id.image); progressBar = findViewById(R.id.progress_circular); mAuth = FirebaseAuth.getInstance();

GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestIdToken(getString(R.string.default_web_client_id))

.requestEmail() .build(); mGoogleSignInClient = GoogleSignIn.getClient(this, gso);

btn_login.setOnClickListener(v -> SignInGoogle()); btn_logout.setOnClickListener(v -> Logout()); if (mAuth.getCurrentUser() != null) {

FirebaseUser user = mAuth.getCurrentUser(); updateUI(user); } }

public void SignInGoogle() { progressBar.setVisibility(View.VISIBLE); Intent signInIntent = mGoogleSignInClient.getSignInIntent();

startActivityForResult(signInIntent, GOOGLE_SIGN_IN); } private void firebaseAuthWithGoogle(GoogleSignInAccount acct) { Log.d("TAG", "firebaseAuthWithGoogle:" + acct.getId());

AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null); mAuth.signInWithCredential(credential) .addOnCompleteListener(this, task -> { if (task.isSuccessful()) { progressBar.setVisibility(View.INVISIBLE);

Log.d("TAG", "signInWithCredential:success"); FirebaseUser user = mAuth.getCurrentUser(); updateUI(user);

} else { progressBar.setVisibility(View.INVISIBLE); Log.w("TAG", "signInWithCredential:failure",

task.getException()); Toast.makeText(MainActivity.this, "Authentication failed.",

Toast.LENGTH_SHORT).show(); updateUI(null); } }); }

@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data);

if (requestCode == GOOGLE_SIGN_IN) { Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);

try { GoogleSignInAccount account = task.getResult(ApiException.class);

` if (account != null) firebaseAuthWithGoogle(account); } catch (ApiException e) { Log.w("TAG", "Google sign in failed", e); } } }

`

private void updateUI(FirebaseUser user) { if (mAuth.getCurrentUser() != null) { Intent intent = new Intent(MainActivity.this, ` MainNavActivity.class); startActivity(intent); finish(); } else {

`

text.setText("Firebase Login \n"); Picasso.get().load(R.drawable.ic_firebase_logo).into(image); image.setVisibility(View.VISIBLE);

btn_logout.setVisibility(View.INVISIBLE); btn_login.setVisibility(View.VISIBLE); } }

private void Logout() { FirebaseAuth.getInstance().signOut(); mGoogleSignInClient.signOut().addOnCompleteListener(this,

task -> updateUI(null)); }

  • post your proguard file. – Lingeshwaran Jul 25 '19 at 08:38
  • Possible duplicate of [What ProGuard configuration do I need for Firebase on Android?](https://stackoverflow.com/questions/26273929/what-proguard-configuration-do-i-need-for-firebase-on-android) – Lingeshwaran Jul 25 '19 at 08:41
  • # Add project specific ProGuard rules here. # You can control the set of applied configuration files using the # proguardFiles setting in build.gradle. # For more details, see # http://developer.android.com/guide/developing/tools/proguard.html # If your project uses WebView with JS, uncomment the following # and specify the fully qualified class name to the JavaScript interface # class: #-keepclassmembers class fqcn.of.javascript.interface.for.webview { # public *; #} # Uncomment this to preserve the line number information for # debugging stack traces. All default thigs – Sanchyan Chakraborty Jul 25 '19 at 09:20
  • Can I encript only which file I want. In default all files are encrypted or locked. Can I write any code that only lock that particular class. This will be helpful. Cause I'm unable to find out for which class google sigin in method stops working ! – Sanchyan Chakraborty Jul 25 '19 at 09:22
  • see this answer https://stackoverflow.com/questions/26273929/what-proguard-configuration-do-i-need-for-firebase-on-android#answer-26274623 – Lingeshwaran Jul 25 '19 at 09:25
  • @Lingeshwaran -keep class com.google.android.gms.auth.api.signin.GoogleSignInClient.** { *; } -keep class com.google.android.gms.common.api.GoogleApi.** { *; } -keep class com.google.firebase.auth.GoogleSignInClient.** { *; } -keep class * extends com.example.dhop.Activity.MainActivity.** { *; } -keep class com.firebase.** { *; } -keep class org.apache.** { *; } -keepnames class com.fasterxml.jackson.** { *; } -keepnames class javax.servlet.** { *; } -keepnames class org.ietf.jgss.** { *; } -dontwarn org.apache.** -dontwarn org.w3c.dom.** Add this. Won't work – Sanchyan Chakraborty Jul 25 '19 at 09:46
  • I think my updateUI sytem won't work. How can I keep it from proguard ? – Sanchyan Chakraborty Jul 25 '19 at 09:46
  • -keep com.example.dhop.Activity.MainActivity { updateUI; } I'm getting error of this line. This orientation is wrong ? – Sanchyan Chakraborty Jul 25 '19 at 09:48
  • How to keep a method in a class in proguard ? – Sanchyan Chakraborty Jul 25 '19 at 09:51
  • My problem not solved yet ! – Sanchyan Chakraborty Jul 25 '19 at 10:02

0 Answers0