Android接入Facebook登录踩坑记录

官方文档:https://developers.facebook.com/docs/facebook-login/android

Facebook SDK

Facebook SDK包含

  • facebook-core
  • facebook-common
  • facebook-login
  • facebook-share
  • facebook-places
  • facebook-applinks
  • facebook-marketing
  • facebook-messenger
  • notifications
  • AccountKit

实现登录功能至少需要

  • facebook-core
  • facebook-common
  • facebook-login

可以分别引入core、common、login,也可以直接引入facebook-android-sdk

Atlas Bundle中引用Facebook SDK

如使用Atlas远程Bundle形式加载,则AndroidManifest.xml中的facebook_app_idfb_login_protocol_scheme不能包含Bundle内部的string等资源,否则导致AndroidManifest.xml会被merge到host中,但string.xml不会,从而找不到资源

app\build\intermediates\manifests\full\debug\AndroidManifest.xml:73: error: Error: No resource found that matches the given name (at 'value' with value '@string/facebook_app_id').

app\build\intermediates\manifests\full\debug\AndroidManifest.xml:74: error: Error: No resource found that matches the given name (at 'theme' with value '@style/com_facebook_activity_theme').

app\build\intermediates\manifests\full\debug\AndroidManifest.xml:82: error: Error: No resource found that matches the given name (at 'scheme' with value '@string/fb_login_protocol_scheme').

valuescheme

若在AndroidManifest.xml中直接将valueschemefacebook_app_idfb_login_protocol_scheme的值写死

App Ids cannot be directly placed in the manifest.They must be prefixed by 'fb' or be placed in the string resource file.

解决方案:将facebook_app_idfb_login_protocol_scheme放在公共module的资源文件中,然后在AndroidManifest.xml中引用

<string name="facebook_app_id">2147844112xxxxxx</string>
<string name="fb_login_protocol_scheme">fb2147844112xxxxxx</string>

theme

FacebookActivity需要指定公共的Theme,给FacebookActivity更换Theme可能会出现冲突,可以通过给Activity添加tools:replace="android:theme"解决。

<activity android:name="com.facebook.FacebookActivity"
    android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
    android:label="@string/app_name"
    tools:replace="android:theme"
    android:theme="@android:style/Theme.Translucent.NoTitleBar"
    />

CardView资源找不到

Facebook SDK内置CardView,若外部再次引用会报版本冲突或找不到资源

app\build\intermediates\awb-res\merged\debug\me.yezhou.lib-social\layout\com_facebook_device_auth_dialog_fragment.xml:22: error: No resource identifier found for attribute 'cardElevation' in package 'me.yezhou.lib.social'
No resource identifier found for attribute 'cardBackgroundColor' in package 'me.yezhou.lib.social'

zxing依赖冲突

facebook-android-sdk包含com.google.zxing.core二维码扫描依赖,如公共module或其他bundle也依赖zxing,注意冲突

Gradle依赖

dependencies {
//    compile('com.facebook.android:facebook-core:4.36.1', {
//        exclude group: 'com.android.support'
//    })
//    compile('com.facebook.android:facebook-common:4.36.1', {
//        exclude group: 'com.android.support'
//    })
//    compile('com.facebook.android:facebook-login:4.36.1', {
//        exclude group: 'com.android.support'
//    })
    compile('com.facebook.android:facebook-android-sdk:4.36.1', {
        //exclude group: 'com.android.support'
        exclude group: 'com.android.support', module: 'appcompat'
        exclude group: 'com.google.zxing'
    })
}

所提供的网址不被应用程序配置所接纳

所提供的网址不被应用程序配置所接纳。: One or more of the given URLs is not allowed by the App's settings. To use this URL you must add a valid native platform in your App's settings.

将软件包名称与应用的默认类关联

地址:https://developers.facebook.com/docs/facebook-login/android#5----------------

Invalid key hash

Invalid key hash. The key hash xxx does not match any stored key hashs. Configure your app key hashes at https://developers.facebook.com/apps/2147844112xxxxxx

为应用提供开发和发布密钥散列

keytool -exportcert -alias androiddebugkey -keystore "C:\Users\yezhou\.android\debug.keystore" | "C:\OpenSSL-Win64\bin\openssl" sha1 -binary | "C:\OpenSSL-Win64\bin\openssl" base64
输入密钥库口令:  //注意不要输入口令,为空即可

版权声明:
作者:Joe.Ye
链接:https://www.appblog.cn/index.php/2023/03/18/android-access-facebook-login-record/
来源:APP全栈技术分享
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
打赏
海报
Android接入Facebook登录踩坑记录
官方文档:https://developers.facebook.com/docs/facebook-login/android Facebook SDK Facebook SDK包含 facebook-core facebook-common facebook-login f……
<<上一篇
下一篇>>
文章目录
关闭
目 录