简体   繁体   English

在Android Gradle构建中不使用libs文件夹中的Jar文件

[英]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.

相关问题 将android库项目转换为带有资源的jar文件(libs和build文件夹) - Convert android library project to jar file with resources (libs and build folder) Android:jar文件(LIB或LIBS)的文件夹名称是什么? - Android: What is the folder name of the jar files (LIB or LIBS)? 如何使Android Gradle项目使用复制到libs文件夹中的jar文件? - How to make an Android Gradle project use a jar file that's copied into the libs folder? Android Gradle构建两次包含jni库 - Android gradle build includes jni libs twice 在gradle android build中使用progaurd生成jar文件 - Generating jar files using progaurd in gradle android build 如何在公共目录(不是libs)中引用外部jar文件以使用ant构建android项目? - How do I reference external jar files in a common directory (not libs) to build android project using ant? Libs文件夹vs构建路径依赖关系(ANDROID) - Libs folder vs build path dependency (ANDROID) 将Gradle构建模块作为.aar放置在另一个模块的libs文件夹中 - Gradle build module as .aar and put in another module libs folder Android:libs中的.jar文件与gradle中的依赖项url - Android: .jar file in libs vs dependency url in gradle Android eclipse-在libs文件夹和参考库中重复的android.jar - Android eclipse - android.jar duplicated in libs folder and Referenced Libraries
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM