Android gradle build with firebase dependency has warnings (ignoring httpclient) - java

In my Android project which use firebase the gradle build shows this annoying warning:
WARNING: Dependency org.apache.httpcomponents:httpclient:4.0.1 is ignored for devDebug as it may be conflicting with the internal version provided by Android.
In case of problem, please repackage it with jarjar to change the class packages
i tryed adding the exclude option on the build.gradle but i had no luck
compile ('com.firebase:firebase-client-android:2.2.1') {
exclude module: 'org.apache.httpcomponents:httpclient:4.0.1' //IGNORED
}
i also tryed removing the version like suggested but the warning remains
compile ('com.firebase:firebase-client-android:2.2.1') {
exclude group:'org.apache.httpcomponents', module: 'httpclient' //SAME
}

I found the option to remove the warning
configurations {
compile.exclude group: "org.apache.httpcomponents", module: "httpclient"
}

If I am not mistaken this should be
compile ('com.firebase:firebase-client-android:2.2.1') {
exclude group:'org.apache.httpcomponents', module: 'httpclient'
}
version can be omitted.

Related

Trying to exclude transitive Log4j dependency

So I've seen other posts (eg. Can't use hbase-shaded-client jar because of its internal dependency to log4j-1.2.17(CVE-2019-1757)) stating that they have a way to exclude the transitive dependency of log4j:log4j:1.2.17 however if I run ./gradlew app:dependencies I can still see that the transitive dependency exists.
I have tried referring to the following migration doc https://logging.apache.org/log4j/2.x/manual/migration.html but Im not sure if this is just transferring the calls over from log4j 1.x over to 2.x at runtime or if its supposed to update the transitive dependency all together. I tried even excluding the transitive dependency and using slf4j instead in my build.gradle file like so:
compile ('custom-library-that-I-cant-change-code-in'), {
exclude group: 'log4j', module: 'log4j'
}
// https://mvnrepository.com/artifact/org.slf4j/log4j-over-slf4j
implementation 'org.slf4j:log4j-over-slf4j:1.7.35'
How can I make sure if this is even working, or at least not using that older log4j:log4j:1.2.17 or am I going about this all wrong and there is an easier way of doing this
To answer you first question the following exclude wasn't working for me as well,
compile ('custom-library-that-I-cant-change-code-in'), {
exclude group: 'log4j', module: 'log4j'
}
try this in your build.gradle it should work
configurations {
compile.exclude group: "log4j", module: "log4j"
}

gradle exclude specific jars from runtime dependencies

Is there a way to exclude specific jars from a group using Gradle? I have tried below code, but this removed all the jars of that group
configurations {
all*.exclude group: 'org.xxxx.xxxx'
}
My requirement is to remove only specific jars from the group, not all jars. This exercise we are doing to exclude transitive dependencies during runtime in our system.
thanks.
You can exclude all dependencies from a group, or only some modules of a group, in dependencies block:
dependencies {
/* -------------- SpringBoot without Tomcat ------------------- */
compile('org.springframework.boot:spring-boot-starter-web') {
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
}
}
I add link to the Gradle documentation explaining transitive dependencies in detail: https://docs.gradle.org/current/userguide/managing_transitive_dependencies.html

Failed to resolve: com.android.support:support-v4:26.0.2

when i use this library :
compile 'co.ronash.android:pushe-base:1.4.0'
I get this error in gradle:
Failed to resolve: com.android.support:support-v4:26.0.2
I can't fix it.
There is a solution to be there library Ignored
'com.android.support:support-v4:26.0.2' from 'co.ronash.android:pushe-base:1.4.0' ?
Because I have already compiled a newer version of support-v4 library.
All my dependencies code in gradle :
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha7'
compile 'com.android.support:appcompat-v7:26.0.0-alpha1'
compile 'com.android.support:support-v4:26.+' //--> its ok and no problem
compile 'uk.co.chrisjenx:calligraphy:2.2.0'
compile 'co.ronash.android:pushe-base:1.4.0' //--->this code is error Failed to resolve: com.android.support:support-v4:26.0.2
compile 'com.google.android.gms:play-services-gcm:11.0.4'
compile 'com.google.android.gms:play-services-location:11.0.4'
testCompile 'junit:junit:4.12'
}
There are a few reasons which can cause this kind of problem.
Checkout these solution, I guess it might help you:
1. Remove Pushe and try adding support-v4 library with version of 26.0.2 to make sure it gets downloaded and cached to your system.
compile 'com.android.support:support-v4:26.0.2' // or implementation
If it still can't be resolved then you have a problem getting it from it's repository server. checkout build.gradle(project:your_prj) and make sure this block is valid.
allprojects {
repositories {
google() // or maven { url 'https://maven.google.com/' } for lower gradles
jcenter()
}
}
If your country is included in sanction you might need to use a VPN to be able to get them. You can also use a proxy like Fod(also donate if you can since it's opensource) or shecan.
Remember all support libraries better be 26.0.2 to avoid conflict and crashing. Your support libraries are 26.0.0-alpha1 which is lower.
After you successfully added and cached support-v4 then try to add Pushe to your dependencies again.
! And also remember that pushe has a support-v4 bundled in it and it's not really needed for you to add it yourself
And Make sure you have
<uses-sdk tools:overrideLibrary="co.ronash.pushe" />
in you manifest. Therefore you can override it's libraries and dependencies.
At the end keep your SDK update.
Edit:
Current version of Pushe is using android support libraries. If you attend to use AndroidX be sure to enable jettifier in order to do runtime conversion.

Gradle compileJava fails due to missing excluded dependency

stupid question but I am a little lost here.
i exclude slf4j-api from configuration compile.
configurations {
compile.exclude module: "spring-boot-starter-tomcat"
compile.exclude module: "tomcat-embed-el"
compile.exclude module: "logback-classic"
compile.exclude module: "spring-boot-starter-logging"
compile.exclude module: "slf4j-api"
}
No I can't compile the classes anymore because of the missing slf4j dependency, which will be provided later by an container. I tried to add
compileOnly group:....
providedCompile group ....
provided (plugin by netflix)
but so far it is not working. always getting the error
can not find symbol org.slf4j....
import failed .....
so how do I add an compileOnly dependency in gradle that is recognized?
Regards
Mathias
have you tried compileOnly instead of compile.exclude module, like for servlet api it will be like this
compileOnly 'javax.servlet:servlet-api:2.5'
So in the end I excluded per module. If I have the time to write a script for this I will post it here. Thanks to everybody
Regards
Mathias

add "compile 'com.jakewharton:butterknife:8.5.1" lead to conflict

add "compile 'com.jakewharton:butterknife:8.5.1" lead to conflict:
com.android.build.api.transform.TransformException:
java.util.zip.ZipException: duplicate entry:
android/support/v4/hardware/display/DisplayManagerCompat$JellybeanMr1Impl.class
How to deal with it?Thanks.
You can try to exclude the dependency.
compile('compile 'com.jakewharton:butterknife:8.5.1') {
exclude group: 'com.android.support', module: 'support-v4'
}
The reason for this error is that your project and butterknife both depend on the android support library, but the versions used are out of sync.
As Modge answered, it has a conflict when compiling the butterknife library on the grade file. However, you must exclude the support-compat module in order to avoid the conflict. You may define your dependencies as follows.
dependencies {
...
// Support version library may differ from yours
compile 'com.android.support:support-v4:22.2.1'
compile ('com.jakewharton:butterknife:8.5.1') {
exclude module: 'support-compat'
}
...
}

Categories

Resources