问题描述
我有一个这样的目录/项目设置:
I have a directory/project setup like this:
C:
_dev
Projects
Logger
MyProject
Logger 是一个使用 Gradle 的 Android 库项目.MyProject 是一个标准的 Android 项目项目,需要使用 Logger 库.
Logger is an Android library project using Gradle. MyProject is a standard Android project project that needs to make use of the Logger library.
我正在使用 Android Studio 并尝试将 Logger 添加到外部库.虽然这在开发过程中有效,但我会收到有关在构建时找不到该类的消息.
I am using Android Studio and have tried adding Logger to the external libraries. Whilst this works during development, I get messages about the class not being found when building.
我对 Gradle 完全陌生,但在 MyProject 中的 build.gradle 中尝试了以下内容:
I'm completely new to Gradle, but have tried the following in my build.gradle within MyProject:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 18
buildToolsVersion "18.1.0"
defaultConfig {
minSdkVersion 16
targetSdkVersion 18
}
dependencies {
compile files("../Logger")
}
}
dependencies {
compile 'com.android.support:gridlayout-v7:18.0.0'
compile 'com.android.support:appcompat-v7:18.0.0'
}
推荐答案
最简单的方法是将 MyProject
设为多项目,将 Logger
项目作为子项目.
The simplest way is to make MyProject
a multi project with the Logger
project as a subproject.
settings.gradle
在 MyProject
目录:
include ":logger"
project(":logger").projectDir = file("../logger")
在 MyProject
的 build.gradle
中,您现在可以将此库作为项目引用:
In the build.gradle
of MyProject
you can now reference this lib as a project:
dependencies {
compile 'com.android.support:gridlayout-v7:18.0.0'
compile 'com.android.support:appcompat-v7:18.0.0'
compile project(":logger")
}
这篇关于需要另一个目录中的 Gradle 项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!