java - 在 Android studio 中使用 Jcenter 和 gradle

标签 java android gradle dependencies jcenter

编辑:想通了,我对项目范围的 build.gradle 文件的 allprojects->repositories 部分实现了 JBaruch 的建议。

我正在编写一个依赖于 IOIO 的项目。在我的项目上编译 IOIO 的库给我带来了麻烦。我尝试将 .aar 和 .jar 文件直接放在我的 libs/目录中。然而,在 gradle 中使用 .aar 文件被证明是一个麻烦事。现在,我正尝试使用 jcenter 来查找这些库。

我用jcenter做仓库,gradle原来无法解析

com.github.ytai.ioio:IOIOLibCore

但指定版本号 5.05 解决了这个问题。但是,现在 gradle 无法解析

com.sparetimelabs:purejavacomm:0.0.22

这不是我要求与我的项目一起编译的库。

下面是我的 app/build.gradle 文件的副本

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "com.example.agrc.elkausbtransfer"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
        compile 'com.android.support:appcompat-v7:23.0.1'
        compile 'com.github.ytai.ioio:IOIOLibCore:5.05'
        compile 'com.github.ytai.ioio:IOIOLibPC:5.05'
        compile 'com.github.ytai.ioio:IOIOLibAndroid:5.05'
        compile 'com.github.ytai.ioio:IOIOLibAndroidAccessory:5.05'
        compile 'com.github.ytai.ioio:IOIOLibAndroidDevice:5.05'
        /* To use IOIO from source
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile(name: 'IOIOLibAndroid-release', ebxt: 'aar')
        compile(name: 'IOIOLibAndroidAccessory-release', ext: 'aar')
        compile(name: 'IOIOLibAndroidDevice-release', ext: 'aar')
        */
    }

在尝试了 JBaruch 的建议并将 maven url 添加到我的项目(根)build.gradle 文件后,我注意到 Gradle Build 文件如下所示:

    Executing tasks: [:app:assembleDebug]

Configuration on demand is an incubating feature.

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration ':app:_debugCompile'.
   > Could not find com.sparetimelabs:purejavacomm:0.0.22.
     Searched in the following locations:
         https://jcenter.bintray.com/com/sparetimelabs/purejavacomm/0.0.22/purejavacomm-0.0.22.pom
         https://jcenter.bintray.com/com/sparetimelabs/purejavacomm/0.0.22/purejavacomm-0.0.22.jar
         file:/home/eric/Libs/Android/extras/android/m2repository/com/sparetimelabs/purejavacomm/0.0.22/purejavacomm-0.0.22.pom
         file:/home/eric/Libs/Android/extras/android/m2repository/com/sparetimelabs/purejavacomm/0.0.22/purejavacomm-0.0.22.jar
         file:/home/eric/Libs/Android/extras/google/m2repository/com/sparetimelabs/purejavacomm/0.0.22/purejavacomm-0.0.22.pom
         file:/home/eric/Libs/Android/extras/google/m2repository/com/sparetimelabs/purejavacomm/0.0.22/purejavacomm-0.0.22.jar
     Required by:
         ElkaUsbTransfer:app:unspecified
         ElkaUsbTransfer:app:unspecified > com.github.ytai.ioio:IOIOLibPC:5.05

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 2.061 secs

即,Gradle 没有在提供的 maven url 中进行搜索。我如何强制 Gradle 执行此操作?

最佳答案

com.sparetimelabs:purejavacomm:0.0.22 是 IOIO 项目的传递依赖。问题是 Spare time labs 有自己的存储库,不会将他们的 Artifact 发布到 Bintray。您需要做的是将他们的存储库添加到 Gradle 中的存储库列表中:

repositories {
    jcenter()
    maven {
       url 'http://www.sparetimelabs.com/maven2'
    }  
}

关于java - 在 Android studio 中使用 Jcenter 和 gradle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32772252/

相关文章:

android - NoClassDefFoundError 使用 Android 应用程序、Maven 和 Eclipse 开发库

java - 找不到满足版本限制的 'com.google.code.findbugs:jsr305' 版本

android - 关于 Android 的 Cordova 构建过程的一些问题

java - Eclipse错误: Invalid signature file digest for Manifest main attributes on several projects

java - Java 生产者消费者多线程中的终止

java - 让控制台等待用户输入关闭

android - 无法通过我的 GLSurfaceView 获取 AdView

java - Spring Boot应用程序启动失败,tomcat 7 jdk1.8

android - 无法添加名称为 'testCompile' 的配置,因为具有该名称的配置已存在

gradle - Gradle快捷方式符号不适用于复制任务