问题描述
我有以下问题.当我想在Gradle依赖项中使用本地jar时.
I have the following problem. When I want to use a local jar in my Gradle dependencies.
如果我只添加:
compile files('libs/PushLinkAndroid-5.3.0.jar')
它不起作用.
注意:某些输入文件使用或覆盖不推荐使用的API.注意:有关详细信息,请使用-Xlint:deprecation重新编译.4个错误
Note: Some input files use or override a deprecated API. Note: Recompile with -Xlint:deprecation for details. 4 errors
失败
失败:构建失败,并出现异常.
FAILURE: Build failed with an exception.
-
出了什么问题:任务':app:compileDebugJava'的执行失败.
What went wrong: Execution failed for task ':app:compileDebugJava'.
尝试:使用--stacktrace选项运行以获取堆栈跟踪.使用--info或>-debug选项运行,以获取更多日志输出.
Try: Run with --stacktrace option to get the stack trace. Run with --info or >--debug option to get more log output.
建立失败
总时间:6.543秒
如果我将绝对路径添加到Jar中,则项目将编译,并且一切正常:
If i add the absolute path to the Jar, the project compiles and everything works finde:
compile files('C:/Users/Kai/AndroidStudioProjects/ProjectA/libs/PushLinkAndroid-5.3.0.jar')
看起来Path出了点问题,但是当绝对Path正常工作时怎么可能呢?
Looks like there is something wrong with the Path but how could this be when the absolute Path works fine?
Build.gradle
Build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "de.xyz.kai.migraenebook"
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
//compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.jakewharton:butterknife:7.0.1'
compile project(':volley')
debugCompile 'im.dino:dbinspector:3.2.1@aar'
compile 'de.hdodenhof:circleimageview:1.3.0'
compile 'com.android.support:recyclerview-v7:+'
//compile files('C:/Users/Kai/AndroidStudioProjects/MigraeneBook/libs/PushLinkAndroid-5.3.0.jar')
compile files('libs/PushLinkAndroid-5.3.0.jar')
//compile files('libraries/PushLinkAndroid-5.3.0.jar')
//compile files('C:/Users/Kai/AndroidStudioProjects/MigraeneBook/libraries/PushLinkAndroid-5.3.0.jar')
}
注意:我尝试了其他文件夹,PushLink.jar位于库"和库"中.我使用或注释掉的命令没有区别-绝对路径有效,相对路径无效.
NOTE: I tried different folders, the PushLink.jar is in "libs" and "libraries". It doesn't make a difference which command I use or comment out - absolute path is working, relative not.
推荐答案
尝试一下,它将包括本地存储库中的所有JAR,因此您不必每次都指定它:
Try this, it would include all JARs in the local repository, so you wouldn't have to specify it every time:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
此外,您应该知道在通过引用文件时
Also, you should know that when referencing a file via
files("relative/path/to/a.jar")
路径是相对于此片段所在的构建脚本进行评估的.因此,当您的 build.gradle
文件位于/a/project/build.gradle
中时,jar应该位于/a/project/relative/path/to/a.jar
中.在多项目gradle构建中,您可以将jar放在相对于根-项目的文件夹中,并通过
path is evaluated relative to the buildscript this snippet is in. So when your build.gradle
file is located in /a/project/build.gradle
, then the jar should be in /a/project/relative/path/to/a.jar
.In a multiproject gradle build you can put the the jar in a folder relative to the root - project and reference it in all subprojects via
rootProject.files("relative/to/root/a.jar")
因此请考虑到这一点,然后重新检查gradle设置是否正确.
So take this to account and re-check if your gradle settings are correct.
这篇关于摇篮绝对/相对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!