Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NoClassDefFoundError: org/apache/commons/logging/LogFactory #476

Closed
emumair opened this issue Jun 8, 2018 · 57 comments
Closed

NoClassDefFoundError: org/apache/commons/logging/LogFactory #476

emumair opened this issue Jun 8, 2018 · 57 comments

Comments

@emumair
Copy link

emumair commented Jun 8, 2018

  • 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.

@minbi
Copy link
Contributor

minbi commented Jun 8, 2018

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.

@minbi minbi self-assigned this Jun 8, 2018
@minbi
Copy link
Contributor

minbi commented Jun 8, 2018

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

@marosseleng
Copy link

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

@elliott-accolade
Copy link

elliott-accolade commented Jun 28, 2018

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.+'

@karannaik
Copy link

karannaik commented Jul 7, 2018

Has anyone solved this problem yet?

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

@C0lumbo
Copy link

C0lumbo commented Jul 26, 2018

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.

@minbi
Copy link
Contributor

minbi commented Jul 30, 2018

Please add dependency for now:

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

@C0lumbo
Copy link

C0lumbo commented Jul 31, 2018

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.**

@charbgr
Copy link

charbgr commented Aug 7, 2018

We also have this issue.

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

@elliottj-accolade
Copy link

elliottj-accolade commented Aug 7, 2018

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

    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?

@elliottj-accolade
Copy link

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.

@emezias
Copy link

emezias commented Aug 10, 2018

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?
#265

@pavlospt
Copy link

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!

@emezias
Copy link

emezias commented Aug 10, 2018

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

@roshanrajaratnam
Copy link

+1

@emezias
Copy link

emezias commented Aug 14, 2018

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:+'
}

@dlazaro66
Copy link

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

@charbgr
Copy link

charbgr commented Aug 17, 2018

This is quite blocking!

@dwaynehoy
Copy link

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.

@mauricegavin
Copy link

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

@emezias
Copy link

emezias commented Aug 20, 2018

@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.

@minbi
Copy link
Contributor

minbi commented Aug 20, 2018

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

@emezias
Copy link

emezias commented Aug 21, 2018 via email

@minbi
Copy link
Contributor

minbi commented Aug 21, 2018

@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.

@emezias
Copy link

emezias commented Aug 21, 2018 via email

@DrewCarlson
Copy link

@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 minbi changed the title NoClassDefFoundError: org/apache/commons/logging/LogFactory during MobileAnalyticsManager initialization NoClassDefFoundError: org/apache/commons/logging/LogFactory Aug 21, 2018
@mutablealligator
Copy link
Contributor

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.

@mutablealligator
Copy link
Contributor

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.

@AnthonyUccello
Copy link

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.

@minbi
Copy link
Contributor

minbi commented Nov 8, 2018

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

@AnthonyUccello
Copy link

AnthonyUccello commented Nov 8, 2018

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)

@AnthonyUccello
Copy link

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

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

@mutablealligator
Copy link
Contributor

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

@minbi
Copy link
Contributor

minbi commented Nov 8, 2018

@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.

@AnthonyUccello
Copy link

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

@danielesegato
Copy link

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.

zaclimon added a commit to ApplETS/ETSMobile-Android2 that referenced this issue Jan 1, 2019
Fixes the following error:
java.lang.ClassNotFoundException: Didn't find class "org.apache.commons.logging.LogFactory"

Solution based on the following issue:
aws-amplify/aws-sdk-android#476
jamesonwilliams added a commit that referenced this issue Jul 14, 2020
The Android SDK uses HttpURLConnection as its HTTP runtime.
aws-android-sdk-core contains dead code that references the legacy
Apache HTTP Client used by the V1 Java SDK, from which this codebase
originates. The Apache HTTP client has considerable baggage on the
Android platform, and can cause runtime failures. In an effort to fully
remove it from the codebase, it is being removed from core.

As of this commit, Apache Logging is still a compile-time dependency in
core. If it is provided at runtime, it will be used. Otherwise, the SDK
will fallback to logging against the Android Log utility. This behavior
is discussed here: #476
jamesonwilliams added a commit that referenced this issue Jul 14, 2020
The Android SDK uses HttpURLConnection as its HTTP runtime.
aws-android-sdk-core contains dead code that references the legacy
Apache HTTP Client used by the V1 Java SDK, from which this codebase
originates. The Apache HTTP client has considerable baggage on the
Android platform, and can cause runtime failures. In an effort to fully
remove it from the codebase, it is being removed from core.

As of this commit, Apache Logging is still a compile-time dependency in
core. If it is provided at runtime, it will be used. Otherwise, the SDK
will fallback to logging against the Android Log utility. This behavior
is discussed here: #476
@sauravpradhan
Copy link

sauravpradhan commented Sep 21, 2020

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 ?

@raphkim
Copy link
Contributor

raphkim commented Sep 21, 2020

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.

@raphkim raphkim reopened this Sep 21, 2020
@jamesonwilliams
Copy link
Contributor

jamesonwilliams commented Sep 21, 2020

@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.

@sauravpradhan
Copy link

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.

@jamesonwilliams
Copy link
Contributor

jamesonwilliams commented Feb 18, 2021

All references to Apache Logging have been removed from the SDK as of 2.19.4. If you are encountering issue #476, the current recommendation is to update to the latest version of the SDK.

@jarve
Copy link

jarve commented Aug 23, 2021

No android. Latest version of your SDK today: 2.17.24. Just plain java and very easy code S3Client s3 = S3Client.builder()
.region(Region...)build();
ListBucketsResponse listBucketsResponse = s3.listBuckets();
listBucketsResponse.buckets().stream().forEach(x -> System.out.println(x.name()));
and
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at org.apache.http.conn.ssl.AbstractVerifier.(AbstractVerifier.java:61)
at org.apache.http.conn.ssl.AllowAllHostnameVerifier.(AllowAllHostnameVerifier.java:44)
at org.apache.http.conn.ssl.AllowAllHostnameVerifier.(AllowAllHostnameVerifier.java:46)
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.(SSLConnectionSocketFactory.java:151)
at software.amazon.awssdk.http.apache.ApacheHttpClient$ApacheConnectionManagerFactory.getPreferredSocketFactory(ApacheHttpClient.java:630)
at software.amazon.awssdk.http.apache.ApacheHttpClient$ApacheConnectionManagerFactory.create(ApacheHttpClient.java:609)
and adding
commons-logging
commons-logging
1.2

to my pom didn't help. I think it's common problem of the ApacheHttpClient but I have java 11 with better http client, why are you still using the apache one? I also used it too in the past but today?

@jiuzhou9
Copy link

jiuzhou9 commented Aug 24, 2021 via email

@LouieMiddleHawkeye
Copy link

No android. Latest version of your SDK today: 2.17.24. Just plain java and very easy code S3Client s3 = S3Client.builder() .region(Region...)build(); ListBucketsResponse listBucketsResponse = s3.listBuckets(); listBucketsResponse.buckets().stream().forEach(x -> System.out.println(x.name())); and Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory at org.apache.http.conn.ssl.AbstractVerifier.(AbstractVerifier.java:61) at org.apache.http.conn.ssl.AllowAllHostnameVerifier.(AllowAllHostnameVerifier.java:44) at org.apache.http.conn.ssl.AllowAllHostnameVerifier.(AllowAllHostnameVerifier.java:46) at org.apache.http.conn.ssl.SSLConnectionSocketFactory.(SSLConnectionSocketFactory.java:151) at software.amazon.awssdk.http.apache.ApacheHttpClient$ApacheConnectionManagerFactory.getPreferredSocketFactory(ApacheHttpClient.java:630) at software.amazon.awssdk.http.apache.ApacheHttpClient$ApacheConnectionManagerFactory.create(ApacheHttpClient.java:609) and adding commons-logging commons-logging 1.2 to my pom didn't help. I think it's common problem of the ApacheHttpClient but I have java 11 with better http client, why are you still using the apache one? I also used it too in the past but today?

@jarve Did you manage to fix this? I keep getting this trying to start a DynamoDBClient and I'm really stumped as to why.

@jarve
Copy link

jarve commented May 16, 2022

No, but I found go program called rclone to use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests