Aws-sdk-android: NoClassDefFoundError: org/apache/commons/logging/LogFactory

Created on 8 Jun 2018  ·  53Comments  ·  Source: aws-amplify/aws-sdk-android

  • What service are you using?
    Mobile Analytics

  • In what version of SDK are you facing the problem?
    implementation 'com.amazonaws:aws-android-sdk-core:2.4.2'
    implementation 'com.amazonaws:aws-android-sdk-mobileanalytics:2.4.2'

  • Is the issue limited to Simulators / Actual Devices?
    No

  • Can your problem be resolved if you bump to a higher version of SDK?
    No

  • Is this problem related to specific Android/OS version?
    Yes, API level 28

Runs well on version <= 27 but throws exception when app is run on version 28.

Crash occurs at:

CognitoCachingCredentialsProvider credentialsProvider = new CognitoCachingCredentialsProvider(context, BuildConfig.AMAZON_IDENTITY_POOL_ID, region);

  • Stacktrace
06-07 15:58:10.189 5075-5075 E/AndroidRuntime: FATAL EXCEPTION: main
    java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/commons/logging/LogFactory;
        at com.amazonaws.util.VersionInfoUtils.<clinit>(VersionInfoUtils.java:41)
        at com.amazonaws.util.VersionInfoUtils.getVersion(VersionInfoUtils.java:54)
        at com.amazonaws.auth.CognitoCachingCredentialsProvider.<clinit>(CognitoCachingCredentialsProvider.java:81)
        at com.umair.myapp.analytics.AmazonMobileAnalytics.initialize(AmazonMobileAnalytics.java:41)
        at com.umair.myapp.MyApplication.onCreate(MyApplication.java:48)
        at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1154)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5858)
        at android.app.ActivityThread.access$1000(ActivityThread.java:197)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1634)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6642)
        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.ClassNotFoundException: Didn't find class "org.apache.commons.logging.LogFactory" on path: DexPathList[[zip file "/data/app/com.umair.myapp-n6G1DHuwf6SphItF6XvOPw==/base.apk"],nativeLibraryDirectories=[/data/app/com.umair.myapp-n6G1DHuwf6SphItF6XvOPw==/lib/x86, /system/lib]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:126)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        at com.amazonaws.util.VersionInfoUtils.<clinit>(VersionInfoUtils.java:41) 
        at com.amazonaws.util.VersionInfoUtils.getVersion(VersionInfoUtils.java:54) 
        at com.amazonaws.auth.CognitoCachingCredentialsProvider.<clinit>(CognitoCachingCredentialsProvider.java:81) 
        at com.umair.myapp.analytics.AmazonMobileAnalytics.initialize(AmazonMobileAnalytics.java:41) 
        at com.umair.myapp.MyApplication.onCreate(MyApplication.java:48) 
        at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1154) 
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5858) 
        at android.app.ActivityThread.access$1000(ActivityThread.java:197) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1634) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:193) 
        at android.app.ActivityThread.main(ActivityThread.java:6642) 
        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) 
        Suppressed: java.io.IOException: No original dex files found for dex location /data/app/com.umair.myapp-n6G1DHuwf6SphItF6XvOPw==/split_lib_resources_apk.apk
        at dalvik.system.DexFile.openDexFileNative(Native Method)
        at dalvik.system.DexFile.openDexFile(DexFile.java:354)
        at dalvik.system.DexFile.<init>(DexFile.java:101)
        at dalvik.system.DexFile.<init>(DexFile.java:75)
        at dalvik.system.DexPathList.loadDexFile(DexPathList.java:377)
        at dalvik.system.DexPathList.makeDexElements(DexPathList.java:340)
        at dalvik.system.DexPathList.<init>(DexPathList.java:160)
        at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:66)
        at dalvik.system.PathClassLoader.<init>(PathClassLoader.java:64)
        at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:73)
        at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:88)
        at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:74)
        at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:40)
06-07 15:58:10.191 5075-5075 E/AndroidRuntime:     at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:727)
        at android.app.LoadedApk.getClassLoader(LoadedApk.java:772)
        at android.app.LoadedApk.getResources(LoadedApk.java:994)
        at android.app.ContextImpl.createAppContext(ContextImpl.java:2345)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5736)
                ... 8 more

Saw a similar issue here but the given solution is not working for me.

testCompile 'commons-logging:commons-logging:1.1.1'
and
testImplementation 'commons-logging:commons-logging:1.1.1'
both are not working.

Most helpful comment

Android Pie runtime has a crash that's not on earlier Androids. Is anybody at Amazon on a fix for it?

All 53 comments

Hi @emumair ,

Thanks for reporting this issue. Currently, it looks like we may be able to remove this dependency.
We will investigate and reply here when we have more information.

Also, Mobile Analytics is no longer recommended, please use AWS Pinpoint instead.

👍 Same issue here, now with
implementation 'com.amazonaws:aws-android-sdk-sns:2.6.23'

Having this issue with both
api 'com.amazonaws:aws-android-sdk-kinesis:2.2.+'
api 'com.amazonaws:aws-android-sdk-core:2.2.+'

and
api 'com.amazonaws:aws-android-sdk-kinesis:2.6.+'
api 'com.amazonaws:aws-android-sdk-core:2.6.+'

Has anyone solved this problem yet?

I reduced my targetSdk and compileSdk to 27. And it worked!

I'm also affected by this issue. The crash occurs downstream from the call to new AWSKinesisFirehose. I'm using:

aws-android-sdk-core:2.6.+
aws-android-sdk-auth-core:2.6.+
aws-android-sdk-kinesis:2.6.+

Release date for Android P is likely to be 3rd week of August if it follows the pattern of Oreo and Nougat. It would be frustrating if this issue prevented us from using Android P at launch. Thanks.

Please add dependency for now:

implementation 'commons-logging:commons-logging:1.1.1'

implementation 'commons-logging:commons-logging:1.1.1'

is working for me, thanks. Initially I had problems in my submission build, I had to add this lot into my proguard rules to get that working.

-keep class org.apache.log.** { *; }
-dontwarn org.apache.log.**
-keep class org.apache.log4j.** { *; }
-dontwarn org.apache.log4j.**
-keep class org.apache.avalon.** { *; }
-dontwarn org.apache.avalon.**
-keep class javax.servlet.** { *; }
-dontwarn javax.servlet.**

We also have this issue.

Including implementation 'commons-logging:commons-logging:1.1.1' will cause other bugs to other libraries.

We are having this issue now when attempting to release a signed build:

```Error: commons-logging defines classes that conflict with classes now provided by Android. Solutions include finding newer versions or alternative libraries that don't have the same problem (for example, for httpclient use HttpUrlConnection or okhttp instead), or repackaging the library using something like jarjar. [DuplicatePlatformClasses]
implementation 'commons-logging:commons-logging:1.1.1'
~~~~~~~

Explanation for issues of type "DuplicatePlatformClasses":
There are a number of libraries that duplicate not just functionality of
the Android platform but using the exact same class names as the ones
provided in Android -- for example the apache http classes. This can lead
to unexpected crashes.

To solve this, you need to either find a newer version of the library which
no longer has this problem, or to repackage the library (and all of its
dependencies) using something like the jarjar tool, or finally, rewriting
the code to use different APIs (for example, for http code, consider using
HttpUrlConnection or a library like okhttp).

1 errors, 0 warnings
:app:lintVitalProdRelease FAILED
```

This is including the proguard stuff that C0lumbo recommended.

So we're still stuck releasing for Android Pie and targeting API level 28. Any ETA on getting this fixed, considering that Google just started rolling out Android Pie to Pixel devices, etc?

Also there's this: https://developer.android.com/about/versions/pie/android-9.0-changes-all#apache-nonp

An app can be affected if it uses a non-standard ClassLoader that explicitly delegates to the system ClassLoader. These apps need to delegate to the app ClassLoader instead when looking for classes in org.apache.http.*. If they delegate to the system ClassLoader, the apps will fail on Android 9 or higher with a NoClassDefFoundError, because those classes are no longer known to the system ClassLoader. To prevent similar problems in the future, apps should in general load classes through the app ClassLoader rather than accessing the system ClassLoader directly.

+1

I'm using:
api 'commons-logging:commons-logging:1.1.2'
in my dependencies so that the S3 APIs do not fail with the same NoClassDefFound. This is not the right answer.

What about this closed issue?
https://github.com/aws/aws-sdk-android/issues/265

The correct answer on this case is to just use Java's Logger or even create a wrapper class around it with some of the missing functionality such as logger.isDebugEnabled() and just use that one! There is no reason to have that dependency from Apache when it was clear that Apache libraries were being removed from Android since Android 6!

Android Pie runtime has a crash that's not on earlier Androids. Is anybody at Amazon on a fix for it?

+1

almost forgot about this issue - these lines in build.gradle seem to work with the S3 SDK so that the Android P runtime does not crash

api 'com.amazonaws:aws-android-sdk-core:$version'
api ('com.amazonaws:aws-android-sdk-s3:$version'){
exclude module: 'commons-logging:commons-logging:+'
}

@minbi I'm having the same issue here; Is there any release coming soon that solves this problem?

This is quite blocking!

Adding 'commons-logging:commons-logging:1.1.1' as a dependency causes crashes in other libraries like the Google Maps SDK. This is blocking a scheduled release.

It's blocking us from uploading and downloading files to S3 in production on Android P devices.

@minbi The problem with locking #265 is that this issue refers to MobileAnalyticsManager while the earlier, closed issue refers to a problem with client initialization. The problem I am experiencing is with the S3 client fetching keys. Developers using the S3 APIs might be led to believe that the NoClassDefFoundError on the S3 client is solved when it is not.

@emezias , correct me if I am wrong, but aren't these both related to the usage of commons logging in the SDK?

You might say instead that these reports are related to compatibility with
Android 9. The problem is in the Amazon SDK logging. They report the
problem using different packages in the SDK that are crashing with the
latest Android. The Android apps are not using the commons logging objects.

It looks like there was an earlier pull request and fix for #265. This
would mean you have both a new bug and a regression.

On Mon, Aug 20, 2018, 7:11 PM minbi notifications@github.com wrote:

@emezias https://github.com/emezias , correct me if I am wrong, but
aren't these both related to the usage of commons logging in the SDK?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/aws/aws-sdk-android/issues/476#issuecomment-414493237,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAyqsZZdyRho8Hf7k8H8HTobwnfhzZ4sks5uS0IQgaJpZM4UfhVC
.

@emezias , we are treating this as the issue for tracking the commons logging issue for all SDKs under AWS Android SDK: S3, Cognito, Mobile Analytics from whichever library they surface.

Feel free to open another issue if your issue differs significantly. Closed issue are not monitored, but I saw a bit of activity, so I locked it with a redirect to this issue.

Thanks @minbi. If that is the case the issue title referring to the
MobileAnalyticsManager is specific and confusing. Can you correct it?
Developers that do not use Amazon for analytics are affected. Issue 265 on
the S3 Amazon client was filed before this one and is still a problem.

On Mon, Aug 20, 2018, 8:35 PM minbi notifications@github.com wrote:

@emezias https://github.com/emezias , we are treating this as the issue
for tracking the commons logging issue for all SDKs under AWS Android SDK.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/aws/aws-sdk-android/issues/476#issuecomment-414509217,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAyqsWHyeUkExMoQS92PLMRa4bGjedzbks5uS1W5gaJpZM4UfhVC
.

@minbi It would be valuable in the future to include the reason and more explicit direction when stopping an active conversation.

Additionally if this is to be the primary issue for the bug: updating the title, providing details (in summary) of the root cause, and adding any insight into the status of your investigation would be appreciated.

@minbi any reason why this is taking so long? Is there anything blocking you?

Also about this:

Also, Mobile Analytics is no longer recommended, please use AWS Pinpoint instead.

We tried to migrate to Pinpoint but the same issue seems to be there using the version:
com.amazonaws:aws-android-sdk-pinpoint:2.6.28

@minbi As other people said, this issue is blocking everyone to have Android Pie support. If there's anything we can do to help you out, just ping us 👍

看看这个
缺少资源包:


commons-logging
commons-logging
1.2

Any news on the progress of the resolution of this issue?

@minbi Can we get some form of update on this issue?

Adding
implementation group: 'commons-logging', name: 'commons-logging', version: '1.2'
Solved our problem, but definitely waiting for a fix

UPDATE #1:
As was stated above me, the app now has other bugs related to the apache thing. This is definitely not the solution.

UPDATE #2:
I ended up targeting to API 27, cancelling all other attempts

@minbi this is blocking us and many other developers from adding support for Android P. Is a fix in the works?

This is not just Mobile Analytics related. In the app I'm working on, we are using Kinesis and Cognito only, and it is still occurring.

Thanks for investigating!

This issue is blocking us as well from supporting Android P. Any news on the status of the fix would be greatly appreciated!

Am I the only one that I don't find anything related to apache logging in that release tag?

@pavlospt you're not alone, it wasn't fixed in the release v2.6.29, it still uses it :(

Hi everyone,

We are working on a fix for this issue. Please see #521 for a preview of the change and to post any comments or bug reports about the fix.

@minbi Great! Is there any ETA on releasing this?

We have fixed this in 2.6.30. The maven release is in progress. The changes are pushed to GitHub. Apologies for the delay in getting the fix. Please upgrade to the latest and let us know if it fixes the issue.

Description of the fix: We introduced a LogFactory and Log interface in the SDK (aws-android-sdk-core) and made Apache Commons Logging and android.util.Log as implementations of the Log interface. By default, the LogFactory checks if Apache Commons Logging is present, if so, it will use the Commons Logging as the logger, else it will use android.util.Log.

Customers who want to use Apache Commons Logging can import it as an explicit dependency and LogFactory will use it. Please feel free to provide feedback on this fix. We will be happy to take in the recommendations. Closing the issue.

You will get a warning say not to use the commons library
screen shot 2018-11-08 at 3 22 32 pm

However, for my project, even though it warned against it, it still worked. Not an ideal solution, and as others have mentioned might cause other issues depending on your other dependencies.

@AnthonyUccello Do you need commons logging for your project? If not, then you can let it default to Android logging instead.

I spoke too soon, my build server threw this error:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:lint'.
> Lint found errors in the project; aborting build.

 Fix the issues identified by lint, or add the following to your build script to proceed with errors:
 ...
 android {
     lintOptions {
         abortOnError false
     }
 }
 ...

 Errors found:

 /godata/pipelines/android-pr/app/build.gradle:263: Error: commons-logging defines classes that conflict with classes now provided by Android. Solutions include finding newer versions or alternative libraries that don't have the same problem (for example, for httpclient use HttpUrlConnection or okhttp instead), or repackaging the library using something like jarjar. [DuplicatePlatformClasses]
     implementation 'commons-logging:commons-logging:1.1.1'

@minbi Can you clarify how I let it default to Android logging instead? This is failing when I try to mock an object (failing with the original error this thread is about)

The issue is, in the VersionInfoUtils there are missing libraries:

screen shot 2018-11-08 at 4 09 41 pm

@AnthonyUccello Can you upgrade to the latest 2.7.+ and see if it fixes the issue? We fixed this issue in 2.6.30.

@emumair This is how the code branches the logic if else. Remove that dependency. We only included the option to go to commons logging for those that need or depend on functionality provided by commons logging.

@kvasukib Yes! That did fix it! Thank you!

Guys the proper workaround is the same you need for using Google Maps:

Add this inside your Application in the App manifest

        <uses-library
            android:name="org.apache.http.legacy"
            android:required="false"/>

still has to be fixed in the library.

I am using : implementation 'com.amazonaws:aws-android-sdk-s3:2.19.0' and can still see the issue. Can anyone here let me know if this was fixed and released ? Anybody faced this issue recently ?

Hi @sauravpradhan ,
Thank you for letting us know regarding this issue. Looks like the bug got resurfaced after our recent dependency cleanup. We will investigate a fix for the next release.

@sauravpradhan @raphkim Ah yes. In #2014, I set out to remove our dependency on the Apache HTTP client. As part of that, I've removed this line from the aws-android-sdk-core:

useLibrary 'org.apache.http.legacy'

I suspect that this has removed the _logging_ dependency from the runtime classpath, as well.

Some workarounds for the consumer are suggested in this StackOverflow thread.

I believe our next step here will be to remove the Apache Logging dependency entirely.

I cannot move to a SDK < 28, more over the problem is when we progaurd the app. Debug apk and non progaurded relase apk's are fine . Adding the implementation of commons or even including jar did not work out for me. And since it was fixed long back , I was really looking for my project configs as all comments suggested it's fixed. @raphkim Thanks for reopening this.

Was this page helpful?
0 / 5 - 0 ratings