编程语言
首页 > 编程语言> > Java-在Android Studio中将Gradle与Jcenter结合使用

Java-在Android Studio中将Gradle与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添加到我的Project(根)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网址.我如何强制Gradle执行此操作?

解决方法:

com.sparetimelabs:purejavacomm:0.0.22是IOIO项目的可传递依赖项.问题在于,业余时间实验室拥有自己的存储库,并且不会将其工件发布到Bintray.您需要做的是将其存储库添加到Gradle中的存储库列表中:

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

标签:gradle,dependencies,jcenter,java,android
来源: https://codeday.me/bug/20191119/2037997.html