发布时会忽略Android依赖项

时间:2014-08-13 19:59:24

标签: android

在使用gradle构建项目时,我收到了很多这些警告。我看到https://stackoverflow.com/a/15794650/864069,但我不清楚如何沉默这些。这听起来像 我依赖的这些东西的任何版本都会被剥离,转而支持android.jar中打包的版本。

我想这没关系,但我真的想关闭它们,以便我看到的东西只是真正的问题。

所以,具体来说,我很好奇:

  1. 这是否表明存在问题?似乎绝对不是。
  2. 如何关闭它?
  3. 不是每个人都看到这套警告吗?我怀疑使用gradle + android.Log的整个人群正在看到这组警告。
  4. WARNING: Dependency commons-logging:commons-logging:1.1.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 commons-logging:commons-logging:1.1.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 commons-logging:commons-logging:1.1.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
    WARNING: Dependency commons-logging:commons-logging:1.1.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
    WARNING: Dependency commons-logging:commons-logging:1.1.1 is ignored for debugTest 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 debugTest 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 robolectric 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 robolectric 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 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 commons-logging:commons-logging:1.1.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 commons-logging:commons-logging:1.1.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
    WARNING: Dependency commons-logging:commons-logging:1.1.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
    WARNING: Dependency commons-logging:commons-logging:1.1.1 is ignored for debugTest 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 debugTest 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
    

2 个答案:

答案 0 :(得分:86)

我不确定这是否会产生问题。最好的办法是遵循警告中的建议,或完全排除依赖关系(您的观点#2,我已在下面回答)。

我也一直在看这些警告,特别是'commons-logging'警告。

您链接的主题中的答案是,您应该忽略这些依赖关系,因为Android API已经包含它们(我认为。如果我错了,请纠正我)。

例如,如果您特别要求公共日志记录(或其他提供类似警告的日志记录),请将其从列表中删除。

build.gradle文件:

dependencies {
    ...
    compile 'commons-logging:commons-logging:1.1.3' #Remove this line; you don't need it.
    ....
}

此外,如果您的依赖项需要将commons-logging作为传递依赖项,那么您也应该将其排除。

示例:

dependencies {
    ...
    compile 'some.package.that:requires_commons_logging:1.2.3'
    ....
}

变为

dependencies {
    ...
    compile ('some.package.that:requires_commons_logging:1.2.3') {
        exclude group: 'commons-logging', module: 'commons-logging'
    }
    ....
}

完全排除它的简单方法可以通过将其添加到build.gradle文件中来完成,而不必在每个依赖项中将其排除:

configurations {
    all*.exclude group: 'commons-logging', module: 'commons-logging'
}

最后,要查看依赖关系树(并查看每个依赖关系可以自行转换的哪些依赖关系,这可能会非常有用),请从项目的根目录使用此命令:

./gradlew :your_module_name:dependencies

答案 1 :(得分:10)

如果要静默警告,则必须在build.gradle中为每个依赖项添加此警告:

exclude group: 'org.apache.httpcomponents', module: 'httpclient'

它将是:

dependencies {
    ...
    compile ('some.package.that:requires_commons_logging:1.2.3') {
        exclude group: 'commons-logging', module: 'commons-logging'
    }
    ....
}