安装Facebook应用程序时,我的Facebook登录按钮正常工作。
当设备上没有安装Facebook应用时,它会崩溃我的应用:
E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: Failed resolution of:
Landroid/support/customtabs/CustomTabsIntent$Builder;
at com.facebook.internal.CustomTab.openCustomTab(CustomTab.java:47)
at com.facebook.CustomTabMainActivity.onCreate(CustomTabMainActivity.java:67)
at android.app.Activity.performCreate(Activity.java:6251)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.customtabs.CustomTabsIntent$Builder" on path: DexPathList[[zip file "/data/app/com.testapp-2/base.apk"],nativeLibraryDirectories=[/data/app/com.testapp-2/lib/arm, /data/app/com.testapp-2/base.apk!/lib/armeabi-v7a, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at com.facebook.internal.CustomTab.openCustomTab(CustomTab.java:47)
at com.facebook.CustomTabMainActivity.onCreate(CustomTabMainActivity.java:67)
at android.app.Activity.performCreate(Activity.java:6251)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Suppressed: java.lang.ClassNotFoundException: android.support.customtabs.CustomTabsIntent$Builder
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 15 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
清单:
<activity
android:name="com.facebook.CustomTabActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="@string/fb_login_protocol_scheme" />
</intent-filter>
</activity>
,而fb_login_protocol_scheme值根据需要以“fb”开头。
Gradle依赖项:
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:25.3.0'
compile 'com.android.support:design:25.3.0'
compile 'com.google.firebase:firebase-core:10.2.1'
compile 'com.google.firebase:firebase-database:10.2.1'
compile 'com.google.firebase:firebase-ads:10.2.1'
compile ('com.facebook.android:facebook-android-sdk:4.20.0') // app invites
{
exclude group: 'com.android.support'
}
compile 'com.facebook.android:audience-network-sdk:4.20.0'
compile "com.android.support:cardview-v7:25.3.0"
testCompile 'junit:junit:4.12'
}
我该如何解决?
答案 0 :(得分:18)
您要从facebook依赖项中排除'com.android.support'。我认为这是因为它不包括与你相同版本的支持库(facebook sdk 4.20.0使用android:support:25.0.0但你包含支持库25.3.0,所以排除它是正确的做)。
但是,如果您希望CustomTab功能正常工作,则必须在应用依赖项中包含相应的依赖项,因此请添加以下行:
compile 'com.android.support:customtabs:25.3.0'
它应该有用。
答案 1 :(得分:0)
添加这两个依赖项:
implementation('com.facebook.android:facebook-login:[4,5)') {
exclude group: 'com.android.support'
}
implementation 'com.android.support:customtabs:25.3.0'
答案 2 :(得分:0)
在build.gradle中添加此依赖项
implementation 'com.android.support:customtabs:28.0.0'