Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
指定Android库项目以包含其依赖项的正确方法是什么_Android_Android Gradle Plugin - Fatal编程技术网

指定Android库项目以包含其依赖项的正确方法是什么

指定Android库项目以包含其依赖项的正确方法是什么,android,android-gradle-plugin,Android,Android Gradle Plugin,在Android Studio中,我试图编译一个使用Android库的Android应用程序模块。 该库包含Bugsense的jar文件(gradle自动包含) 尽管库模块编译正确,但应用程序模块失败,因为它正在查找库模块中使用的Bugsense jar文件 我确实有一个变通方法,允许项目编译。通过在项目中包含Bugsense依赖项,一切都可以正常工作 我的问题是:如何在不复制Bugsense依赖项的情况下编译项目 这是我的build.gradle文件,用于库项目 buildscript {

在Android Studio中,我试图编译一个使用Android库的Android应用程序模块。
该库包含Bugsense的jar文件(gradle自动包含)

尽管库模块编译正确,但应用程序模块失败,因为它正在查找库模块中使用的Bugsense jar文件

我确实有一个变通方法,允许项目编译。通过在项目中包含Bugsense依赖项,一切都可以正常工作

我的问题是:如何在不复制Bugsense依赖项的情况下编译项目

这是我的build.gradle文件,用于库项目

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'
}
库项目称为“util”

下面是应用程序build.gradle的android部分

android {
    compileSdkVersion 15
    buildToolsVersion '19.0.0'

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 15
    }

    dependencies {
        compile project(':util')
    }
}
编译此文件时,会出现以下错误:

* 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
我可以通过向应用程序的build.gradle文件的repositories部分添加Bugsense来完成编译。以下是我为应用程序项目添加到build.gradle文件的代码

repositories {
    mavenCentral()
    maven { url 'http://www.bugsense.com/gradle/' }
}
请记住,上面的代码位于应用程序项目和库的build.gradle中

如何避免将Bugsense依赖项同时添加到应用程序和库项目中

更新:

我用的是Gradle 1.8

我用“gradle clean assembleDebug”从命令行编译

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

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' }

这是预期的行为。仅考虑当前已解析其配置的项目的存储库声明,即使涉及可传递依赖项。通常,存储库在根项目的
allprojects{..}
subprojects{…}
块中声明,在这种情况下,此问题永远不会发生


PS:
dependencies{..}
需要跳出
android{..}
块。

依赖项应该可以通过gradle传递。我多次使用库项目中的依赖项,没有任何问题。您的设置一定有问题。几个月前,我使用bugsense时没有问题。你可以发布你的整个gradle版本,并提及你正在运行的gradle版本吗。还可以使用命令指定您正在使用的构建。Matt Wolfe,我以前在库项目中使用过类似的技术,它已经起作用了。然而,在这种情况下,我使用的是项目中libs目录中的jar文件,而不是Gradle获取的文件。您能描述一下您是如何使用Bugsense的吗?它是在附带的库中还是直接与应用程序项目一起使用?谢谢-我很感谢你花时间看这个。这可能是gradle 1.9版的问题。我之前读过一段时间,在android上使用它时出现了一些问题。不确定这些问题是否已经解决。我仍然坚持1.8的价格。我看不出上面有什么不对劲的地方,所以很难说。不过我会尝试Gradle1.8,我实际上使用的是Gradle1.8(Android gradle插件还不支持1.9)。我修正了帖子以反映正确的版本。这有什么用?为什么会这样?我希望它能找到依赖项的依赖项并下载它们,或者和当前的依赖项合并。我们不能这样做有什么原因吗?