Android Cloud vision [duplicate] - android

I'm trying to add the following dependency but it is ignore. I can't understand how to resolve it please help me Thank you.
Dependency
compile 'com.google.apis:google-api-services-drive:v2-rev170-1.20.0'
Waring for ignoring dependency
Warning:Dependency org.apache.httpcomponents:httpclient:4.0.1 is ignored for debug 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 Warning:Dependency
org.apache.httpcomponents:httpclient:4.0.1 is ignored for release 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

You can exclude dependencies in the build.gradle file of your module.
compile('com.google.apis:google-api-services-drive:v2-rev170-1.20.0') {
exclude module: 'httpclient' //by artifact name
exclude group: 'org.apache.httpcomponents' //by group
exclude group: 'org.apache.httpcomponents', module: 'httpclient' //by both name and group
}

Exclude module httpclient from all configurations. Add this code in the build.gradle file:
configurations {
compile.exclude group: "org.apache.httpcomponents", module: "httpclient"
}

Use the following code to exclude the conflicting modules from the google APIs library.
compile 'com.google.apis:google-api-services-drive:v2-rev170-1.20.0' {
exclude module: 'httpcore'
exclude module: 'httpclient'
}

Related

commons-logging defines classes that conflict with classes now provided by Android after Android Studio Update

I have updated Android Studio to version 3 and now seems unable to compile my project previously compiled without errors.
The error message is the follow
Error: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]
The dependencies are
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:27.0.0'
compile 'com.android.support:design:27.0.0'
compile 'com.google.api-client:google-api-client-android:1.23.0' exclude module: 'httpclient'
compile 'com.google.http-client:google-http-client-gson:1.23.0' exclude module: 'httpclient'
compile 'com.google.firebase:firebase-core:11.4.2'
}
and error seems caused by
compile 'com.google.api-client:google-api-client-android:1.23.0' exclude module: 'httpclient'
compile 'com.google.http-client:google-http-client-gson:1.23.0' exclude module: 'httpclient'
I already use exclude module: 'httpclient'
So why It doesn't compile?
Is this a bug of Android Studio 3 and\or included com.android.tools.build:gradle:3.0.0 plugin or I'm missing something? With the previous version no problem to compile exactly the same project.
Add to build.gradle located in app module
configurations {
all {
exclude module: 'httpclient'
}
}
If the problem is with commons-logging then it must be excluded too.
Add the following code in app/build.gradle
configurations {
all {
exclude module: 'httpclient'
exclude module: 'commons-logging'
}
}
Got the same issue. I have done below changes
configurations {
all{
exclude group: 'commons-logging', module: 'commons-logging'
exclude group: 'org.apache.httpcomponents'
}
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'org/apache/http/version.properties'
exclude 'org/apache/http/client/version.properties'
}
You should replace "compile" with "implementation" as it's deprecated in the latest gradle and exlude "org.apache.httpcomponents" from Google api client libraries:
implementation('com.google.api-client:google-api-client-android:1.23.0') {
exclude group: 'org.apache.httpcomponents'
}
implementation('com.google.http-client:google-http-client-gson:1.23.0') {
exclude group: 'org.apache.httpcomponents'
}
this solution was found here:
https://developers.google.com/google-apps/activity/v1/quickstart/android
Run in terminal, inside project folder:
./gradlew app:dependencies > dependencies.txt
Then check dependencies.txt to find who is using conflictive dependencies and act accordingly (check for updates, get rid of it, or use exclude as suggested by #Silverstorm)
If you want to continue with async-http then add below following code only in app/build.gradle
configurations {
all {
exclude module: 'commons-logging'
}
}
As 'org.apache.httpcomponents:httpclient:4.3.3' is deprecated after SDKversion 23 so
replace this:
compile 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
with
compile 'org.apache.httpcomponents:httpclient:4.3.3'
I received these two errors today.
1. 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.
2. 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.
After struggling for sometime, I figured that I was using a Firebase library which was causing these errors.
implementation platform('com.google.firebase:firebase-bom:29.2.0')
So, I updated it:
implementation platform('com.google.firebase:firebase-bom:29.2.1')
And Invalidated Caches and Restarted the project and it worked like a charm.
Earlier BOM version of Firebase was also working fine.
implementation platform('com.google.firebase:firebase-bom:29.1.0')
Please don't update Firebase BOM version: 29.2.0
I removed commons-logging as suggested above, of course it crashed on some phone with Fatal Exception: java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/commons/logging/LogFactory;. How can Android claim the commons-logging is conflicting with Android API when the Android API doesn't contain any of those classes?!? There is no org.apache.commons.logging at https://developer.android.com/reference/packages :facepalm:
I've added back implementation 'commons-logging:commons-logging:1.0.4' to the build.gradle - Android Studio underlines it with red but gradle compiles happily. :facepalm:
Android :triple_facepalm:
if you are facing this issue because of org.apache.httpcomponents:httpmime dependency, then use this in your app level build.gradle file:
implementation('org.apache.httpcomponents:httpmime:4.5.12') {
exclude group: 'org.apache.httpcomponents', module: 'httpclient'
}
implementation "org.apache.httpcomponents:httpcore:4.4.13"
I had to join multiple solutions from here. This is what worked for me:
configurations {
all*.exclude group: 'com.google.guava', module: 'listenablefuture'
configureEach {
exclude module: 'httpclient'
exclude module: 'commons-logging'
exclude group: 'commons-logging', module: 'commons-logging'
exclude group: 'org.apache.httpcomponents'
}
}
Add this then sync your gradle
configurations {
all*.exclude group: 'com.google.guava', module: 'listenablefuture'
all*.exclude module: 'httpclient'
all*.exclude module: 'commons-logging'
}
in my case android studio couldn't recognize "httpclient"
so i couldn't use #Silverstorm answer.
instead found another answer:
Error: json defines classes that conflict with classes now provided by Android
which implies to add below could in app build.gradle:
configurations {
all {
exclude group: 'org.json', module: 'json'
}
}

Gradle DSL method not found: 'exclude()'

I am working in Android Studio and when I added the line in build.gradle file
dependencies {
compile files('libs/poi-ooxml-schemas-3.12-20150511-a.jar'){
exclude group: 'stax', module: 'stax-api'
}
}
I caught the error:
Gradle DSL method not found: 'exclude()'
What is the reason of the error?
The way you defined the dependency, you applied the closure to files instead of compile.
files('libs/poi-ooxml-schemas-3.12-20150511-a.jar'){
exclude group: 'stax', module: 'stax-api'
}
Instead you have to make sure to apply the closure to compile directly.
compile(files('libs/poi-ooxml-schemas-3.12-20150511-a.jar')){
exclude group: 'stax', module: 'stax-api'
}
But I doubt it's necessary at all. Groups and modules are part of the Maven system and the JAR file itself doesn't have this information to exclude.

How to exclude 'jar' file from External Library

I am getting httpclient-android-4.3.5.1.jar file with one of the aar file that I am adding in my dependencies.
I want to exclude this jar from this dependency, because this is giving me duplicate library error message.
I have tried many things, from
exclude group: 'org.apache.httpcomponents', module: 'httpclient-android'
to
{exclude module: "httpclient-android-4.3.5.1"}
but nothing is helping, the '.jarfile is still there and part ofSDK`
Did you try this also?:
configurations { all { exclude module: 'httpclient' exclude module: 'httpcore' } }

java.util.zip.ZipException: duplicate entry: android/support/v4/view/MotionEventCompatEclair.class

I'm new to android studio and am trying to import a project from eclipse but I feel like i am running into every single problem possible. The error I'm currently getting is:
Error:Execution failed for task ':jobFlexwithInvoice:packageAllDebugClassesForMultiDex'.
> java.util.zip.ZipException: duplicate entry: android/support/v4/view/MotionEventCompatEclair.class
Ive seen similar answers to problems like here and here. But i think I need more help because its just not going away. I've added the exception to just about everything in my build.gradle file, including the actual support 4v dependency just for kicks, and am still getting this error. And also I have multiple build.gradle files because of included projects? It seems like the project build.gradle file can be ignored, I just have to add the exceptions to the module build.gradle files? (which is annoying when someone says to add something to the build.gradle file, im not always sure which one)
Anyway, here are the dependencies sections of each of my build.gradle files as they currently are:
myApp:
dependencies {
compile ('com.android.support:multidex:1.0.0'){
exclude module: 'support-v4'
}
compile project(':facebook') {
exclude module: 'support-v4'
}
compile project(':apptentive')
compile project(':androidsdkui'){
exclude module: 'support-v4'
}
compile ('com.google.android.gms:play-services:+'){
exclude module: 'support-v4'
}
compile files('libs/android-support-v13.jar') {
exclude module: 'support-v4'
}
compile files('libs/DynamicPDF.jar')
compile files('libs/picasso-2.5.0.jar')
compile ('com.android.support:support-v4:22.0.0'){
exclude module: 'support-v4'
}
}
facebook:
dependencies {
compile files('libs/bolts-android-1.2.1.jar')
compile ('com.android.support:support-v4:22.0.0'){
exclude module: 'support-v4'
}
}
androidsdkui:
dependencies {
compile files('libs/appboy.jar')
compile ('com.android.support:support-v4:22.0.0'){
exclude module: 'support-v4'
}
}
there is also an apptentive build.gradle file but it does not have any dependencies. Before adding all of these exceptions I was getting the same error as the one in the first link, now the only difference is its android/support/v4/view/MotionEventCompatEclair.class instead of android/support/v4/util/TimeUtils.class
If there is a way to see where the duplicates are coming from that would be great too, I was unable to find anything with a quick google search.
I updated the question so you can see some of the ways I was doing things wrong. Some of my projects included support v4 and I wasn't excluding them right. The proper way to exclude things from projects is:
compile (project(':facebook')) {
exclude module: 'support-v4'
}
you have to put the extra set of parenthesis around everything after compile. Im assuming the same goes for excluding things from files
ie.
compile file(myfile.jar)
would become
compile (file(myfile.jar)) {
exclude module: 'support-v4'
}
Could you try adding the following in the top-level build.gradle file inside allprojects element? It should look something like below.
allprojects {
configurations {
all*.exclude group: 'com.android.support', module: 'support-v4'
}
}
Hope this helps.

Android Gradle Dependency conflict with internal version provided by Android

Possible duplicate of this question, although the solution did not help me.
I hate copy/paste all source code but seems in gradle there is no way :( since this is the 3rd day that gradle staffing me around I put my codes here and my apology for putting so much code...
I have three projects in my main project. Therefore my settings.gradle looks like this:
include ':booking-sdk'
include ':booking-app-lib'
include ':booking-app'
and my main build.gradle (in root of project) looks like this:
buildscript {
repositories {
jcenter()
mavenCentral()
maven { url 'http://download.crashlytics.com/maven' }
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1.+'
classpath 'com.github.jcandksolutions.gradle:android-unit-test:2.1.1'
}
}
allprojects {
repositories {
jcenter()
mavenCentral()
maven { url 'http://download.crashlytics.com/maven' }
maven { url 'https://zendesk.artifactoryonline.com/zendesk/repo' }
}
}
ext {
ANDROID_SUPPORT = 'com.android.support:support-v4:20.0.0'
CRASHLYTICS = 'com.crashlytics.android:crashlytics:1.+'
androidConfiguration = {
compileSdkVersion 21
buildToolsVersion '21.1.2'
defaultConfig {
minSdkVersion 14
targetSdkVersion 21
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
packagingOptions {
exclude 'values/com_crashlytics_export_strings.xml'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'LICENSE.txt'
}
lintOptions {
abortOnError false
absolutePaths false
lintConfig file("lint.xml")
}
sourceSets {
main {
manifest.srcFile 'src/main/AndroidManifest.xml'
java.srcDirs = ['src/main/java']
resources.srcDirs = ['src/main/resources']
aidl.srcDirs = ['src/main/java']
renderscript.srcDirs = ['src/main/java']
res.srcDirs = ['src/main/res']
assets.srcDirs = ['src/main/assets']
java {
exclude 'com/booking_1/passenger/LibraryConfigurationConstants.java'
exclude 'com/booking_2/passenger/ProductFlavorConstants.java'
}
}
}
signingConfigs {
debug {
storeFile file("$rootProject.projectDir/debug.keystore")
storePassword "android"
keyAlias "androiddebugkey"
keyPassword "android"
}
release {
storeFile file("$rootProject.projectDir/booking-androd-prod.keystore")
storePassword System.getenv("PASSWORD")
keyAlias System.getenv("ALIAS")
keyPassword System.getenv("PASSWORD")
}
}
}
}
For doing Unit test by Robolectric and Instrument test I am following Decard-Gradle project that I tested and works successfully.
booking-sdk is the project that holds business logic of app. It's structure is like this:
-booking-sdk
-/build
-/src
- booking_1 (flavour 1)
- booking_2 (flavour 2)
- main
- test
- build.gradle
I have same package name under /src/main/java and /src/test/java. Finally, build.gradle of booking-sdk looks like this:
apply plugin: 'com.android.library'
android androidConfiguration
android {
publishNonDefault true
productFlavors {
booking_1 { }
booking_2 { }
}
}
dependencies {
repositories {
mavenCentral()
}
compile ANDROID_SUPPORT
compile CRASHLYTICS
compile 'com.google.code.gson:gson:2.3'
compile 'com.squareup.retrofit:retrofit:1.7.0'
compile 'com.google.android.gms:play-services:6.5.87'
compile 'com.squareup.okhttp:okhttp:2.1.0'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.1.0'
compile 'com.squareup.picasso:picasso:2.4.0'
compile 'com.squareup:otto:1.3.5'
compile 'org.apache.commons:commons-lang3:3.3.2'
compile files('src/main/libs/GeoPIP4J.jar')
// Robolectric
testCompile 'junit:junit:4.12'
testCompile 'org.robolectric:robolectric:2.4'
testCompile 'org.hamcrest:hamcrest-core:1.1'
testCompile 'org.hamcrest:hamcrest-library:1.1'
testCompile 'org.hamcrest:hamcrest-integration:1.1'
// TODO: requires special build of robolectric right now. working on this...
androidTestCompile('org.robolectric:robolectric:2.4') {
exclude module: 'classworlds'
exclude module: 'commons-logging'
exclude module: 'httpclient'
exclude module: 'maven-artifact'
exclude module: 'maven-artifact-manager'
exclude module: 'maven-error-diagnostics'
exclude module: 'maven-model'
exclude module: 'maven-project'
exclude module: 'maven-settings'
exclude module: 'plexus-container-default'
exclude module: 'plexus-interpolation'
exclude module: 'plexus-utils'
exclude module: 'wagon-file'
exclude module: 'wagon-http-lightweight'
exclude module: 'wagon-provider-api'
}
}
When I run clean command the result is:
./gradlew :booking-sdk:clean
WARNING: Dependency commons-logging:commons-logging:1.1.1 is ignored for booking_1DebugUnitTest 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
WARNING: Dependency org.apache.httpcomponents:httpclient:4.0.3 is ignored for booking_1DebugUnitTest 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
WARNING: Dependency commons-logging:commons-logging:1.1.1 is ignored for booking_1ReleaseUnitTest 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
WARNING: Dependency org.apache.httpcomponents:httpclient:4.0.3 is ignored for booking_1ReleaseUnitTest 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
WARNING: Dependency commons-logging:commons-logging:1.1.1 is ignored for booking_1DebugUnitTest 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
WARNING: Dependency org.apache.httpcomponents:httpclient:4.0.3 is ignored for booking_1DebugUnitTest 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
WARNING: Dependency commons-logging:commons-logging:1.1.1 is ignored for booking_1ReleaseUnitTest 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
WARNING: Dependency org.apache.httpcomponents:httpclient:4.0.3 is ignored for booking_1ReleaseUnitTest 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
:booking-sdk:clean
BUILD SUCCESSFUL
Total time: 4.83 secs
Error happens when I run ./gradlew :passenger-sdk:check code to see unit test result. I'm getting above outputs first then a lot of errors like this:
...
:booking-sdk:compileBookingDebugUnitTestJava
/Users/admin/Desktop/android/booking/booking-sdk/src/test/java/com/booking/passenger/db/dao/BookingDAOTest.java:3: error: package com.booking.passenger.db.providers does not exist
import com.booking.passenger.db.providers.BookingContentProvider;
It is basically saying all my imports do not exist while they do exists and I have no error in my code file and all imports recognised by class.
Any Idea would be appreciated. Thanks.
OK, Geadle is f*king horrible although is powerful tool.
For your reference if you fall in same trouble this is my experience. Since I'm not sure my findings are absolutely right please correct me if I'm wrong.
I found that it is not possible to put your test folder under library projects. I wanted to have src/test/java for every project libraries and run my test cases like ./gradlew :booking-sdk:test. However, by moving this package to main application (in my case booking-app) and also moving related files from build.gradle of booking-sdk to build.gradle of booking-app I could see test case results.
I found exclude modules from dependencies don't work. The solution that I found is using configuration.
Like this:
configurations {
all*.exclude module: 'classworlds'
all*.exclude module: 'commons-logging'
all*.exclude module: 'httpclient'
all*.exclude module: 'maven-artifact'
all*.exclude module: 'maven-artifact-manager'
all*.exclude module: 'maven-error-diagnostics'
all*.exclude module: 'maven-model'
all*.exclude module: 'maven-project'
all*.exclude module: 'maven-settings'
all*.exclude module: 'plexus-container-default'
all*.exclude module: 'plexus-interpolation'
all*.exclude module: 'plexus-utils'
all*.exclude module: 'wagon-file'
all*.exclude module: 'wagon-http-lightweight'
all*.exclude module: 'wagon-provider-api'
}
Hope it helps.

Categories

Resources