Android kotlin accountkit - 无法正常工作



我已经从多个教程和示例中在 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 天

哈利路亚 我明白了:

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

添加到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'

然后它起作用了。

最新更新