我是一个初学者,我试图创建与Facebook集成的应用程序。
我已经做了所有步骤(在模块结构导入Facebook的SDK,在增加的gradle文件丢失depedencies,加入依赖模块在结构我的应用程序的项目再次)。一切似乎都很正常,我加入main_activity.xml一个简单LoginButton),并没有错误出现了。
由于我试图尽一切MainActivity.java需要进口的Facebook,他们都变成了红色。这些都是进口,如:
进口com.facebook.Session; 进口com.facebook.SessionState; 进口com.facebook.UiLifecycleHelper; 进口com.facebook.widget.LoginButton; 进口com.facebook.widget.LoginButton.UserInfoChangedCallback;
和类似的消息符号会解决不了。我GOOGLE了它,就像我,找不到为我工作的解决方案。在相反的,这似乎并不有一个问题:
进口com.facebook.login.widget.LoginButton;
下面是我的Android清单文件的XML:
<?XML版本=1.0编码=UTF-8&GT?; <清单的xmlns:机器人=http://schemas.android.com/apk/res/android 包=com.user.moviere> <使用许可权的android:NAME =android.permission.INTERNET对/> <应用 机器人:allowBackup =真 机器人:图标=@的mipmap / ic_launcher 机器人:标签=@字符串/ APP_NAME 机器人:主题=@风格/ AppTheme> <元数据机器人:名字=com.facebook.sdk.ApplicationId机器人:值=@字符串/ facebook_app_id/> <活动 机器人:名字=。MainActivity 机器人:标签=@字符串/ APP_NAME> &所述;意图滤光器> <作用机器人:名字=android.intent.action.MAIN/> <类机器人:名字=android.intent.category.LAUNCHER/> &所述; /意图滤光器> < /活性GT; <活动机器人:名字=com.facebook.LoginActivity 机器人:主题=@安卓风格/ Theme.Translucent.NoTitleBar 机器人:标签=@字符串/ APP_NAME/> <元数据机器人:名字=com.facebook.sdk.ApplicationId机器人:值=@字符串/ facebook_app_id/> <活动机器人:名字=com.facebook.FacebookActivity 机器人:configChanges = 键盘| keyboardHidden |屏幕布置|屏幕尺寸|定位 机器人:主题=@安卓风格/ Theme.Translucent.NoTitleBar 机器人:标签=@字符串/ APP_NAME/> < /用途>< /清单>
和这里是我的build.gradle
应用插件:'com.android.application安卓{ compileSdkVersion 21 buildToolsVersion '21 .1.2 defaultConfig { 的applicationIDcom.user.moviere 9的minSdkVersion targetSdkVersion 22 版本code 1 的versionName1.0 } buildTypes { 发布 { minifyEnabled假 proguardFiles getDefaultProguardFile('proguard的-android.txt'),'proguard-rules.pro } }}库{ mavenCentral()}依赖{ 编译文件树(导演:'库',包括:['的* .jar']) //编制项目(:Facebook的) 编译com.android.support:appcompat-v7:22.0.0 编译com.facebook.android:facebook-android-sdk:4.0.0 编译com.android.support:support-v4:22.0.0 }
解决方案
好吧,我创建了从一开始项目,再次导入的FB SDK。但随着进口真正的问题是,Facebook的SDK 4已经改变了一些功能,其中之一就是UiLifecycleHelper例如,它不存在了。
所有的变化全部细节是在这里:
https://developers.facebook.com/docs/android/upgrading-4.x
I'm a begginer and I am trying to create an app with Facebook Integration.
I have done all the steps(Importing Facebook SDK in Module Structure,adding missing depedencies in gradle files,adding the dependencies module for my app project in Structure again). Everything seemed to be fine,I added A simple LoginButton in main_activity.xml) and no error showed up.
Since I tried to do all the facebook imports needed in MainActivity.java, they all turned red. Those were imports like:
import com.facebook.Session;
import com.facebook.SessionState;
import com.facebook.UiLifecycleHelper;
import com.facebook.widget.LoginButton;
import com.facebook.widget.LoginButton.UserInfoChangedCallback;
and messages like "symbol session cannot be resolved". I googled it as much as I could,couldn't find a solution that worked for me. At the opposite, this didn't seem to have a problem:
import com.facebook.login.widget.LoginButton;
Here is my Android Manifest File XML:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.user.moviere" >
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>
<activity
android:name=".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.facebook.LoginActivity"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:label="@string/app_name" />
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>
<activity android:name="com.facebook.FacebookActivity"
android:configChanges=
"keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:label="@string/app_name" />
</application>
</manifest>
And here is my build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion '21.1.2'
defaultConfig {
applicationId "com.user.moviere"
minSdkVersion 9
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
// compile project(':facebook')
compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.facebook.android:facebook-android-sdk:4.0.0'
compile 'com.android.support:support-v4:22.0.0'
}
解决方案
Ok, I created the project from the beginning,imported the FB SDK again. But the real problem with the imports was that Facebook SDK 4 has changed some of the functions,one of them is UiLifecycleHelper for example, it doesn't exist anymore.
Full details about all the changes is here:
https://developers.facebook.com/docs/android/upgrading-4.x
上一篇:最有效的/右实践修剪无意义的零在小数的末尾小数、末尾、最有效、无意义
下一篇:ActionBarDrawerToggle不能应用于Android.support.v7.widget.Toolbar应用于、Android、ActionBarDrawerToggle、support