Ich habe ein Google-Zeichen in meine Anwendung integriert. Wenn ich per USB-Debugging teste, scheint es auf mehreren Geräten gut zu funktionieren, die Google-Anmeldung funktioniert gut, weil der Benutzer auf die Anwendung zugreifen kann. Wenn ich eine signierte Apk mit V1- und V2-Signierung erstelle, kann sich niemand mit dem Server authentifizieren, nicht einmal ich selbst, der den Authentifizierungslink erstellt hat.Google Anmelden funktioniert nicht in Signed APK
Dies ist der Code für die Authentifizierung:
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);
}
}
}
dies ist mein erstes Mal, eine App zu veröffentlichen versuchen, spielen Google, und jede Hilfe wäre sehr dankbar!
Erhalten Sie eine Fehlermeldung auf der Konsole? –
Haben Sie die Release-Key-Store-Signatur zur Entwicklerkonsole hinzugefügt? –