Aws-sdk-android: Could not check if ACCESS_NETWORK_STATE permission is available warning in 2.17.1

Created on 12 Aug 2020  路  29Comments  路  Source: aws-amplify/aws-sdk-android

Describe the bug
Could not check if ACCESS_NETWORK_STATE permission is available warning is shown in logcat for 2.17.1. It looks like AWSMobileClient is looking for the android.support.v4.content.ContextCompat class but it has been replaced with AndroidX in 2.17.

To Reproduce
Updated aws-sdk-android to version 2.17.1 and app calls awsMobileClient.currentUserState()

com.my.app W/AWSMobileClient: Could not check if ACCESS_NETWORK_STATE permission is available.
    java.lang.ClassNotFoundException: android.support.v4.content.ContextCompat
        at java.lang.Class.classForName(Native Method)
        at java.lang.Class.forName(Class.java:454)
        at java.lang.Class.forName(Class.java:379)
        at com.amazonaws.mobile.client.AWSMobileClient.isNetworkAvailable(AWSMobileClient.java:771)
        at com.amazonaws.mobile.client.AWSMobileClient.getUserStateDetails(AWSMobileClient.java:983)
        at com.amazonaws.mobile.client.AWSMobileClient$5.run(AWSMobileClient.java:845)
        at com.amazonaws.mobile.client.AWSMobileClient$5.run(AWSMobileClient.java:842)
        at com.amazonaws.mobile.client.internal.ReturningRunnable.await(ReturningRunnable.java:31)
        at com.amazonaws.mobile.client.AWSMobileClient.currentUserState(AWSMobileClient.java:824)
AWSMobileClient Bug

Most helpful comment

@raphkim @jamesonwilliams Amplify Android 1.3.2 fixes this for me - thanks

All 29 comments

I am also experiencing a similar issue.

W/AWSMobileClient: Could not check if ACCESS_NETWORK_STATE permission is available.
    java.lang.ClassNotFoundException: android.support.v4.content.ContextCompat
        at java.lang.Class.classForName(Native Method)
        at java.lang.Class.forName(Class.java:454)
        at java.lang.Class.forName(Class.java:379)
        at com.amazonaws.mobile.client.AWSMobileClient.isNetworkAvailable(AWSMobileClient.java:771)
        at com.amazonaws.mobile.client.AWSMobileClient.getUserStateDetails(AWSMobileClient.java:983)
        at com.amazonaws.mobile.client.AWSMobileClient$5.run(AWSMobileClient.java:845)
        at com.amazonaws.mobile.client.AWSMobileClient$5.run(AWSMobileClient.java:842)
        at com.amazonaws.mobile.client.internal.ReturningRunnable$1.run(ReturningRunnable.java:44)
        at java.lang.Thread.run(Thread.java:919)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.content.ContextCompat" on path: DexPathList[[zip file "/data/app/com.predictram.socialtrade-xspnsR5VeUK9N76oa-XxrQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.predictram.socialtrade-xspnsR5VeUK9N76oa-XxrQ==/lib/arm64, /system/lib64, /system/product/lib64]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        at java.lang.Class.classForName(Native Method)聽
        at java.lang.Class.forName(Class.java:454)聽
        at java.lang.Class.forName(Class.java:379)聽
        at com.amazonaws.mobile.client.AWSMobileClient.isNetworkAvailable(AWSMobileClient.java:771)聽
        at com.amazonaws.mobile.client.AWSMobileClient.getUserStateDetails(AWSMobileClient.java:983)聽
        at com.amazonaws.mobile.client.AWSMobileClient$5.run(AWSMobileClient.java:845)聽
        at com.amazonaws.mobile.client.AWSMobileClient$5.run(AWSMobileClient.java:842)聽
        at com.amazonaws.mobile.client.internal.ReturningRunnable$1.run(ReturningRunnable.java:44)聽
        at java.lang.Thread.run(Thread.java:919)聽

I have following lines in my manifest file

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

I think this error is because of some other underlying error.

Hey guys @hexdecimal16 @RecargoJereld ,
Did you find anything for this?

Hey guys @hexdecimal16 @RecargoJereld ,
Did you find anything for this?

Unfortunately no, I switched to firebase, for now, it works better for android I guess. But most probably this is because of some other error. Try making a new project and set up properly.

Hey guys @hexdecimal16 @RecargoJereld ,
Did you find anything for this?

Unfortunately no, I switched to firebase, for now, it works better for android I guess. But most probably this is because of some other error. Try making a new project and set up properly.

Thanks a lot. That's sad, I've been trying to complete a personal project for a year and I always run into those problems. I might, as well, switch to firebase.

What Android version are you using? For Android 6.0 (API version 23) and higher, you have to request permission at runtime in addition to adding it to the manifest.

https://developer.android.com/guide/topics/permissions/overview#runtime_requests_android_60_and_higher

@hexdecimal16 I'm using v2.16.13 in the mean time.

@rjuliano I don't think it's a permissions issue. The exception thrown is a ClassNotFoundException. A SecurityException is thrown when a call requires a permission and the permission has not been granted. ACCESS_NETWORK_STATE is a normal level permission and doesn't require runtime approval.

Out of curiosity, have you tried adding a dependency on the android support library for whatever android version you're using?

AWSMobileClient is looking for the android.support.v4.content.ContextCompat class but it has been replaced with AndroidX. A possible fix is also to try to look for androidx.core.content.ContextCompat if the former returns no class found. I suspect the API for both are similar if not the same (disclaimer - highly uninformed take); if that is so, it should be an easy fix

Does 2.18.0 release contain a fix for this particular issue?

edit: seems like it's still in 2.18.0

/AWSMobileClient(12322): Could not check if ACCESS_NETWORK_STATE permission is available.
W/AWSMobileClient(12322): java.lang.ClassNotFoundException: android.support.v4.content.ContextCompat
W/AWSMobileClient(12322):   at java.lang.Class.classForName(Native Method)
W/AWSMobileClient(12322):   at java.lang.Class.forName(Class.java:453)
W/AWSMobileClient(12322):   at java.lang.Class.forName(Class.java:378)
W/AWSMobileClient(12322):   at com.amazonaws.mobile.client.AWSMobileClient.isNetworkAvailable(AWSMobileClient.java:771)
W/AWSMobileClient(12322):   at com.amazonaws.mobile.client.AWSMobileClient.getUserStateDetails(AWSMobileClient.java:983)
W/AWSMobileClient(12322):   at com.amazonaws.mobile.client.AWSMobileClient$5.run(AWSMobileClient.java:845)
W/AWSMobileClient(12322):   at com.amazonaws.mobile.client.AWSMobileClient$5.run(AWSMobileClient.java:842)
W/AWSMobileClient(12322):   at com.amazonaws.mobile.client.internal.ReturningRunnable$1.run(ReturningRunnable.java:44)
W/AWSMobileClient(12322):   at java.lang.Thread.run(Thread.java:764)
W/AWSMobileClient(12322): Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.content.ContextCompat" on path: DexPathList[[zip file "/system/framework/org.apache.http.legacy.boot.jar", zip file "/data/app/com.junto.juntobetamobile.dev-Hs4iXranyH9x_NJFvNHzQg==/base.apk"],nativeLibraryDirectories=[/data/app/com.junto.juntobetamobile.dev-Hs4iXranyH9x_NJFvNHzQg==/lib/arm64, /data/app/com.junto.juntobetamobile.dev-Hs4iXranyH9x_NJFvNHzQg==/base.apk!/lib/arm64-v8a, /system/lib64, /system/vendor/lib64]]

Does not, offending line is here

What is interesting is that the call to ContextCompat.checkSelfPermission uses the imported androidx.core.content.ContextCompat so I fail to understand what Class.forName("android.support.v4.content.ContextCompat") does in that block.

minSDK for androidx is 14 which corresponds to that of aws-android-sdk-mobile-client and so I don't believe supporting older versions was the intention

You can use android.enableJetifier=true in gradle.properties before an issue will fixed

You can use android.enableJetifier=true in gradle.properties before an issue will fixed

It doesn't solve the issue.

What is interesting is that the call to ContextCompat.checkSelfPermission uses the imported androidx.core.content.ContextCompat so I fail to understand what Class.forName("android.support.v4.content.ContextCompat") does in that block.

Thank you @saltonmassally for identifying the issue; I agree with you that this line appears to have no purpose. Here's a PR to remove it. https://github.com/aws-amplify/aws-sdk-android/pull/2091

I am using the 2.18.0.
But I still can find the warning log.

2020-09-09 12:43:19.493 2686-2870/co.spoonme W/AWSMobileClient: Could not check if ACCESS_NETWORK_STATE permission is available.
    java.lang.ClassNotFoundException: android.support.v4.content.ContextCompat
        at java.lang.Class.classForName(Native Method)
        at java.lang.Class.forName(Class.java:454)
        at java.lang.Class.forName(Class.java:379)
        at com.amazonaws.mobile.client.AWSMobileClient.isNetworkAvailable(AWSMobileClient.java:771)
        at com.amazonaws.mobile.client.AWSMobileClient.getUserStateDetails(AWSMobileClient.java:983)
        at com.amazonaws.mobile.client.AWSMobileClient.waitForSignIn(AWSMobileClient.java:923)
        at com.amazonaws.mobile.client.AWSMobileClient.getCredentials(AWSMobileClient.java:364)
        at com.amazonaws.services.pinpoint.AmazonPinpointClient.invoke(AmazonPinpointClient.java:4068)
        at com.amazonaws.services.pinpoint.AmazonPinpointClient.putEvents(AmazonPinpointClient.java:3118)
        at com.amazonaws.mobileconnectors.pinpoint.internal.event.EventRecorder.submitEventsAndEndpoint(EventRecorder.java:384)
        at com.amazonaws.mobileconnectors.pinpoint.internal.event.EventRecorder.submitEventsAndEndpoint(EventRecorder.java:363)
        at com.amazonaws.mobileconnectors.pinpoint.internal.event.EventRecorder.processEvents(EventRecorder.java:334)
        at com.amazonaws.mobileconnectors.pinpoint.internal.event.EventRecorder$1.run(EventRecorder.java:247)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:919)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.content.ContextCompat" on path: DexPathList[[zip file "/data/app/co.spoonme-K4UMYQeugasD7RTbSo9AEQ==/base.apk"],nativeLibraryDirectories=[/data/app/co.spoonme-K4UMYQeugasD7RTbSo9AEQ==/lib/arm64, /data/app/co.spoonme-K4UMYQeugasD7RTbSo9AEQ==/base.apk!/lib/arm64-v8a, /system/lib64]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        at java.lang.Class.classForName(Native Method)聽
        at java.lang.Class.forName(Class.java:454)聽
        at java.lang.Class.forName(Class.java:379)聽
        at com.amazonaws.mobile.client.AWSMobileClient.isNetworkAvailable(AWSMobileClient.java:771)聽
        at com.amazonaws.mobile.client.AWSMobileClient.getUserStateDetails(AWSMobileClient.java:983)聽
        at com.amazonaws.mobile.client.AWSMobileClient.waitForSignIn(AWSMobileClient.java:923)聽
        at com.amazonaws.mobile.client.AWSMobileClient.getCredentials(AWSMobileClient.java:364)聽
        at com.amazonaws.services.pinpoint.AmazonPinpointClient.invoke(AmazonPinpointClient.java:4068)聽
        at com.amazonaws.services.pinpoint.AmazonPinpointClient.putEvents(AmazonPinpointClient.java:3118)聽
        at com.amazonaws.mobileconnectors.pinpoint.internal.event.EventRecorder.submitEventsAndEndpoint(EventRecorder.java:384)聽
        at com.amazonaws.mobileconnectors.pinpoint.internal.event.EventRecorder.submitEventsAndEndpoint(EventRecorder.java:363)聽
        at com.amazonaws.mobileconnectors.pinpoint.internal.event.EventRecorder.processEvents(EventRecorder.java:334)聽
        at com.amazonaws.mobileconnectors.pinpoint.internal.event.EventRecorder$1.run(EventRecorder.java:247)聽
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)聽
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)聽
        at java.lang.Thread.run(Thread.java:919)聽

What should I do?

@richardmcclellan Are we doing a release this week? This issue has been fixed for 15 days; can we do a 2.18.1?

Yes, I am planning to do a release, hopefully tomorrow, if not Friday, so the fix for this should be in it!

2.19.0 has been released, and contains the fix for this issue: https://github.com/aws-amplify/aws-sdk-android/releases/tag/release_v2.19.0

@richardmcclellan We have the same problem in AWS Amplify for Android when I'm using GraphQL. Would you please fix that as well? I'm getting the same error.

2020-09-14 15:58:45.034 13752-13834/com.spendlee.dev W/AWSMobileClient: Could not check if ACCESS_NETWORK_STATE permission is available.
    java.lang.ClassNotFoundException: android.support.v4.content.ContextCompat
        at java.lang.Class.classForName(Native Method)
        at java.lang.Class.forName(Class.java:453)
        at java.lang.Class.forName(Class.java:378)
        at com.amazonaws.mobile.client.AWSMobileClient.isNetworkAvailable(AWSMobileClient.java:771)
        at com.amazonaws.mobile.client.AWSMobileClient.getUserStateDetails(AWSMobileClient.java:983)
        at com.amazonaws.mobile.client.AWSMobileClient$5.run(AWSMobileClient.java:845)
        at com.amazonaws.mobile.client.AWSMobileClient$5.run(AWSMobileClient.java:842)
        at com.amazonaws.mobile.client.internal.ReturningRunnable$1.run(ReturningRunnable.java:44)
        at java.lang.Thread.run(Thread.java:764)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.content.ContextCompat" on path: DexPathList[[zip file "/data/app/com.spendlee.dev-kMppz6q4B32cH-kwXu3lvg==/base.apk"],nativeLibraryDirectories=[/data/app/com.spendlee.dev-kMppz6q4B32cH-kwXu3lvg==/lib/x86, /system/lib, /vendor/lib]]
        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 java.lang.Class.classForName(Native Method)聽
        at java.lang.Class.forName(Class.java:453)聽
        at java.lang.Class.forName(Class.java:378)聽
        at com.amazonaws.mobile.client.AWSMobileClient.isNetworkAvailable(AWSMobileClient.java:771)聽
        at com.amazonaws.mobile.client.AWSMobileClient.getUserStateDetails(AWSMobileClient.java:983)聽
        at com.amazonaws.mobile.client.AWSMobileClient$5.run(AWSMobileClient.java:845)聽
        at com.amazonaws.mobile.client.AWSMobileClient$5.run(AWSMobileClient.java:842)聽
        at com.amazonaws.mobile.client.internal.ReturningRunnable$1.run(ReturningRunnable.java:44)聽
        at java.lang.Thread.run(Thread.java:764)

I think you need to use this new version in your amplify-android project and make a release as we have same problem there. https://github.com/aws-amplify/amplify-android/issues/827

@azisoli The next Amplify Android release will reference the SDK version 2.19.0.

@jamesonwilliams any ETA ? or are you waiting for other changes to be released at the same time as that one?

@jamesonwilliams and any estimation when this release will happen?

Hi @sebsto @azisoli ,

We are currently waiting on other important bug fixes and improvements to be merged into the mainline before releasing Amplify 1.3.2. We cannot give an exact timeline, but the release will be coming very soon!

@raphkim i'm using api(graphql) and i'm calling Amplify.API.mutate(ModelMutation.update(profile) )
and it return response with prevoius data and when i check dynamodb there is no changes in database on cloud and the only error that i receive in logs is this one that we mention here . so could this be the problem? or should be something else?

@azisoli Please feel free to re-open aws-amplify/amplify-android#827 if the issue you are experiencing is not resolved after the release.

@raphkim @jamesonwilliams Amplify Android 1.3.2 fixes this for me - thanks

@sebsto @raphkim i've tried new version but again update is not working for me

Amplify.API.mutate(   ModelMutation.update(profile))

it returns result with previous data and i see these in result:

((GraphQLResponse)response).data=Expecting an element; looking at ERROR_ELEMENT '(1,27) in /fragment.kt
((java.util.ArrayList)((PaginatedResult)((GraphQLResponse)response).data).items).get(0) =Expecting an element; looking at ERROR_ELEMENT '(1,67) in /fragment.kt

@azisoli that looks like a different issue. Could you open a separate issue in the amplify-android repo? https://github.com/aws-amplify/amplify-android/issues/new

Was this page helpful?
0 / 5 - 0 ratings