[英]Using Jcenter with gradle in Android studio
編輯:想通了,我對項目范圍的 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 添加到我的項目 (root) 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
是com.sparetimelabs:purejavacomm:0.0.22
項目的傳遞依賴。 問題是 Spare time labs 有自己的存儲庫,並且不會將他們的工件發布到 Bintray。 您需要做的是將他們的存儲庫添加到您在 Gradle 中的存儲庫列表中:
repositories {
jcenter()
maven {
url 'http://www.sparetimelabs.com/maven2'
}
}
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.0.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.