什么是指定一个Android库项目,包括其依赖的正确方法 [英] What is the correct way to specify an Android library project to include its dependencies

查看:119
本文介绍了什么是指定一个Android库项目,包括其依赖的正确方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Android的工作室,我试图编译它使用一个Android库的Andr​​oid应用程序模块。
这个库包含针对Bugsense一个jar文件(由摇篮自动包含)。

虽然库模块编译正确,应用程序模块将失败,因为它正在寻找被库模块中使用的Bugsense jar文件。

我有一种变通方法,让项目进行编译。通过还包括Bugsense依赖该项目一切正常。

我的问题是:如何让我不用复制Bugsense依赖项目编译

下面是我的库项目build.gradle文件。

  buildscript {
    库{
        mavenCentral()
    }
    依赖{
        类路径com.android.tools.build:gradle:0.6.+
    }
}
应用插件:机器人库

库{
    mavenCentral()
    行家{URLhttp://www.bugsense.com/gradle/'}
}

安卓{
    compileSdkVersion 15
    buildToolsVersion19.0.0

    defaultConfig {
        的minSdkVersion 15
        targetSdkVersion 15
    }
}

依赖{
    编译com.bugsense.trace:bugsense:3.6
}
 

该库项目被称为UTIL

以下是build.gradle的应用程序的Andr​​oid的部分。

 安卓{
    compileSdkVersion 15
    buildToolsVersion '19 .0.0

    defaultConfig {
        的minSdkVersion 15
        targetSdkVersion 15
    }

    依赖{
        编制项目(:UTIL)
    }
}
 

当我编译这个我收到以下错误:

  *出了什么问题:
出现了故障配置项目:BR。
>未能通知项目评估听众。
   >未能解决所有依赖关系配置:BR:_DebugCompile。
      >找不到com.bugsense.trace:bugsense:3.6。
        要求:
            DSS:BR:未指定> DSS:UTIL:不详
 

我可以通过添加Bugsense到应用程序的build.gradle文件的存储库部分进行编译工作。以下是code我添加到应用程序的项目。

的build.gradle文件

 库{
    mavenCentral()
    行家{URLhttp://www.bugsense.com/gradle/'}
}
 

记住,上面的code是在build.gradle应用程序项目和图书馆。

我如何避免加入Bugsense依赖于应用程序和库项目?

更新:

我用摇篮1.8

我从具有摇篮干净assembleDebug

在命令行编译

下面是应用程序项目的完整build.gradle文件:

  buildscript {
    库{
        mavenCentral()
    }
    依赖{
        类路径com.android.tools.build:gradle:0.6.+
    }
}
应用插件:'机器人'

库{
    mavenCentral()
    //行家{URLhttp://www.bugsense.com/gradle/'}
}

安卓{
    compileSdkVersion 15
    buildToolsVersion '19 .0.0

    defaultConfig {
        的minSdkVersion 15
        targetSdkVersion 15
        testPackageNamecom.myapp.test
    }

    依赖{
        编制项目(:共同)
        编制项目(:UTIL)
    }
}

依赖{
    instrumentTestCompilecom.jayway.android.robotium:robotium独奏:4.3
    instrumentTestCompilecom.squareup:巨星 - 安卓1.0 +
    instrumentTestCompilecom.squareup.spoon:勺子客户端:1.0 +
    instrumentTestCompilecom.google.guava:番石榴:15.0'
}

配置{勺}
依赖{勺子'com.squareup.spoon:匙亚军:1.0.5}
 

解决方案

这是预期的行为。仅储存库声明的项目,其配置是目前解决都考虑在内,都参与传递依赖即使当。通常情况下,存储库里面的根项目的 allprojects {...} 的子项目{...} 块中声明这种情况下,永远不会发生这种问题。

PS:相关性{...} 需要到达的安卓之外{...} 块<。 / P>

In Android Studio I'm trying to compile an Android application module which uses an Android library.
The library includes a jar file for Bugsense (included automatically by gradle).

Although the library module compiles correctly, the application module fails because it is looking for the Bugsense jar file that is used within the library module.

I do have a workaround which allows the project to compile. By also including the Bugsense dependency in the project everything works.

My question is: How do I make the project compile without duplicating the Bugsense dependency?

Here is my build.gradle file for the library project.

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.6.+'
    }
}
apply plugin: 'android-library'

repositories {
    mavenCentral()
    maven { url 'http://www.bugsense.com/gradle/' }
}

android {
    compileSdkVersion 15
    buildToolsVersion "19.0.0"

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 15
    }
}

dependencies {
    compile 'com.bugsense.trace:bugsense:3.6'
}

The library project is called "util"

Following is the android section of the build.gradle for the application

android {
    compileSdkVersion 15
    buildToolsVersion '19.0.0'

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 15
    }

    dependencies {
        compile project(':util')
    }
}

When I compile this I get the following error:

* What went wrong:
A problem occurred configuring project ':br'.
> Failed to notify project evaluation listener.
   > Could not resolve all dependencies for configuration ':br:_DebugCompile'.
      > Could not find com.bugsense.trace:bugsense:3.6.
        Required by:
            dss:br:unspecified > dss:util:unspecified

I can make the compile work by adding Bugsense to the repositories section of the build.gradle file for the application. Following is the code I added to the build.gradle file for the application project.

repositories {
    mavenCentral()
    maven { url 'http://www.bugsense.com/gradle/' }
}

Remember, the above code is in the build.gradle for the application project AND the library.

How do I avoid adding the Bugsense dependency to both the application and library projects?

UPDATES:

I'm using Gradle 1.8

I'm compiling from the command line with "gradle clean assembleDebug"

The following is the complete build.gradle file for the application project:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.6.+'
    }
}
apply plugin: 'android'

repositories {
    mavenCentral()
    //maven { url 'http://www.bugsense.com/gradle/' }
}

android {
    compileSdkVersion 15
    buildToolsVersion '19.0.0'

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 15
        testPackageName "com.myapp.test"
    }

    dependencies {
        compile project(':common')
        compile project(':util')
    }
}

dependencies {
    instrumentTestCompile 'com.jayway.android.robotium:robotium-solo:4.3'
    instrumentTestCompile 'com.squareup:fest-android:1.0.+'
    instrumentTestCompile 'com.squareup.spoon:spoon-client:1.0.+'
    instrumentTestCompile 'com.google.guava:guava:15.0'
}

configurations { spoon }
dependencies   { spoon 'com.squareup.spoon:spoon-runner:1.0.5' }

解决方案

It's the expected behavior. Only the repository declarations for the project whose configuration is currently resolved are taken into account, even when transitive dependencies are involved. Typically, repositories are declared inside the root project's allprojects { .. } or subprojects { ... } block, in which case this problem can never occur.

PS: dependencies { .. } needs to go outside the android { ... } block.

这篇关于什么是指定一个Android库项目,包括其依赖的正确方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆