【发布时间】:2026-01-13 03:00:02
【问题描述】:
我在通过 firebase 实现 Facebook 登录时卡在代码中。
我严格按照文档进行操作,但它无法识别 facebook SDK,尽管我可以在项目的库部分中看到所有与 Facebook 相关的库。
在这里你可以看到我的 build.gralde(:app) ;
plugins {
id 'com.android.application'
id 'com.google.gms.google-services'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.mycompany.myapp"
minSdkVersion 21
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.4.0-alpha02'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'com.google.firebase:firebase-auth:21.0.1'
implementation 'com.google.firebase:firebase-database:20.0.1'
implementation 'com.facebook.android:facebook-android-sdk:12.2.0'
implementation platform('com.google.firebase:firebase-bom:28.4.0')
implementation 'com.google.firebase:firebase-auth'
implementation 'com.google.android.gms:play-services-auth:19.2.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
这里是我的 build.gradle(:module) ;
buildscript {
repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:4.1.1"
classpath 'com.google.gms:google-services:4.3.10'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
我的清单文件;
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mycompany.myapp">
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_myapp_logo"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.MYAPP">
<activity android:name=".main_activities.LoginTrialActivity"></activity>
<activity android:name=".user_activities.ForgotPasswordActivity" />
<activity android:name=".user_activities.UserDetails" />
<activity android:name=".SplashScreenActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".user_activities.SigninActivity" />
<activity android:name=".user_activities.SignupActivity" />
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>
<meta-data android:name="com.facebook.sdk.ClientToken" android:value="@string/facebook_client_token"/>
</application>
</manifest>
我还下载了 facebook-android-sdk-4.42.0 插入到任何地方并且从未使用过......我不明白如何使用它。
最后,请看附件图片,看看我实际上有 facebook 库。
您能帮忙吗?
【问题讨论】:
-
你做过 gradle 同步吗?
facebook_app_id和facebook_client_token字符串是否已定义?你看到了什么错误? -
是的,我在 gradle 文件内部和从文件同步 -> 将项目与 Gradle 文件同步。我添加了两个字符串。我只是尝试导入 com.facebook.FacebookSdk;它说“无法解析符号'FacebookSdk'
-
还有其他 2 个问题?
-
我编辑了我的回复,通过它识别“com.facebook”部分的方式,问题是“FacebookSdk”
-
好的,我解决了问题,我将“implementation 'com.facebook.android:facebook-android-sdk:12.2.0' 更改为 'implementation 'com.facebook.android:facebook-android-sdk :4.42.0' 问题就解决了。这个版本是我从“developer.facebook”下载到我电脑上的那个版本。你知道为什么吗?
标签: firebase android-studio firebase-authentication facebook-login facebook-sdk-4.x