Android Kotlin Accountkit-无法正常工作

时间:2018-09-18 00:02:39

标签: java android facebook kotlin account-kit

我已经在JAVA和kotlin中从多个教程和示例中进行过尝试,例如:https://github.com/fbsamples/account-kit-samples-for-android/tree/master/samples/AccountKitSimpleSample,但我无法使其正常工作!

这是我尝试的最新代码:

fun startRequest(){

    val intent = Intent(this, AccountKitActivity::class.java)
    val builder = AccountKitConfiguration.AccountKitConfigurationBuilder(LoginType.PHONE, AccountKitActivity.ResponseType.TOKEN)

    intent.putExtra(AccountKitActivity.ACCOUNT_KIT_ACTIVITY_CONFIGURATION, builder.build())

    startActivityForResult(intent, ACCOUNTKIT_REQUEST_CODE)
    Log.d("letsSee", "pikaboo1") // this is shown in the log
}


public override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
    Log.d("letsSee", "pikaboo2") // this not
    if (requestCode == ACCOUNTKIT_REQUEST_CODE){
        val loginResult: AccountKitLoginResult = data!!.getParcelableExtra(AccountKitLoginResult.RESULT_KEY)

        if(loginResult.getError() != null)
        {
            Log.d("letsSee", "error: " + loginResult.getError().toString())
        }
        else if(loginResult.wasCancelled())
        {
            Log.d("letsSee", "cancelled")
        }
        else
        {
            if(loginResult.getAccessToken() != null){
                val accountid = loginResult.getAccessToken()!!.getAccountId()
                Log.d("letsSee", "Success: " + accountid.toString())
            }else{
                Log.d("letsSee", "FAIL: " + loginResult.getAuthorizationCode()!!.substring(0,10))
            }
        }
    }
}

这是错误日志:

09-18 02:00:51.014 1102-1102/com.amoflirt.amoflirt E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.amoflirt.amoflirt, PID: 1102
    java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/api/Api$zzf;
        at com.google.android.gms.auth.api.Auth.<clinit>(Unknown Source:0)
        at com.facebook.accountkit.ui.AccountKitActivity.onCreate(AccountKitActivity.java:281)
        at android.app.Activity.performCreate(Activity.java:7174)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1220)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2910)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3032)
        at android.app.ActivityThread.-wrap11(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696)
        at android.os.Handler.dispatchMessage(Handler.java:105)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6944)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.common.api.Api$zzf" on path: DexPathList[[zip file "/data/app/com.amoflirt.amoflirt-wtMOEQEYlPaxtL74SS3EhA==/base.apk", zip file "/data/app/com.amoflirt.amoflirt-wtMOEQEYlPaxtL74SS3EhA==/split_lib_dependencies_apk.apk", zip file "/data/app/com.amoflirt.amoflirt-wtMOEQEYlPaxtL74SS3EhA==/split_lib_resources_apk.apk", zip file "/data/app/com.amoflirt.amoflirt-wtMOEQEYlPaxtL74SS3EhA==/split_lib_slice_0_apk.apk", zip file "/data/app/com.amoflirt.amoflirt-wtMOEQEYlPaxtL74SS3EhA==/split_lib_slice_1_apk.apk", zip file "/data/app/com.amoflirt.amoflirt-wtMOEQEYlPaxtL74SS3EhA==/split_lib_slice_2_apk.apk", zip file "/data/app/com.amoflirt.amoflirt-wtMOEQEYlPaxtL74SS3EhA==/split_lib_slice_3_apk.apk", zip file "/data/app/com.amoflirt.amoflirt-wtMOEQEYlPaxtL74SS3EhA==/split_lib_slice_4_apk.apk", zip file "/data/app/com.amoflirt.amoflirt-wtMOEQEYlPaxtL74SS3EhA==/split_lib_slice_5_apk.apk", zip file "/data/app/com.amoflirt.amoflirt-wtMOEQEYlPaxtL74SS3EhA==/split_lib_slice_6_apk.apk", zip file "/data/app/com.amoflirt.amoflirt-wtMOEQEYlPaxtL74SS3EhA==/split_lib_slice_7_apk.apk", zip file "/data/app/com.amoflirt.amoflirt-wtMOEQEYlPaxtL74SS3EhA==/split_lib_slice_8_apk.apk", zip file "/data/app/com.amoflirt.amoflirt-wtMOEQEYlPaxtL74SS3EhA==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.amoflirt.amoflirt-wtMOEQEYlPaxtL74SS3EhA==/lib/arm64, /system/lib64, /system/vendor/lib64]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:93)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        at com.google.android.gms.auth.api.Auth.<clinit>(Unknown Source:0) 
        at com.facebook.accountkit.ui.AccountKitActivity.onCreate(AccountKitActivity.java:281) 
        at android.app.Activity.performCreate(Activity.java:7174) 
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1220) 
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2910) 
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3032) 
        at android.app.ActivityThread.-wrap11(Unknown Source:0) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696) 
        at android.os.Handler.dispatchMessage(Handler.java:105) 
        at android.os.Looper.loop(Looper.java:164) 
        at android.app.ActivityThread.main(ActivityThread.java:6944) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374) 
        Suppressed: java.io.IOException: No original dex files found for dex location (arm64) /data/app/com.amoflirt.amoflirt-wtMOEQEYlPaxtL74SS3EhA==/split_lib_resources_apk.apk
        at dalvik.system.DexFile.openDexFileNative(Native Method)
        at dalvik.system.DexFile.openDexFile(DexFile.java:353)
        at dalvik.system.DexFile.<init>(DexFile.java:100)
        at dalvik.system.DexFile.<init>(DexFile.java:74)
        at dalvik.system.DexPathList.loadDexFile(DexPathList.java:374)
        at dalvik.system.DexPathList.makeDexElements(DexPathList.java:337)
        at dalvik.system.DexPathList.<init>(DexPathList.java:157)
        at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:65)
        at dalvik.system.PathClassLoader.<init>(PathClassLoader.java:64)
        at com.android.internal.os.PathClassLoaderFactory.createClassLoader(PathClassLoaderFactory.java:43)
        at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:69)
        at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:36)
        at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:678)
        at android.app.LoadedApk.getClassLoader(LoadedApk.java:711)
        at android.app.LoadedApk.getResources(LoadedApk.java:944)
09-18 02:00:51.015 1102-1102/com.amoflirt.amoflirt E/AndroidRuntime:     at android.app.ContextImpl.createAppContext(ContextImpl.java:2303)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5943)
        at android.app.ActivityThread.-wrap1(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1764)
                ... 6 more

我对这个可怕的垃圾感到绝望,已经浪费了2天

2 个答案:

答案 0 :(得分:0)

Halleluja我知道了:

https://github.com/evollu/react-native-fcm/issues/998

将googlePlayServicesVersion = 12.0.1添加到gradle.properties(我认为这是不必要的) 在android / build.gradle中添加了以下内容:

 allprojects {
    repositories {
    //start here
    configurations.all {
 resolutionStrategy.eachDependency { DependencyResolveDetails details ->
   def requested = details.requested
       if (requested.group == 'com.google.android.gms') {
          details.useVersion '12.0.1'
       }
       if (requested.group == 'com.google.firebase') {
          details.useVersion '12.0.1'
         }
       }
     }
    //end
     jcenter()
       maven {
         url "https://maven.google.com"
       }
     }
 }

这是我尝试的第1000000次修复,我99.999%的人确定它不会起作用,但它确实:D

答案 1 :(得分:0)

添加到您的build.gradle文件中:

implementation 'com.facebook.android:account-kit-sdk:4.37.0'
implementation "com.google.android.gms:play-services-auth-api-phone:16.0.0"
implementation 'com.google.android.gms:play-services-auth:16.0.1'
implementation 'com.google.android.gms:play-services-base:16.0.1'

然后它起作用。