在 Android studio 中使用 Jcenter 和 gradle

2024-02-24

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

我正在编写一个依赖 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 构建文件如下所示:

    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 有自己的存储库,并且不将其工件发布到 Bintray。您需要做的是将其存储库添加到 Gradle 中的存储库列表中:

repositories {
    jcenter()
    maven {
       url 'http://www.sparetimelabs.com/maven2'
    }  
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在 Android studio 中使用 Jcenter 和 gradle 的相关文章

随机推荐