Google+登录集成崩溃了Android应用程序

时间:2014-08-12 16:47:48

标签: android

我正在将Google+登录集成集成到我的Android应用程序中。我正在学习本教程。 http://www.androidhive.info/2014/02/android-login-with-google-plus-account-1/ 我按照每一步,但当我在我的Android设备上运行应用程序时,应用程序在启动屏幕后崩溃。

Log cat在应用程序中显示没有错误,但在Google Play服务库中显示错误。这是Log cat

08-12 20:33:11.091: I/Icing(1980): Storage manager: low false usage 1.76MB avail 142.75MB capacity 0.94GB
08-12 20:33:12.651: E/Icing(1980): Array storage bad crc 2710746905 vs 2358592732
08-12 20:33:12.691: E/Icing(1980): Array storage bad crc 4278960758 vs 0
08-12 20:33:13.381: E/Icing(1980): Array storage bad crc 1590354048 vs 4192529010
08-12 20:33:13.381: E/Icing(1980): Trie mmap next failed
08-12 20:33:14.001: W/Icing(1980): Docstore bad crc 0x691d1876 vs 0x6e27403b
08-12 20:33:15.511: E/Icing(1980): Array storage bad crc 2034485993 vs 0
08-12 20:33:15.511: E/Icing(1980): Trie mmap node failed
08-12 20:33:15.891: W/Icing(1980): Error while loading LangUtil; unable to load Cld2DetectLanguage: undefined symbol: IcingExtCld2DetectLanguage
08-12 20:33:16.571: I/Icing(1980): updateResources: need to parse gfv{com.google.android.gms}
08-12 20:33:16.991: I/Icing(1980): Not enough disk space for indexing trimmable
08-12 20:33:16.991: I/Icing(1980): Internal init done: storage state 1
08-12 20:33:17.151: I/Icing(1980): 3 corpora need re-polling
08-12 20:33:17.251: I/Icing(1980): Post-init done
08-12 20:33:17.261: I/Icing(1980): doRemovePackageData com.umonistudio.tile
08-12 20:33:18.231: I/Icing(1980): Indexing FDBA7D5375B5D790F9C439EE9076658C1D1E8126 from com.google.android.googlequicksearchbox 
08-12 20:33:18.261: I/Icing(1980): Indexing 1163DB23413769866189369CD48BB8356F823578 from com.google.android.gm
08-12 20:33:18.271: I/Icing(1980): Indexing 427C1771ABBC521123604E224408F07F2376CCFA from com.google.android.googlequicksearchbox
08-12 20:33:18.311: I/Icing(1980): Not enough disk space for indexing trimmable 
08-12 20:33:18.351: I/Icing(1980): Indexing done FDBA7D5375B5D790F9C439EE9076658C1D1E8126
08-12 20:33:18.361: I/Icing(1980): Not enough disk space for indexing trimmable
08-12 20:33:18.361: I/Icing(1980): Cannot sync trimmable corpus: no trimmable
08-12 20:33:18.361: E/Icing(1980): Aborting indexing of corpus 1163DB23413769866189369CD48BB8356F823578
08-12 20:33:18.361: I/Icing(1980): Indexing done 1163DB23413769866189369CD48BB8356F823578
08-12 20:33:18.371: I/Icing(1980): Not enough disk space for indexing trimmable
08-12 20:33:18.511: I/Icing(1980): Not enough disk space for indexing trimmable
08-12 20:33:18.521: I/Icing(1980): Indexing done    427C1771ABBC521123604E224408F07F2376CCFA
08-12 20:40:18.881: I/EventLogService(1980): Aggregate from 1407856218577 (log), 1407856218577 (data)
08-12 20:40:19.031: W/EventLogAggregator(1980): Unknown tag: SYSTEM_AUDIT
08-12 20:40:19.031: W/EventLogAggregator(1980): Unknown tag: faceunlock
08-12 20:40:19.031: W/EventLogAggregator(1980): Unknown tag: snet
08-12 20:40:19.031: W/EventLogAggregator(1980): Unknown tag: snet_gcore
08-12 20:43:05.201: I/MultiDex(2810): install
08-12 20:43:05.221: I/MultiDex(2810): MultiDexExtractor.load(/data/app/com.google.android.gms-1.apk, false)
08-12 20:43:05.241: I/MultiDex(2810): loading existing secondary dex files 
08-12 20:43:05.251: I/MultiDex(2810): load found 1 secondary dex files
08-12 20:43:05.271: I/MultiDex(2810): install done
08-12 20:43:05.381: I/ProviderInstaller(2810): Insert disabled by gate 'gms:security:enable_conscrypt_in_gms_application'
08-12 20:53:14.311: W/Uploader(1980): No account for auth token provided
08-12 21:10:19.131: I/EventLogService(1980): Aggregate from 1407858019039 (log), 1407858019039 (data)
08-12 21:14:49.861: I/MultiDex(5375): install
08-12 21:14:49.881: I/MultiDex(5375): MultiDexExtractor.load(/data/app/com.google.android.gms-1.apk, false)
08-12 21:14:49.901: I/MultiDex(5375): loading existing secondary dex files
08-12 21:14:49.911: I/MultiDex(5375): load found 1 secondary dex files
08-12 21:14:49.921: I/MultiDex(5375): install done
08-12 21:14:50.021: I/ProviderInstaller(5375): Insert disabled by gate 'gms:security:enable_conscrypt_in_gms_application'

以下是代码

 public class Login extends Activity implements View.OnClickListener, ConnectionCallbacks, OnConnectionFailedListener {


private static final int RC_SIGN_IN = 0;
private GoogleApiClient mGoogleApiClient;
private boolean mIntentInProgress;
private boolean mSignInClicked;
private ConnectionResult mConnectionResult;

Button Login, Google, FB, TW, forgot, signup;
EditText email, pswd;
TextView invalid;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.login);
    Intitialize();
    login();
    startGoogleAPI();
}

private void startGoogleAPI() {
    // TODO Auto-generated method stub
    mGoogleApiClient = new GoogleApiClient.Builder(this)
    .addConnectionCallbacks(this)
    .addOnConnectionFailedListener(this).addApi(Plus.API, null)
    .addScope(Plus.SCOPE_PLUS_LOGIN).build();
}
protected void onStart() {
    super.onStart();
    mGoogleApiClient.connect();
}

protected void onStop() {
    super.onStop();
    if (mGoogleApiClient.isConnected()) {
        mGoogleApiClient.disconnect();
    }
}


private void Intitialize() {
    // TODO Auto-generated method stub

    Login = (Button) findViewById(R.id.bLogin);
    Google = (Button) findViewById(R.id.btnGplus);
    FB = (Button) findViewById(R.id.btnFb);
    TW = (Button) findViewById(R.id.btnTwitter);
    signup = (Button) findViewById(R.id.button1);
    forgot = (Button) findViewById(R.id.button2);
    email = (EditText) findViewById(R.id.etLoginEmail);
    pswd = (EditText) findViewById(R.id.etLoginPassword);
    invalid = (TextView) findViewById(R.id.tvLoginInvalid);
    facebook = new Facebook(FB_APP_ID);
    mAsyncRunner = new AsyncFacebookRunner(facebook);
}

private void login() {
    // TODO Auto-generated method stub
    Login.setOnClickListener(this);
    Google.setOnClickListener(this);
    FB.setOnClickListener(this);
    TW.setOnClickListener(this);
    forgot.setOnClickListener(this);
    signup.setOnClickListener(this);

}

@Override
public void onClick(View v) {
    // TODO Auto-generated method stub
    switch (v.getId()) {
    case R.id.bLogin:
        if (email.getText().toString().equals("")
                || pswd.getText().toString().equals("")) {
            invalid.setText("Enter Email or Password");
        } else if (!validEmail(email.getText().toString())) {
            invalid.setText("Email is not valid");
        } else {
            String e = email.getText().toString();
            String pwd = pswd.getText().toString();
            Person p = new Person();
            p.setEmail(e);
            p.setPassword(pwd);

            //Web Api Call

        }

        break;
    case R.id.btnGplus:
        signInWithGplus();

        break;
    case R.id.btnFb:

        break;
    case R.id.btnTwitter:

        break;
    case R.id.button1:
        // sign up
        Intent i = new Intent("packageName.REGISTER");
        startActivity(i);
        break;
    case R.id.button2:
        // forgot
        Intent j = new Intent("pacageName.FORGOTPASSWORD");
        startActivity(j);
        break;
    }
}



private boolean validEmail(String email) {
    Pattern pattern = Patterns.EMAIL_ADDRESS;
    return pattern.matcher(email).matches();
}


private void signInWithGplus() {
    // TODO Auto-generated method stub
    if (!mGoogleApiClient.isConnecting()) {
        mSignInClicked = true;
        resolveSignInError();
    }
}

private void getGoogleProfileInformation() {
    try {
        if (Plus.PeopleApi.getCurrentPerson(mGoogleApiClient) != null) {
            com.google.android.gms.plus.model.people.Person currentPerson = Plus.PeopleApi
                    .getCurrentPerson(mGoogleApiClient);
            String personName = currentPerson.getDisplayName();
            String email = Plus.AccountApi.getAccountName(mGoogleApiClient);

            Person p = new Person();

            p.setUsername(personName);
            p.setEmail(email);

        } else {
            Toast.makeText(getApplicationContext(),
                    "Person information is null", Toast.LENGTH_LONG).show();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

private void resolveSignInError() {
    if (mConnectionResult.hasResolution()) {
        try {
            mIntentInProgress = true;
            mConnectionResult.startResolutionForResult(this, RC_SIGN_IN);
        } catch (SendIntentException e) {
            mIntentInProgress = false;
            mGoogleApiClient.connect();
        }
    }
}
@Override
protected void onActivityResult(int requestCode, int responseCode,
        Intent intent) {
    if (requestCode == RC_SIGN_IN) {
        if (responseCode != RESULT_OK) {
            mSignInClicked = false;
        }

        mIntentInProgress = false;

        if (!mGoogleApiClient.isConnecting()) {
            mGoogleApiClient.connect();
        }
    }
}

private void signOutFromGplus() {
    if (mGoogleApiClient.isConnected()) {
        Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
        mGoogleApiClient.disconnect();
        mGoogleApiClient.connect();
    }
}


@Override
public void onConnectionFailed(ConnectionResult result) {
    // TODO Auto-generated method stub
    if (!result.hasResolution()) {
        GooglePlayServicesUtil.getErrorDialog(result.getErrorCode(), this,
                0).show();
        return;
    }

    if (!mIntentInProgress) {
        // Store the ConnectionResult for later usage
        mConnectionResult = result;

        if (mSignInClicked) {
            // The user has already clicked 'sign-in' so we attempt to
            // resolve all
            // errors until the user is signed in, or they cancel.
            resolveSignInError();
        }
    }
}

@Override
public void onConnected(Bundle arg0) {
    // TODO Auto-generated method stub
    mSignInClicked = false;
    getGoogleProfileInformation();
}

public void onDisconnected() {
    // TODO Auto-generated method stub
    mGoogleApiClient.connect();
}

@Override
public void onConnectionSuspended(int arg0) {
    // TODO Auto-generated method stub
    mGoogleApiClient.connect();
}

清单文件中的权限

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />

<meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />

如果我删除此代码并运行该应用程序。然后应用程序运行正常,但添加此代码后,应用程序在启动画面后崩溃。

任何帮助都将非常感谢...提前致谢

1 个答案:

答案 0 :(得分:1)

[[已解决]] 只需从addApi(Plus.API)方法中删除'null'作为参数即可解决错误

mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this).addApi(Plus.API)
.addScope(Plus.SCOPE_PLUS_LOGIN).build();

P.S请记住,您必须为您在Android设备中使用的电子邮件地址生成客户端ID作为主电子邮件地址。在我的案例中,这也对我有帮助。

相关问题