I've tried to initialize AWSMobileClient.defaultMobileClient()
from my AWS Mobile Hub sample project into my test project using this code:
if (AWSMobileClient.defaultMobileClient() == null) {
Log.e("MainActivity", "Initializing AWS Mobile Client...");
final ClientConfiguration clientConfiguration = new ClientConfiguration();
clientConfiguration.setUserAgent(AWSConfiguration.AWS_MOBILEHUB_USER_AGENT);
final IdentityManager identityManager = new IdentityManager(getApplicationContext(), clientConfiguration);
final AWSMobileClient awsClient =
new AWSMobileClient.Builder(getApplicationContext())
.withCognitoRegion(AWSConfiguration.AMAZON_COGNITO_REGION)
.withCognitoIdentityPoolID(AWSConfiguration.AMAZON_COGNITO_IDENTITY_POOL_ID)
.withIdentityManager(identityManager)
.withClientConfiguration(clientConfiguration)
.build();
AWSMobileClient.setDefaultMobileClient(awsClient);
}
When I opened the app in my device, I got this error log in the Android Studio:
09-21 13:01:34.596 28886-28886/com.intap.snspushtest E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.intap.snspushtest, PID: 28886
java.lang.IncompatibleClassChangeError: The method 'java.io.File android.support.v4.content.ContextCompat.getNoBackupFilesDir(android.content.Context)' was expected to be of type virtual but instead was found to be of type direct (declaration of 'com.google.android.gms.iid.zzd' appears in /data/app/com.intap.snspushtest-1/base.apk)
at com.google.android.gms.iid.zzd.zzeC(Unknown Source)
at com.google.android.gms.iid.zzd.<init>(Unknown Source)
at com.google.android.gms.iid.zzd.<init>(Unknown Source)
at com.google.android.gms.iid.InstanceID.zza(Unknown Source)
at com.google.android.gms.iid.InstanceID.getInstance(Unknown Source)
at com.amazonaws.mobile.push.GCMTokenHelper.<init>(GCMTokenHelper.java:44)
at com.amazonaws.mobile.AWSMobileClient.<init>(AWSMobileClient.java:121)
at com.amazonaws.mobile.AWSMobileClient.<init>(AWSMobileClient.java:24)
at com.amazonaws.mobile.AWSMobileClient$Builder.build(AWSMobileClient.java:101)
at com.intap.snspushtest.MainActivity.onCreate(MainActivity.java:43)
at android.app.Activity.performCreate(Activity.java:6876)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3206)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349)
at android.app.ActivityThread.access$1100(ActivityThread.java:221)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7224)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
The lines are as below.
AWSMobileClient.java:121
this.gcmTokenHelper = new GCMTokenHelper(context, AWSConfiguration.GOOGLE_CLOUD_MESSAGING_SENDER_ID);
AWSMobileClient.java:24
public class AWSMobileClient {
AWSMobileClient.java:101
return
new AWSMobileClient(applicationContext,
cognitoIdentityPoolID,
cognitoRegion,
identityManager,
clientConfiguration);
MainActivity.java:43
final AWSMobileClient awsClient =
new AWSMobileClient.Builder(getApplicationContext())
.withCognitoRegion(AWSConfiguration.AMAZON_COGNITO_REGION)
.withCognitoIdentityPoolID(AWSConfiguration.AMAZON_COGNITO_IDENTITY_POOL_ID)
.withIdentityManager(identityManager)
.withClientConfiguration(clientConfiguration)
.build();
I don't really understand what problem I am facing with, so could you please help me?
I have changed my Google Play Services library version from 9.0.0 to 9.0.1 and it solved it.