发布时忽略 Android 依赖项

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25295066/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 09:18:39  来源:igfitidea点击:

Android dependency is ignored for release

android

提问by secureboot

I get a lot of these warnings when building my project with gradle. I see https://stackoverflow.com/a/15794650/864069, but I'm unclear how to silence these. It sounds like any version of these things I'm depending on is getting stripped out in favor of the version packaged in android.jar.

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

I suppose that's okay, but I really would like to shut these up so that the things I see are real problems only.

我想那没问题,但我真的很想把这些关起来,这样我看到的东西就只是真正的问题。

So, specifically, I'm curious:

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

  1. Does this indicate an issue? Seems like definitely not.
  2. How do I shut this up?
  3. Doesn't everyone see this set of warnings? I'm skeptical that the entire universe of people using gradle + android.Log is seeing this set of warnings.
  1. 这是否表明有问题?好像绝对不行。
  2. 我该如何闭嘴?
  3. 是不是每个人都看到了这组警告?我怀疑整个使用 gradle + android.Log 的人都看到了这组警告。
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

回答by maraci

I'm unsure if this can create issues. The best thing to do is to follow the suggestion in the warning, or exclude the dependency entirely (your point #2, which I've answered below).

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

I've been seeing these warnings as well, specifically the 'commons-logging' one.

我也一直看到这些警告,特别是“commons-logging”警告。

What the answer in the thread you linked too is saying is that you should ignore these dependencies since the Android APIs include them already (I think. Correct me if I'm wrong).

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

For example if you are specifically requiring commons-logging (or another that gives a similar warning) remove it from your list.

例如,如果您特别需要 commons-logging(或其他给出类似警告的),请将其从您的列表中删除。

build.gradle file:

build.gradle 文件:

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

Also, if you have a dependency that requires commons-logging as a transitive dependency, you should exclude it as well.

此外,如果您有一个需要 commons-logging 作为传递依赖项的依赖项,您也应该排除它。

Example:

例子:

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

becomes

变成

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

An easy way to completely exclude it can be done by adding this to your build.gradle file as well, without having to exclude it in each dependency:

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

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

Finally, to view the dependency tree (and to see what each of your dependencies transitively import on their own which can conflict, which can be very useful), use this command from the root of your project:

最后,要查看依赖关系树(并查看您的每个依赖项自行导入哪些可能会发生冲突,这非常有用),请从项目的根目录使用以下命令:

./gradlew :your_module_name:dependencies

回答by Sigvent

If you want to silent the warnings, you have to add this in your build.gradle for each dependency :

如果您想使警告静音,则必须在 build.gradle 中为每个依赖项添加以下内容:

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

It will be :

这将是 :

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