Google 登录签名的 apk 不起作用 [英] Google sign in signed apk not working

查看:23
本文介绍了Google 登录签名的 apk 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一切正常,直到我生成签名的 apk .我按照谷歌开发者页面上的说明进行了整个过程

Well all works till i generate the signed apk . I followed the entire process as told on the google developers page

1.我生成了带有keyhash和包名的google-services.json文件
2.像这样包含所有的类级别和应用级别的依赖

1.I generated the google-services.json file with keyhash and package name in it
2.Included all the class level and application level dependencies like this

// Top-level build file where you can add configuration options common to all sub-projects/modules.

 buildscript {
repositories {
    jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle:1.3.0'
    classpath 'com.google.gms:google-services:2.0.0-alpha6'

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}
}
 allprojects {
  repositories {
     jcenter()
   }
  }

应用程序gradle文件

Application gradle file

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'

android {
compileSdkVersion 23
buildToolsVersion "23.0.0"

defaultConfig {
    applicationId "com.example.skmishra.finalgooglesignin"
    minSdkVersion 14
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'),          'proguard-rules.pro'
    }
   }
}

 dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.google.android.gms:play-services:8.3.0'


}

  1. 我的登录java代码

  1. My Sign In java Code

package com.example.skmishra.finalgooglesignin;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.google.android.gms.auth.api.Auth;
import com.google.android.gms.auth.api.signin.GoogleSignInAccount;
import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
import com.google.android.gms.auth.api.signin.GoogleSignInResult;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.SignInButton;
import com.google.android.gms.common.api.GoogleApiClient;

public class MainActivity extends AppCompatActivity implements GoogleApiClient.OnConnectionFailedListener, View.OnClickListener {

    private static final int RC_SIGN_IN = 200 ;
    private static final String TAG = "Sign In" ;
    private GoogleApiClient mGoogleApiClient;
   SignInButton google;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        // Configure sign-in to request the user's ID, email address, and basic
// profile. ID and basic profile are included in DEFAULT_SIGN_IN.
        GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                .requestEmail()
                .build();
        mGoogleApiClient = new GoogleApiClient.Builder(this)
                .enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
                .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
                .build();
        SignInButton signInButton = (SignInButton) findViewById(R.id.sign_in_button);
        signInButton.setSize(SignInButton.SIZE_STANDARD);
        signInButton.setScopes(gso.getScopeArray());
        google=(SignInButton)findViewById(R.id.sign_in_button);
        google.setOnClickListener(this);


    }


    @Override
    public void onConnectionFailed(ConnectionResult connectionResult) {
        Toast.makeText(this,"Failed to connect",Toast.LENGTH_LONG).show();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.sign_in_button:
                signIn();
                break;
            // ...
        }
    }

    private void signIn() {
        Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
        startActivityForResult(signInIntent, RC_SIGN_IN);
    }
    @Override
    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);
            handleSignInResult(result);
        }
    }

    private void handleSignInResult(GoogleSignInResult result) {
        Log.d(TAG, "handleSignInResult:" + result.isSuccess());
        if (result.isSuccess()) {
            // Signed in successfully, show authenticated UI.
            GoogleSignInAccount acct = result.getSignInAccount();
            Toast.makeText(this,"Name :"+acct.getDisplayName()+" Email :"+acct.getEmail(),Toast.LENGTH_LONG).show();
        } else {
            // Signed out, show unauthenticated UI.
            Toast.makeText(this,"Signed out ",Toast.LENGTH_LONG).show();
        }
    }
}

  1. 我的布局代码

  1. My layout code

    <com.google.android.gms.common.SignInButton
        android:id="@+id/sign_in_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Check this out"

        />

推荐答案

据我所知,您已经在开发者控制台中提供了调试 SHA1,然后你签署了 apk 并且 SHA1 改变了.如果是这种情况,请尝试以下操作,您应该获取发布 SHA1 并用它替换旧的 SHA.

As I understand, you have provided the debug SHA1 in the developer console, then you signed the apk and the SHA1 changed. If this is the case try the following you should obtain the release SHA1 from the keystore and replace the old SHA with that.

1. 打开终端并将目录更改为 JDK bin 目录.在路径中包含您安装的 JDK 版本,对我来说是 - jdk1.8.0_101(输入 javac -version 以获取 Java 版本):

1. Open terminal and change the directory to JDK bin directory. Include your installed JDK version inside the path, for me it was - jdk1.8.0_101 (type javac -version to get the Java version) :

Mac

    cd /Library/Java/JavaVirtualMachines/<your_JDK_version>.jdk/Contents/Home/bin

Windows

    cd C:Program FilesJavayour_JDK_versionin 

2. 使用 keytool 获取发布 SHA1 :

2. Use keytool to obtain the release SHA1 :

    keytool -list -v -keystore <keystore_name> -alias <alias_name>

3. 转到您的项目的凭据页面 并将 SHA1 替换为您的密钥库的发行版 SHA1.

3. Go to your project's credentials page and replace the SHA1 to your keystore's release SHA1.

这篇关于Google 登录签名的 apk 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆