在 Android studio 中将 Jcenter 与 gradle 一起使用
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 添加到我的项目(根)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'
}
}
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()
}
}
编辑:弄清楚了,我对项目范围 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 构建文件如下所示:
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'
}
}
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()
}
}