Vikash Kumar
Vikash Kumar

Reputation: 145

gradle build warning when running app, cant run app

I am quite new to android and cant understand this error.When sync the gradle file, android studio is exiting without any error but when I am trying to build the app and run it it gives 2 warnings as:

Information:Gradle tasks [:app:generateDebugSources, :app:generateDebugAndroidTestSources]

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

.......

my gradle file is this:

apply plugin: 'com.android.application'

repositories {
    maven {
        url 'http://google-api-client-libraries.appspot.com/mavenrepo'
    }
    mavenCentral()
    mavenLocal()

}

 android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "in.cornerstores.cornerfresh"
        minSdkVersion 14
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.0.0'
    compile 'com.google.android.gms:play-services:7.0.0'
    compile 'com.android.support:support-v4:22.0.0'
    compile 'com.android.support:recyclerview-v7:21.0.3'
    compile 'com.facebook.android:facebook-android-sdk:4.0.0'
    compile([group: 'com.google.api-client', name: 'google-api-client-android', version: '1.20.0'])
    compile([group: 'com.appspot.corner_fresh', name: 'fresh_api', version: 'v1-1.20.0-SNAPSHOT'])
    compile('com.google.api-client:google-api-client:1.18.0-rc') {
        // Exclude artifacts that the Android SDK/Runtime provides.
        exclude group: 'xpp3', module: 'shared'
        exclude group: 'org.apache.httpcomponents', module: 'httpclient'
        exclude group: 'junit', module: 'junit'
        exclude group: 'com.google.android', module: 'android'
    }

    // Add the Android extensions for the Google API client library.
    // This will automatically include play services as long as you have download that library
    // from the Android SDK manager.
    // Add the Android extensions for the Google API client library.
    compile('com.google.api-client:google-api-client-android:1.18.0-rc') {
        // Exclude play services, since we're not using this yet.
        exclude(group: 'com.google.android.gms:play-services', module: 'google-play-services')
    }
    // END Google APIs
    // The following client libraries make HTTP/JSON on Android easier.
    // Android extensions for Google HTTP Client.
    compile('com.google.http-client:google-http-client-android:1.18.0-rc') {
        exclude(group: 'com.google.android', module: 'android')
    }
    // This is used by the Google HTTP client library.
    compile 'com.google.guava:guava:18.0'
    compile files('libs/fresh_api-v1-1.20.0-SNAPSHOT.jar')

}

I tried everything I can find on stackoverflow but still it is showing the error. Couldn't find any proper answer to this. Kindly suggest the solution. I am stuck in my project due to this. Thanks

Upvotes: 2

Views: 3394

Answers (3)

sivi
sivi

Reputation: 11114

In my case I had to exlude it twice like so .. I don't think it's too complicated but it can be be confusing. I think it's better to solve those warning beacause they may come back in weird forms afterwards.

compile ('com.google.apis:google-api-services-urlshortener:v1-rev47-1.22.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
}

compile ('com.google.api-client:google-api-client-android:1.21.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
}

Upvotes: 0

Christian
Christian

Reputation: 4641

Even if this question is quite old, it is unresolved and I struggled myself for some time to find the reason in a similar configuration.

You excluded the duplicated imports in the libraries, but you imported Google-Apis twice.

The exclude-part needs to be in

compile('com.google.api-client:google-api-client:1.18.0-rc') {
    // Exclude artifacts that the Android SDK/Runtime provides.
    exclude group: 'xpp3', module: 'shared'
    exclude group: 'org.apache.httpcomponents', module: 'httpclient'
    exclude group: 'junit', module: 'junit'
    exclude group: 'com.google.android', module: 'android'
}

and in your example you again included the apis by:

compile([group: 'com.google.api-client', name: 'google-api-client-android', version: '1.20.0'])

without the exclude-part which caused the duplicate import.

Upvotes: 2

zhengshangxin
zhengshangxin

Reputation: 1

You can have a try of deleting the line: compile fileTree(dir: 'libs', include: ['*.jar'])

Upvotes: 0

Related Questions