程序问答   发布时间:2022-06-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了AWSMobile 与 Amplify大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决AWSMobile 与 Amplify?

开发过程中遇到AWSMobile 与 Amplify的问题如何解决?下面主要结合日常开发的经验,给出你关于AWSMobile 与 Amplify的解决方法建议,希望对你解决AWSMobile 与 Amplify有所启发或帮助;

我最近从一个项目中继承了一些旧代码。它被重新用作 ATAK(AndroID Tactical Assault Kit)插件,它需要使用 AWS Amplify 从 AWS S3 上传和下载文件。代码的原始创建者使用 AWS Amplify 上传文件。

现在,当我尝试在 Cli 中设置 AWS amplify(遵循 AWS 移动开发指南)时,我注意到运行 amplify init、amplify add auth、amplify add storage 和 amplify add API 时一切顺利。没关系。

接下来,我将依赖项添加到 build.gradle (:app) 文件内的 Gradle 文件中。这也工作正常并同步。

现在,代码实际上从未超过如下所示的 AWS.configure 部分:

            Amplify.addplugin(new AWSCognitoAuthPlugin());
            Amplify.addplugin(new AWSCognitoAuthPlugin());
            Amplify.addplugin(new AWSS3StoragePlugin());
            com.atakmap.coremap.log.Log.i(TAG,"Amplify Plugin configure!");
            com.atakmap.coremap.log.Log.i(TAG,"Amplify: (plugin == null) == " + Boolean.toString(plugin == null));
            Amplify.configure(plugin);

            com.atakmap.coremap.log.Log.i(TAG,"Amplify Plugin configure Afterwards!!");
            androID.util.Log.i("MyAmplifyApp","Initialized Amplify");
        } catch (AmplifyException error) {
            androID.util.Log.e("MyAmplifyApp","Could not initialize Amplify",error);
        }
2021-04-13 15:09:58.824 27642-27642/com.atakmap.app.civ E/MyAmplifyApp: Could not initialize Amplify
    AmplifyException {message=Failed to instantiate AWSMobileClIEnt,cause=java.lang.NullPointerException: Attempt to invoke virtual method 'androID.content.Context androID.content.Context.getApplicationContext()' on a null object reference,recoverySuggestion=See attached exception for more details}
        at com.amplifyframework.auth.cognito.AWSCognitoAuthPlugin.configure(AWSCognitoAuthPlugin.java:87)
        at com.amplifyframework.core.category.category.configure(category.java:13)
        at com.amplifyframework.core.Amplify.configure(Amplify.java:17)
        at com.amplifyframework.core.Amplify.configure(Amplify.java:1)
        at com.atakmap.androID.helloworld.recyclervIEw.RecyclerVIEwDropDown.<init>(RecyclerVIEwDropDown.java:200)
        at com.atakmap.androID.helloworld.HelloWorldDropDownReceiver.<init>(HelloWorldDropDownReceiver.java:653)
        at com.atakmap.androID.helloworld.HelloWorldMapComponent.onCreate(HelloWorldMapComponent.java:254)
        at com.atakmap.androID.helloworld.plugin.HelloWorldlifecycle.onCreate(HelloWorldlifecycle.java:78)
        at com.atak.plugins.impl.lifecycleMapComponent$2.run(Sourcefile:142)
        at androID.os.Handler.handleCallback(Handler.java:873)
        at androID.os.Handler.dispatchMessage(Handler.java:99)
        at androID.os.Looper.loop(Looper.java:193)
        at androID.app.ActivityThread.main(ActivityThread.java:6669)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.androID.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:858)
     Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'androID.content.Context androID.content.Context.getApplicationContext()' on a null object reference
        at com.amazonaws.mobile.auth.core.IDentityManager.<init>(IDentityManager.java:207)
        at com.amazonaws.mobile.clIEnt.AWSMobileClIEnt$2.run(AWSMobileClIEnt.java:482)
        at com.amazonaws.mobile.clIEnt.internal.InternalCallback$1.run(InternalCallback.java:101)
        at java.lang.Thread.run(Thread.java:764)

我有几个问题。

AWS Mobile 似乎已被弃用。

如果导致问题的代码与 AWS Mobile 相关,是否有办法绕过此错误而不必使用 AWSMobile,如果是,我应该在哪里查看?

解决方法

AWS Mobile 似乎已被弃用。

您正在使用 AWS Amplify,截至 2021 年,这是最新一代产品。

Amplify.addPlugin(new AWSCognitoAuthPlugin());
Amplify.addPlugin(new AWSCognitoAuthPlugin());

看起来您要添加此插件两次;您应该只添加一次独特的插件。

在 CLI 中设置 AWS 放大

请注意,Amplify Storage 类别需要 Amplify Auth 类别。你也跑amplify add auth了吗? CLI 将在 app/src/main/res/raw/amplifyconfiguration.json 生成一个文件。检查此文件以确保它包含有关身份验证和存储的信息。

最后——

Amplify.configure(plugin);

上面的配置方法是针对 Android Context。我不清楚传入的是什么,但它有一个奇怪的名称(“plugin”。)

大佬总结

以上是大佬教程为你收集整理的AWSMobile 与 Amplify全部内容,希望文章能够帮你解决AWSMobile 与 Amplify所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: