I have recently inherited some old code from a project. It is being repurposed a plugin for ATAK (Android Tactical Assault Kit) and it needs to use AWS Amplify to upload and download files from AWS S3. The original creator of the code used AWS amplify for uploading files.
Now, when I try setting up AWS amplify in the CLI (following the AWS Mobile Development Guide), I notice that everything goes smoothly with running amplify init, amplify add auth, amplify add storage, and amplify add API. That's all fine.
Next, I added the dependencies to my Gradle file inside of my build.gradle (:app) file. That also worked fine and synced.
Now, the code never actually gets past the AWS.configure part shown below:
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)
I have a few questions.
AWS Mobile seems to be deprecated.
If the code that is causing the issue refers to AWS Mobile, is there a way to get around this error without having to use AWSMobile, and if so, where should I look?