好吧一切正常,直到我生成签名的apk.我在谷歌开发者页面上讲述了整个过程
1.我生成了带有keyhash和包名称的Google-services.Json文件
2.包括所有类级别和应用程序级别的依赖关系
// 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文件
apply plugin: 'com.androID.application'apply plugin: 'com.Google.gms.Google-services'androID {compileSdkVersion 23buildToolsversion "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'}
>我的登录java代码
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(); } }}
>我的布局代码
<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.
如果是这种情况,请尝试以下 *** 作obtain the release SHA1 from the keystore并将旧的SHA替换为.
1.打开终端并将目录更改为JDK bin目录.在路径中包含已安装的JDK版本,对我来说是 – jdk1.8.0_101(输入javac -version来获取Java版本):
苹果电脑
cd /library/Java/JavaVirtualMachines/<your_JDK_version>.jdk/Contents/Home/bin
视窗
cd C:\Program files\Java\your_JDK_version\bin
2.使用keytool获取版本SHA1:
keytool -List -v -keystore <keystore_name> -alias <alias_name>
3.转到project’s credentials page并将SHA1替换为密钥库的版本SHA1.
总结以上是内存溢出为你收集整理的java – 谷歌登录签名apk无法正常工作全部内容,希望文章能够帮你解决java – 谷歌登录签名apk无法正常工作所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)