I have integrated a google sign in into my application. when I test by USB debugging, it seems to work fine on multiple devices, the google sign in works fine, because the user can access the application. When I create a signed apk, with V1 and V2 signing, nobody can authenticate with the server, not even me, who created the authentication link in the first place.
this is the code responsible for the authentication:
public class MainActivity extends AppCompatActivity implements View.OnClickListener, GoogleApiClient.OnConnectionFailedListener {
private LinearLayout prof_section;
private Button SignOut;
private SignInButton SignIn;
private TextView Name,Email;
private ImageView Prof_Picture;
private Button continueBut;
String personName;
private static final int REQ_CODE = 9001;
String name;
Intent nameSave;
private GoogleApiClient mGoogleApiClient;
public static final String prefsName = "com.personal.mayankthakur.myapplication";
private static final String TAG = "MainActivity";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(com.personal.mayankthakur.myapplication.R.layout.activity_main);
prof_section = (LinearLayout) findViewById(com.personal.mayankthakur.myapplication.R.id.prof_section);
SignOut = (Button) findViewById(com.personal.mayankthakur.myapplication.R.id.logoutBtn);
SignIn = (SignInButton) findViewById(com.personal.mayankthakur.myapplication.R.id.gSignIn);
Name = (TextView) findViewById(com.personal.mayankthakur.myapplication.R.id.nameSpace);
Email = (TextView) findViewById(com.personal.mayankthakur.myapplication.R.id.emailSpace);
Prof_Picture = (ImageView) findViewById(com.personal.mayankthakur.myapplication.R.id.profilePicture);
continueBut = (Button) findViewById(com.personal.mayankthakur.myapplication.R.id.button2);
continueBut.setOnClickListener(this);
SignOut.setOnClickListener(this);
SignIn.setOnClickListener(this) ;
prof_section.setVisibility(View.GONE);
continueBut.setVisibility(View.GONE);
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.build();
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this, this)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
}
@Override
public void onConnectionFailed (@NonNull ConnectionResult connectionResult){
}
private void signIn() {
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
startActivityForResult(signInIntent, REQ_CODE );
}
private void signOut(){
Auth.GoogleSignInApi.signOut(mGoogleApiClient).setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(@NonNull Status status) {
updateUI(false);
}
});
}
private void handleReuslt(GoogleSignInResult result){
if(result.isSuccess())
{
GoogleSignInAccount acct = result.getSignInAccount();
personName = acct.getDisplayName();
// This is the shared preference
SharedPreferences.Editor prefs = getSharedPreferences(prefsName, MODE_PRIVATE).edit();
//adding a value to the preference
prefs.putString("personName", personName);
prefs.apply();
String personEmail = acct.getEmail();
// This is the shared preference
SharedPreferences.Editor emailPrefs = getSharedPreferences(prefsName, MODE_PRIVATE).edit();
//adding a value to the preference
emailPrefs.putString("personEmail", personEmail);
emailPrefs.apply();
String imgUrl = acct.getPhotoUrl().toString();
Uri personPhoto = acct.getPhotoUrl();
Name.setText(personName);
Email.setText(personEmail);
Glide.with(this).load(imgUrl).into(Prof_Picture);
updateUI(true);
}
else
{
updateUI(false);
}
}
private void updateUI(boolean isLogin){
if(isLogin)
{
prof_section.setVisibility(View.VISIBLE);
SignIn.setVisibility(View.GONE);
continueBut.setVisibility(View.VISIBLE);
}
else
{
prof_section.setVisibility(View.GONE);
SignIn.setVisibility(View.VISIBLE);
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == REQ_CODE)
{
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
handleReuslt(result);
}
}
@Override
public void onClick (View v) {
switch (v.getId()) {
case com.personal.mayankthakur.myapplication.R.id.gSignIn:
signIn();
break;
case com.personal.mayankthakur.myapplication.R.id.logoutBtn:
signOut();
break;
case com.personal.mayankthakur.myapplication.R.id.button2:
nameSave = new Intent(MainActivity.this, Activity2.class);
MainActivity.this.startActivity(nameSave);
}
}
}
this is my first time trying to publish an app to google play, and any help would be greatly appreciated!
是您的build variant
debug
因为必须将其设置为release
。
Add the SHA-1 checksum of the release key in the firebase/google console.
First generate key using following command:
keytool -list -v -keystore KEYSTORE_PATH -alias ALIAS_NAME
Then copy the SHA-1 checksum and go to:
Firebase Console > Your project > Settings of the app > Add Fingerprint
Then save the checksum and you are good to go.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.