[英]How does a gradle dependency find a package?
我的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')
}
但是,當我編譯程序gradle / android studio時,它抱怨找不到我所知道的位於這些jar中的程序包。
Error:(3, 47) error: package com.qualcomm.robotcore.eventloop.opmode does not exist
該軟件包位於$ {ftcLibLocation} /RobotCore-release.jar中,為什么構建找不到它?
創建一個libs
文件夾(與src
目錄相鄰),並將所有jar文件包含在該目錄中。
然后在您的build.gradle
文件中,使用以下命令:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
您不必分別編譯每個依賴項。
發生這種情況有多種原因。 可能最有用的啟動工具是gradle dependencies
命令。 它會告訴您有關您的依賴項的信息,這可能會讓您感到驚訝。 有關此的更多信息:
ftcLibLocation
在gradle運行的環境中未正確設置。 通常gradle將在構建期間顯示完整路徑,或者您可以顯示或記錄它: https://discuss.gradle.org/t/accessing-the-buildscript-classpath/5297
jar文件已更改,但是gradle緩存不知道這一點。 有時我會遇到這個問題,我必須去:
{userhome}\\.gradle\\.caches
並且在其中您會發現很多文件夾,這些文件夾已經緩存了對庫的引用。 這些庫通常是遠程的,但是我看到了本地庫被緩存的問題。 您可以刪除此目錄-或查找有問題的部件。 刪除將導致您的所有依賴項再次下載,可能需要一段時間。
另一個潛在的問題是Android Studio和gradle。 有時,插件無法正確更新。 重新啟動Android Studio,然后重試。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.