我正在关注Android的快速启动应用程序(https://developers.google.com/identity/toolkit/android/quickstart)并发出以下错误:
FATAL EXCEPTION: main
Process: com.google.identitytoolkit.demo, PID: 12813
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/facebook/Session;
(...)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.facebook.Session" on path: DexPathList[[zip file "/data/app/com.google.identitytoolkit.demo-1/base.apk"],nativeLibraryDirectories=[/vendor/lib64, /system/lib64]]
(...)
Suppressed: java.lang.ClassNotFoundException: com.facebook.Session
(...)
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
这是我的代码:
的AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.identitytoolkit.demo"
android:versionCode="1"
android:versionName="1.0.0" >
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.google.identitytoolkit.demo.GitkitDemo"
android:label="@string/app_name"
android:launchMode="singleTask" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="gitkit"
android:scheme="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" />
</intent-filter>
</activity>
<activity android:name="com.facebook.LoginActivity"/>
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data
android:name="identitytoolkit.show_providers"
android:value="Google, Yahoo, Facebook" />
<meta-data
android:name="identitytoolkit.use_google_plus"
android:value="false" />
<meta-data
android:name="identitytoolkit.api_key"
android:value="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" />
<meta-data
android:name="identitytoolkit.server_client_id"
android:value="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" />
<meta-data
android:name="identitytoolkit.server_widget_url"
android:value="INSERT_YOUR_SERVER_WIDGET_URL" />
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/fb_app_id"/>
</application>
GitkitDemo.java
package com.google.identitytoolkit.demo;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.facebook.appevents.AppEventsLogger;
import com.facebook.FacebookSdk;
import com.google.identitytoolkit.GitkitClient;
import com.google.identitytoolkit.GitkitUser;
import com.google.identitytoolkit.IdToken;
import java.io.IOException;
public class GitkitDemo extends Activity implements OnClickListener {
private GitkitClient client;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
@Override
public void onSignIn(IdToken idToken, GitkitUser user) {
showProfilePage(idToken, user);
}
@Override
public void onSignInFailed() {
Toast.makeText(GitkitDemo.this, "Sign in failed", Toast.LENGTH_LONG).show();
}
}).build();
showSignInPage();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (!client.handleActivityResult(requestCode, resultCode, intent)) {
super.onActivityResult(requestCode, resultCode, intent);
}
}
@Override
protected void onNewIntent(Intent intent) {
if (!client.handleIntent(intent)) {
super.onNewIntent(intent);
}
}
private void showSignInPage() {
setContentView(R.layout.welcome);
Button button = (Button) findViewById(R.id.sign_in);
button.setOnClickListener(this);
}
private void showProfilePage(IdToken idToken, GitkitUser user) {
setContentView(R.layout.profile);
showAccount(user);
findViewById(R.id.sign_out).setOnClickListener(this);
}
@Override
public void onClick(View v) {
if (v.getId() == R.id.sign_in) {
client.startSignIn();
} else if (v.getId() == R.id.sign_out) {
showSignInPage();
}
}
private void showAccount(GitkitUser user) {
((TextView) findViewById(R.id.account_email)).setText(user.getEmail());
if (user.getDisplayName() != null) {
((TextView) findViewById(R.id.account_name)).setText(user.getDisplayName());
}
if (user.getPhotoUrl() != null) {
final ImageView pictureView = (ImageView) findViewById(R.id.account_picture);
new AsyncTask<String, Void, Bitmap>() {
@Override
protected Bitmap doInBackground(String... arg) {
try {
byte[] result = HttpUtils.get(arg[0]);
return BitmapFactory.decodeByteArray(result, 0, result.length);
} catch (IOException e) {
return null;
}
}
@Override
protected void onPostExecute(Bitmap bitmap) {
if (bitmap != null) {
pictureView.setImageBitmap(bitmap);
}
}
}.execute(user.getPhotoUrl());
}
}
}
的build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
}
}
repositories {
mavenCentral()
flatDir {
dirs 'libs'
}
}
apply plugin: 'com.android.application'
android {
compileSdkVersion 19
buildToolsVersion '19.1.0'
defaultConfig {
minSdkVersion 15
targetSdkVersion 19
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
res.srcDirs = ['res']
}
}
}
dependencies {
compile 'com.google.android.gms:play-services:6.1.11'
compile 'com.facebook.android:facebook-android-sdk:4.6.0'
compile(name: 'identitytoolkit-api11', ext: 'aar')
compile(name: 'identitytoolkit_fb', ext: 'jar')
}
答案 0 :(得分:0)
这是由于Facebook更改了v4的SDK。 Facebook Session Class已不复存在。这个库'identitytoolkit_fb'仅适用于Facebook Android SDK v3。我想你可能想从Github https://github.com/googlesamples/identity-toolkit-android/blob/master/plugins/identitytoolkit_fbv4.jar?raw=true下载v4版本库。
使用那个替换当前的“identitytoolkit_fb.jar”。那可行。