简体   繁体   English

gradle依赖关系如何找到包?

[英]How does a gradle dependency find a package?

I have this in my gradle file for an android studio application...` 我的gradle文件中有这个用于android studio应用程序...

apply plugin: 'com.android.application'

def ftcLibLocation = "../../../android/ftc_lib/ftc_app/FtcRobotController/libs"

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

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

dependencies {
    compile 'com.android.support:appcompat-v7:22.1.1'
    compile files('${ftcLibLocation}/FtcRobotController-debug.jar')
    compile files('${ftcLibLocation}/FtcCommon-release.jar')
    compile files('${ftcLibLocation}/ModernRobotics-release.jar')
    compile files('${ftcLibLocation}/RobotCore-release.jar')
    compile files('${ftcLibLocation}/WirelessP2p-release.jar')
    compile files('${ftcLibLocation}/Analytics-release.jar')
    compile files('${ftcLibLocation}/d2xx.jar')
}

and yet when I compile the program gradle/android studio complains that it can't find packages that I know are located in those jars. 但是,当我编译程序gradle / android studio时,它抱怨找不到我所知道的位于这些jar中的程序包。

Error:(3, 47) error: package com.qualcomm.robotcore.eventloop.opmode does not exist

That package is located in ${ftcLibLocation}/RobotCore-release.jar why isn't the build locating it? 该软件包位于$ {ftcLibLocation} /RobotCore-release.jar中,为什么构建找不到它?

Create a libs folder (adjacent to the src directory) and include all your jars in that directory. 创建一个libs文件夹(与src目录相邻),并将所有jar文件包含在该目录中。

Then in your build.gradle file, use this : 然后在您的build.gradle文件中,使用以下命令:

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}

You don't have to compile every dependency separately. 您不必分别编译每个依赖项。

There are several reasons that this could happen. 发生这种情况有多种原因。 Probably the most useful tool for starting is the gradle dependencies command. 可能最有用的启动工具是gradle dependencies命令。 It will tell you things about your dependencies that may surprise you. 它会告诉您有关您的依赖项的信息,这可能会让您感到惊讶。 More about it here: 有关此的更多信息:

What is the Gradle artifact dependency graph command? 什么是Gradle工件依赖关系图命令?

  1. Your path variable ftcLibLocation is not set properly in the environment in which gradle is running. 您的路径变量ftcLibLocation在gradle运行的环境中未正确设置。 Usually gradle will display the full path during the build or you can display or log it: 通常gradle将在构建期间显示完整路径,或者您可以显示或记录它:

https://discuss.gradle.org/t/accessing-the-buildscript-classpath/5297 https://discuss.gradle.org/t/accessing-the-buildscript-classpath/5297

  1. The jar file has been changed, but gradle cache does not know that. jar文件已更改,但是gradle缓存不知道这一点。 I run into this sometimes and I have to go to: 有时我会遇到这个问题,我必须去:

    {userhome}\\.gradle\\.caches

    and in there you will find a lot of folders that have cached references to libraries. 并且在其中您会发现很多文件夹,这些文件夹已经缓存了对库的引用。 Those libraries are usually remote, but I have seen problems with local libs being cached. 这些库通常是远程的,但是我看到了本地库被缓存的问题。 You can delete this directory - or find the part that has the problem. 您可以删除此目录-或查找有问题的部件。 Deleting will cause all your dependencies to download again, and may take awhile. 删除将导致您的所有依赖项再次下载,可能需要一段时间。

  2. Another potential problem is Android Studio and gradle. 另一个潜在的问题是Android Studio和gradle。 Sometimes the plugin does not update properly. 有时,插件无法正确更新。 Reboot Android Studio and try again. 重新启动Android Studio,然后重试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM