[英]Jar files in libs folder are not used in Android Gradle build
i just started to play with the gradle build system for Android. 我刚刚开始玩Android的gradle构建系统。
However i'm not able build one of my projects. 但是我无法构建我的一个项目。 It depends on a jar in the libs/ folder.
它取决于libs /文件夹中的jar。
Doing gradle build
fails in the compileDebug
task because all of the classes from the jar file are missing. 在
compileDebug
任务中执行gradle build
失败,因为缺少jar文件中的所有类。
It is a library project! 这是一个图书馆项目! Here is my build.gradle file:
这是我的build.gradle文件:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.2'
}
}
apply plugin: 'android-library'
android {
target='android-16'
sourceSets {
main {
manifest {
srcFile 'AndroidManifest.xml'
}
java {
srcDir 'src'
}
res {
srcDir 'res'
}
assets {
srcDir 'assets'
}
resources {
srcDir 'src'
}
}
}
}
Am i missing something obvious? 我错过了一些明显的东西吗
Goddchen Goddchen
just found the answer myself: 我自己找到了答案:
Seems like the current version of the Android Gradle plugin doesn't look for jars in the libs/ folder. 似乎当前版本的Android Gradle插件不会在libs /文件夹中查找jar。 So you have to add them yourself:
所以你必须自己添加它们:
dependencies {
compile files('libs/mylib.jar')
}
or 要么
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
Place this within the android
namespace like this: 把它放在
android
命名空间中,如下所示:
android {
target = "android-15"
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
}
Just in case none of the solutions worked for you, you may want to try to provide the path to the *.jar manually: 如果没有一个解决方案适合您,您可能想尝试手动提供* .jar的路径:
compile files('../<your-library-folder>/<your-library>.jar')
The '../'
part means that Gradle will search for the library starting from the root projects folder (not app module). '../'
部分意味着Gradle将从根项目文件夹(不是app模块)开始搜索库。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.