【问题标题】:Should I move some dependencies to `runtime` in Gradle in Android Studio?我应该将一些依赖项移动到 Android Studio 中 Gradle 中的“运行时”吗?
【发布时间】:2017-07-20 00:55:48
【问题描述】:

在 Android Studio 中使用gradle-lint-plugin,提示

:lintGradle

This project contains lint violations. A complete listing of the
violations follows.  Because none were serious, the build's overall
status was unaffected.

this dependency should be moved to the runtime configuration since it
has no classes warning   unused-dependency                 
app/build.gradle:43 compile 'com.android.support:appcompat-v7:24.1.0'

this dependency should be moved to the runtime configuration since it
has no classes warning   unused-dependency                 
app/build.gradle:44 compile 'com.android.support:design:24.1.0'

this dependency should be moved to the runtime configuration since it
has no classes warning   unused-dependency                 
app/build.gradle:45 compile 'com.android.support:cardview-v7:24.1.0'

this dependency should be moved to the runtime configuration since it
has no classes warning   unused-dependency                 
app/build.gradle:52 compile
'com.github.gigamole.arcprogressstackview:library:+'

this dependency should be moved to the runtime configuration since it
has no classes warning   unused-dependency                 
app/build.gradle:53 compile 'com.github.dexafree:materiallist:3.2.1'

this dependency should be moved to the runtime configuration since it
has no classes warning   unused-dependency                 
app/build.gradle:54 compile 'com.android.volley:volley:1.0.0'

this dependency should be moved to the runtime configuration since it
has no classes warning   unused-dependency                 
app/build.gradle:55 compile 'com.cocosw:bottomsheet:1.+@aar'

this dependency should be moved to the runtime configuration since it
has no classes warning   unused-dependency                 
app/build.gradle:57 compile 'com.android.support:support-v4:+'

this dependency should be moved to the runtime configuration since it
has no classes warning   unused-dependency                 
app/build.gradle:58 compile 'com.github.shem8:material-login:1.4.0'

this dependency should be moved to the runtime configuration since it
has no classes warning   unused-dependency                 
app/build.gradle:64
compile('com.github.ozodrukh:CircularReveal:1.3.1@aar') {
    transitive = true; }

this dependency should be moved to the runtime configuration since it
has no classes warning   unused-dependency                 
app/build.gradle:74 compile 'com.github.rey5137:material:1.2.4'

? app/build.gradle: 11 problems (0 errors, 11 warnings)

To apply fixes automatically, run fixGradleLint, review, and commit
the changes.


BUILD SUCCESSFUL

我应该接受建议吗?如果这些依赖项应该在 runtime 中,为什么每个依赖项 wiki/doc 都不这么说并坚持告诉我们将依赖项放在 compile 中?

编辑:我尝试接受建议,换句话说,将关键字compile 更改为runtime,例如runtime 'com.android.support:appcompat-v7:24.1.0'。然而,Android Studio 暗示

Error:Could not find method runtime() for arguments
[com.android.support:appcompat-v7:24.1.0] on object of type
org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

Please install the Android Support Repository from the Android SDK
Manager. <a href="openAndroidSdkManager">Open Android SDK Manager</a>

那么问题出在哪里?

【问题讨论】:

    标签: android android-studio gradle android-gradle-plugin lint


    【解决方案1】:

    我相信apkruntime 的android,例如:

    apk 'com.android.support:appcompat-v7:24.1.0'
    

    有人说package

    https://stackoverflow.com/a/28473873/360211

    也许两者都有效,也许没有区别,也许有。我不知道那些非常难以搜索的术语。

    【讨论】:

      【解决方案2】:

      您应该将编译所需的依赖项放在compile 中,这包括您直接在源代码中使用的类。

      您应该将编译不需要但在运行时需要的依赖项放在runtime 中,这些在编译类路径中不可用,但它们将在执行时可用。

      【讨论】:

      • 嗯,奇怪。也许你应该发布你的build.gradle
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-09-16
      • 2013-07-27
      • 1970-01-01
      • 2014-10-06
      • 2013-08-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多