2014-05-11 61 views
1

我一直试图弄清楚这几天,但我放弃了。Android Studio:无法让Facebook SDK工作

下面是我收到的错误:3.14

我下载了Facebook SDK,提取它

Error:(9, 1) error: package com.facebook does not exist 
Error:(10, 1) error: package com.facebook.model does not exist 
Error:(11, 20) error: package com.facebook does not exist 
Error:(21, 58) error: package Session does not exist 
Error:(21, 9) error: cannot find symbol variable Session 
Error:(48, 9) error: cannot find symbol variable Session 

我使用过Android Studio 0.58和Facebook SDK,然后去文件>导入模块和选择了“Facebook”模块。没有帮助。

我把jar文件放到我的libs文件夹中。清洁。同步。没有帮助。

我添加到我的build.gradle(许多搜索建议)。做了同步。我检查了一下,“android-support-v4.jar”位于项目结构的依赖项中。仍然没有帮助。

这里是我的build.gradle:

apply plugin: 'android' 

android { 
compileSdkVersion 19 
buildToolsVersion '19.0.3' 

defaultConfig { 
    minSdkVersion 9 
    targetSdkVersion 19 
    versionCode 6 
    versionName "0.3.0" 
} 
signingConfigs{ 
    release { 
     storeFile file("path") 
     storePassword "password" 
     keyAlias "alias" 
     keyPassword "password" 
    } 
buildTypes { 
    release { 
     runProguard true 
     proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' 
     debuggable false 
     signingConfig signingConfigs.release 
     zipAlign true 
     } 
    } 
} 
} 
dependencies { 
    compile fileTree(include: ['*.jar'], dir: 'libs') 
    compile 'com.android.support:appcompat-v7:19.+' 
    compile 'com.google.android.gms:play-services:+' 
    compile files('libs/libGoogleAnalyticsServices.jar') 
    compile files('libs/android-support-v4.jar') 
} 

这里是我的Android的Manifest.xml

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
package="com.understandingyourbody.uyb" > 

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

<application 
    android:allowBackup="true" 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" 
    android:theme="@style/AppTheme" 
    > 
    <meta-data 
     android:name="com.google.android.gms.version" 
     android:value="@integer/google_play_services_version" 
     /> 
    <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/app_id"/> 


    <activity 
     android:name="com.understandingyourbody.uyb.MainActivity" 
     android:label="@string/app_name"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 
      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 

    <activity 
     android:name="com.understandingyourbody.uyb.WordPress" 
     android:label="@string/app_name"> 
     <intent-filter> 
      <action android:name="android.intent.action.WORDPRESS" /> 
      <category android:name="android.intent.category.DEFAULT" /> 
     </intent-filter> 
    </activity> 

    <activity 
     android:name="com.understandingyourbody.uyb.Facebook" 
     android:label="@string/app_name"> 
     <intent-filter> 
      <action android:name="android.intent.action.FACEBOOK" /> 
      <category android:name="android.intent.category.DEFAULT" /> 
     </intent-filter> 
    </activity> 

    <activity android:name="com.google.android.gms.ads.AdActivity" 
     android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/> 

</application> 

这里是我的Java

package com.understandingyourbody.uyb; 

import android.os.Bundle; 
import android.app.Activity; 
import android.content.Intent; 
import android.widget.TextView; 

import com.facebook.*; 
import com.facebook.model.*; 
import com.facebook.Session; 

public class Facebook extends Activity { 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.facebook); 

    // start Facebook Login 
    Session.openActiveSession(this, true, new Session.StatusCallback() { 

     // callback when session changes state 
     @Override 
     public void call(Session session, SessionState state, Exception exception) { 
      if (session.isOpened()) { 

       // make request to the /me API 
       Request.newMeRequest(session, new Request.GraphUserCallback() { 

        // callback after Graph API response with user object 
        @Override 
        public void onCompleted(GraphUser user, Response response) { 
         if (user != null) { 
          TextView welcome = (TextView) findViewById(R.id.welcome); 
          welcome.setText("Hello " + user.getName() + "!"); 
         } 
        } 
       }).executeAsync(); 
      } 
     } 
    }); 
} 

@Override 
public void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 
    Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data); 
} 

} 

回答

0

导入时该模块,不要忘了广告d它作为一个依赖:

dependencies { 
    compile project(':facebooksdk') // The name of the module. 
} 
+0

这给了我一个错误: 错误:(37,0)无法在项目':UYB'中找到具有路径':facebooksdk'的项目。 – dongemus

+0

你能告诉我你的'settings.gradle'吗? – nhaarman

+0

这是1行: 包括':UYB' – dongemus

相关问题