我的应用程序点击“ Continue with facebook”后崩溃/关闭

时间:2018-07-23 13:37:45

标签: android android-studio kotlin facebook-login android-facebook

我正在尝试将facebook与我在android studio中的应用程序集成。我是Kotlin语言的业余爱好者,可以用来实现自己的目标。

我遵循了Facebook开发者页面上的教程。问题是,一旦我按下登录按钮,它就会加载2到3秒钟,然后崩溃/关闭。

LoginActivity.kt file

中的代码段
val fblogin_button= findViewById<LoginButton>(R.id.login_button)
    fblogin_button.setOnClickListener {
        callbackManager = CallbackManager.Factory.create()
        LoginManager.getInstance().logInWithReadPermissions(this,Arrays.asList("email"))
        LoginManager.getInstance().registerCallback(callbackManager,
        object : FacebookCallback<LoginResult>{
            override fun onSuccess(result: LoginResult) {
                Log.d("LoginActivity","Facebook token" + result.accessToken.token)
                startActivity(Intent(baseContext,GradeActivity::class.java))
            }

            override fun onCancel() {
                Log.d("LoginActivity","Facebook oncancel")
            }

            override fun onError(error: FacebookException?) {
                Log.d("LoginActivity","Facebook onError")
            }

        })
    }

onCreate方法之外,我还有另一种方法。如下所示。

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
    super.onActivityResult(requestCode, resultCode, data)
    callbackManager?.onActivityResult(requestCode,resultCode,data)
}

Manifest文件的内容如下所示。

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.vishwa.imaginators">
<uses-permission android:name="android.permission.INTERNET" />
<!--<uses-permission android:name="android.permission.CAMERA" />-->
<!--<uses-feature android:name="android.hardware.camera" />-->
<!--<uses-feature android:name="android.hardware.camera" android:required="false" />-->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".SplashscreenActivity"
        android:theme="@style/AppTheme"
        android:noHistory="true">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".LoginActivity"
        android:theme="@style/AppTheme"
        android:noHistory="true">
    </activity>
    <activity android:name=".GradeActivity"
        android:theme="@style/AppTheme"
        android:noHistory="true">

    </activity>
    <activity android:name=".MainActivity">

    </activity>
    <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:label="@string/app_name" />
    <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>


</application>

您可以看到onSuccess方法,如果登录成功,则GradeActivity应该打开,而关闭。

日志如下所示。

07-23 19:22:37.154 22589-22589/? I/art: Late-enabling -Xcheck:jni
07-23 19:22:37.219 22589-22589/? D/TidaProvider: TidaProvider()
07-23 19:22:37.257 22589-22589/com.example.vishwa.imaginators 
W/ActivityThread: Application com.example.vishwa.imaginators is waiting for the debugger on port 8100...
07-23 19:22:37.282 22589-22589/com.example.vishwa.imaginators I/System.out: 
Sending WAIT chunk
07-23 19:22:37.375 22589-22595/com.example.vishwa.imaginators I/art: Debugger is active
07-23 19:22:37.483 22589-22589/com.example.vishwa.imaginators I/System.out: Debugger has connected
waiting for debugger to settle...
07-23 19:22:37.684 22589-22589/com.example.vishwa.imaginators I/System.out: waiting for debugger to settle...
07-23 19:22:37.884 22589-22589/com.example.vishwa.imaginators I/System.out: waiting for debugger to settle...
07-23 19:22:38.084 22589-22589/com.example.vishwa.imaginators I/System.out: waiting for debugger to settle...
07-23 19:22:38.284 22589-22589/com.example.vishwa.imaginators I/System.out: waiting for debugger to settle...
07-23 19:22:38.484 22589-22589/com.example.vishwa.imaginators I/System.out: waiting for debugger to settle...
07-23 19:22:38.685 22589-22589/com.example.vishwa.imaginators I/System.out: waiting for debugger to settle...
07-23 19:22:38.885 22589-22589/com.example.vishwa.imaginators I/System.out: debugger has settled (1427)
07-23 19:22:38.943 22589-22589/com.example.vishwa.imaginators W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --non-interactive --runtime-arg -Xms64m --runtime-arg -Xmx512m -j2 --instruction-set-variant=generic --instruction-set-features=default --dex-file=/data/app/com.example.vishwa.imaginators-2/split_lib_dependencies_apk.apk --oat-file=/data/dalvik-cache/arm64/data@app@com.example.vishwa.imaginators-2@split_lib_dependencies_apk.apk@classes.dex) because non-0 exit status
07-23 19:22:39.444 22589-22589/com.example.vishwa.imaginators W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --non-interactive --runtime-arg -Xms64m --runtime-arg -Xmx512m -j2 --instruction-set-variant=generic --instruction-set-features=default --dex-file=/data/app/com.example.vishwa.imaginators-2/split_lib_slice_0_apk.apk --oat-file=/data/dalvik-cache/arm64/data@app@com.example.vishwa.imaginators-2@split_lib_slice_0_apk.apk@classes.dex) because non-0 exit status
07-23 19:22:39.501 22589-22589/com.example.vishwa.imaginators W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --non-interactive --runtime-arg -Xms64m --runtime-arg -Xmx512m -j2 --instruction-set-variant=generic --instruction-set-features=default --dex-file=/data/app/com.example.vishwa.imaginators-2/split_lib_slice_1_apk.apk --oat-file=/data/dalvik-cache/arm64/data@app@com.example.vishwa.imaginators-2@split_lib_slice_1_apk.apk@classes.dex) because non-0 exit status
07-23 19:22:39.560 22589-22589/com.example.vishwa.imaginators W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --non-interactive --runtime-arg -Xms64m --runtime-arg -Xmx512m -j2 --instruction-set-variant=generic --instruction-set-features=default --dex-file=/data/app/com.example.vishwa.imaginators-2/split_lib_slice_2_apk.apk --oat-file=/data/dalvik-cache/arm64/data@app@com.example.vishwa.imaginators-2@split_lib_slice_2_apk.apk@classes.dex) because non-0 exit status
07-23 19:22:39.630 22589-22589/com.example.vishwa.imaginators W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --non-interactive --runtime-arg -Xms64m --runtime-arg -Xmx512m -j2 --instruction-set-variant=generic --instruction-set-features=default --dex-file=/data/app/com.example.vishwa.imaginators-2/split_lib_slice_3_apk.apk --oat-file=/data/dalvik-cache/arm64/data@app@com.example.vishwa.imaginators-2@split_lib_slice_3_apk.apk@classes.dex) because non-0 exit status
07-23 19:22:39.711 22589-22589/com.example.vishwa.imaginators W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --non-interactive --runtime-arg -Xms64m --runtime-arg -Xmx512m -j2 --instruction-set-variant=generic --instruction-set-features=default --dex-file=/data/app/com.example.vishwa.imaginators-2/split_lib_slice_4_apk.apk --oat-file=/data/dalvik-cache/arm64/data@app@com.example.vishwa.imaginators-2@split_lib_slice_4_apk.apk@classes.dex) because non-0 exit status
07-23 19:22:39.774 22589-22589/com.example.vishwa.imaginators W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --non-interactive --runtime-arg -Xms64m --runtime-arg -Xmx512m -j2 --instruction-set-variant=generic --instruction-set-features=default --dex-file=/data/app/com.example.vishwa.imaginators-2/split_lib_slice_5_apk.apk --oat-file=/data/dalvik-cache/arm64/data@app@com.example.vishwa.imaginators-2@split_lib_slice_5_apk.apk@classes.dex) because non-0 exit status
07-23 19:22:39.844 22589-22589/com.example.vishwa.imaginators W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --non-interactive --runtime-arg -Xms64m --runtime-arg -Xmx512m -j2 --instruction-set-variant=generic --instruction-set-features=default --dex-file=/data/app/com.example.vishwa.imaginators-2/split_lib_slice_6_apk.apk --oat-file=/data/dalvik-cache/arm64/data@app@com.example.vishwa.imaginators-2@split_lib_slice_6_apk.apk@classes.dex) because non-0 exit status
07-23 19:22:39.904 22589-22589/com.example.vishwa.imaginators W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --non-interactive --runtime-arg -Xms64m --runtime-arg -Xmx512m -j2 --instruction-set-variant=generic --instruction-set-features=default --dex-file=/data/app/com.example.vishwa.imaginators-2/split_lib_slice_7_apk.apk --oat-file=/data/dalvik-cache/arm64/data@app@com.example.vishwa.imaginators-2@split_lib_slice_7_apk.apk@classes.dex) because non-0 exit status
07-23 19:22:39.965 22589-22589/com.example.vishwa.imaginators W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --non-interactive --runtime-arg -Xms64m --runtime-arg -Xmx512m -j2 --instruction-set-variant=generic --instruction-set-features=default --dex-file=/data/app/com.example.vishwa.imaginators-2/split_lib_slice_8_apk.apk --oat-file=/data/dalvik-cache/arm64/data@app@com.example.vishwa.imaginators-2@split_lib_slice_8_apk.apk@classes.dex) because non-0 exit status
07-23 19:22:40.033 22589-22589/com.example.vishwa.imaginators W/art: Failed execv(/system/bin/dex2oat --runtime-arg -classpath --runtime-arg  --instruction-set=arm64 --instruction-set-features=smp,a53 --runtime-arg -Xrelocate --boot-image=/system/framework/boot.art --non-interactive --runtime-arg -Xms64m --runtime-arg -Xmx512m -j2 --instruction-set-variant=generic --instruction-set-features=default --dex-file=/data/app/com.example.vishwa.imaginators-2/split_lib_slice_9_apk.apk --oat-file=/data/dalvik-cache/arm64/data@app@com.example.vishwa.imaginators-2@split_lib_slice_9_apk.apk@classes.dex) because non-0 exit status
07-23 19:22:40.043 22589-22589/com.example.vishwa.imaginators W/System: ClassLoader referenced unknown path: /data/app/com.example.vishwa.imaginators-2/lib/arm64
07-23 19:22:40.145 22589-22817/com.example.vishwa.imaginators D/com.facebook.FacebookSdk: getGraphApiVersion: v3.0
07-23 19:22:40.149 22589-22817/com.example.vishwa.imaginators I/DpmTcmClient: RegisterTcmMonitor from: com.android.okhttp.TcmIdleTimerMonitor
07-23 19:22:40.154 22589-22589/com.example.vishwa.imaginators I/InstantRun: starting instant run server: is main process
07-23 19:22:40.247 22589-22589/com.example.vishwa.imaginators W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
07-23 19:22:40.290 22589-22589/com.example.vishwa.imaginators D/AccessibilityManager: current package=com.example.vishwa.imaginators, accessibility manager mIsFinalEnabled=false, mOptimizeEnabled=false, mIsUiAutomationEnabled=false, mIsInterestedPackage=false
07-23 19:22:40.312 22589-22589/com.example.vishwa.imaginators V/BoostFramework: BoostFramework() : mPerf = com.qualcomm.qti.Performance@7199c39
BoostFramework() : mPerf = com.qualcomm.qti.Performance@97127e
07-23 19:22:40.462 22589-22589/com.example.vishwa.imaginators W/com.facebook.appevents.AppEventsLogger: activateApp events are being logged automatically. There's no need to call activateApp explicitly, this is safe to remove.
07-23 19:22:40.529 22589-22841/com.example.vishwa.imaginators D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
07-23 19:22:40.648 22589-22841/com.example.vishwa.imaginators I/Adreno: QUALCOMM build                   : a7823f5, I59a6815413
Build Date                       : 09/23/16
OpenGL ES Shader Compiler Version: XE031.07.00.00
Local Branch                     : mybranch22028469
Remote Branch                    : quic/LA.BR.1.3.3_rb2.26
Remote Branch                    : NONE
Reconstruct Branch               : NOTHING
07-23 19:22:40.684 22589-22824/com.example.vishwa.imaginators D/com.facebook.FacebookSdk: getGraphApiVersion: v3.0
07-23 19:22:40.688 22589-22824/com.example.vishwa.imaginators W/AnalyticsUserIDStore: initStore should have been called before calling setUserID
07-23 19:22:40.727 22589-22589/com.example.vishwa.imaginators W/art: Before Android 4.1, method int android.support.v7.widget.ListViewCompat.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
07-23 19:22:40.733 22589-22841/com.example.vishwa.imaginators I/OpenGLRenderer: Initialized EGL, version 1.4
07-23 19:22:40.783 22589-22841/com.example.vishwa.imaginators E/HAL: hw_get_module_by_class: module name gralloc
hw_get_module_by_class: module name gralloc
07-23 19:22:41.010 22589-22850/com.example.vishwa.imaginators D/com.facebook.FacebookSdk: getGraphApiVersion: v3.0
07-23 19:22:41.351 22589-22824/com.example.vishwa.imaginators D/com.facebook.FacebookSdk: getGraphApiVersion: v3.0
07-23 19:22:41.465 22589-22839/com.example.vishwa.imaginators I/Timeline: Timeline: Activity_launch_request time:459431007
07-23 19:22:41.507 22589-22589/com.example.vishwa.imaginators V/BoostFramework: BoostFramework() : mPerf = com.qualcomm.qti.Performance@bb9ef8e
07-23 19:22:41.508 22589-22589/com.example.vishwa.imaginators V/BoostFramework: BoostFramework() : mPerf = com.qualcomm.qti.Performance@afc73af
07-23 19:22:43.725 22589-22589/com.example.vishwa.imaginators I/Timeline: Timeline: Activity_launch_request time:459433267
07-23 19:22:43.781 22589-22589/com.example.vishwa.imaginators I/Timeline: Timeline: Activity_launch_request time:459433323
07-23 19:22:44.848 22589-22589/com.example.vishwa.imaginators D/com.facebook.FacebookSdk: getGraphApiVersion: v3.0
07-23 19:22:45.179 22589-22589/com.example.vishwa.imaginators D/com.facebook.FacebookSdk: getGraphApiVersion: v3.0

现在,该应用程序无法在正常模式下运行,即使我不在调试模式下运行,它也可以在调试模式下运行。

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

另一个链接问题的答案为我解决了这个问题。其here