运行应用程序时无法生成警告,无法运行应用程序

时间:2015-04-14 21:11:41

标签: java android android-gradle apache-httpclient-4.x build.gradle

我对Android很新,并且无法理解这个错误。当同步gradle文件时,android studio正在退出而没有任何错误但是当我尝试构建应用程序并运行它时它会发出2个警告:

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

.......

我的gradle文件是这样的:

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')

}

我尝试了在stackoverflow上可以找到的所有内容,但它仍然显示错误。找不到合适的答案。请提出解决方案。由于这个原因,我被困在我的项目中。感谢

3 个答案:

答案 0 :(得分:2)

即使这个问题很老,也没有解决,我在一段时间内努力寻找类似配置的原因。

您排除了库中的重复导入,但您导入了两次Google-Apis。

排除部分需要在

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

在您的示例中,您再次将apis包括在内:

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

没有导致重复导入的exclude-part。

答案 1 :(得分:0)

您可以尝试删除该行: 编译fileTree(dir:' libs',include:[' * .jar'])

答案 2 :(得分:0)

在我的情况下,我不得不两次这样排除..我不认为它太复杂但可能会令人困惑。我认为解决这些问题会更好,因为之后他们可能会以奇怪的形式回来。

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
}