gpt4 book ai didi

安卓工作室 : Cannot get Facebook SDK working

转载 作者:行者123 更新时间:2023-11-29 21:08:54 26 4
gpt4 key购买 nike

几天来我一直在努力解决这个问题,但我放弃了。

这是我遇到的错误:

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 3.14

我下载了 facebook SDK,将其解压缩,然后转到"file">“导入模块”并选择“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);
}

}

最佳答案

我在这里找到了答案:https://stackoverflow.com/a/23577782/3554758

我添加的是“Android 库”而不是选择“导入现有项目”现在效果很好 enter image description here

关于安卓工作室 : Cannot get Facebook SDK working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23596545/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com