Cannot compile anymore with gradle 3.6.2
farindk opened this issue · 11 comments
The recent update to gradle 3.6.2 added a new lint check that now blocks using the nextcloud android library because of the commons-httpclient
library conflict (see #411).
Error output is:
Error: httpclient 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-httpclient:commons-httpclient:3.1@jar" // remove after entire switch to lib v2
~~~~~~~~~~
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).
2 errors, 0 warnings
Only workarounds so far is to stay with the old gradle 3.6.1 or switch off the lint errors. Both are no long-term solutions for production code.
Yes. It was me who proposed to add this as a workaround :-)
But with gradle 3.6.2 this is not enough anymore.
Hm. With https://github.com/nextcloud/android it is still working and there we also use 3.6.2.
Is your project somewhere available?
No, it is a private project. Forgot to say: you have to compile in release mode. Otherwise lint is not running.
We run lint on every PR, and it does not complain…
I cannot imagine a reason why it should behave different in our android app…
Is this still valid?
Yes, I still have to add the following to disable the error.
buildTypes {
release {
minifyEnabled true
lintOptions {
abortOnError false
}
}
}
Can you test it with a new sample project? If this then happens also there, then please share it, so we can have a look together…
Here is a very simple test application. It is an Android Studio starting template. I just changed the app/build.gradle
.
LintErrorTestApp.zip
You'll have to change the release signing config as I obviously did not include my keys.
Then I'm building with Android Studio 4.0:
LintErrorTestApp$ ./gradlew assembleRelease
> Task :app:lintVitalRelease FAILED
LintErrorTestApp/app/build.gradle: 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]
LintErrorTestApp/app/build.gradle:81: Error: httpclient 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-httpclient:commons-httpclient:3.1@jar" // remove after entire switch to lib v2
~~~~~~~~~~
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).
2 errors, 0 warnings
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:lintVitalRelease'.
> Lint found fatal errors while assembling a release target.
To proceed, either fix the issues identified by lint, or modify your build script as follows:
...
android {
lintOptions {
checkReleaseBuilds false
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError false
}
}
...
It seems that it is conflicting because of:
implementation 'com.google.http-client:google-http-client-gson:1.26.0'
On Nextcloud Files we do use
implementation 'com.google.code.gson:gson:2.8.6'
Thanks, that solved it for me.