我最近从一个项目中继承了一些旧代码。它正在被重新用作 ATAK(Android 战术突击工具包)的插件,它需要使用 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,如果是,我应该在哪里查看?