我有一个包含使用Gradle的活动android的库项目。 为了让它工作,我必须添加
compile 'com.michaelpardo:activeandroid:3.1.0-SNAPSHOT'
并为其添加存储库,如下所示:
repositories {
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
}
但是,如果我在库项目中执行此操作,则会收到错误:
Error:A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration ':app:_debugCompile'.
> Could not find com.michaelpardo:activeandroid:3.1.0-SNAPSHOT.
Searched in the following locations:
https://jcenter.bintray.com/com/michaelpardo/activeandroid/3.1.0-SNAPSHOT/maven-metadata.xml
https://jcenter.bintray.com/com/michaelpardo/activeandroid/3.1.0-SNAPSHOT/activeandroid-3.1.0-SNAPSHOT.pom
https://jcenter.bintray.com/com/michaelpardo/activeandroid/3.1.0-SNAPSHOT/activeandroid-3.1.0-SNAPSHOT.jar
file:/Users/user/AndroidSDK/extras/android/m2repository/com/michaelpardo/activeandroid/3.1.0-SNAPSHOT/maven-metadata.xml
file:/Users/user/AndroidSDK/extras/android/m2repository/com/michaelpardo/activeandroid/3.1.0-SNAPSHOT/activeandroid-3.1.0-SNAPSHOT.pom
file:/Users/user/AndroidSDK/extras/android/m2repository/com/michaelpardo/activeandroid/3.1.0-SNAPSHOT/activeandroid-3.1.0-SNAPSHOT.jar
file:/Users/user/AndroidSDK/extras/google/m2repository/com/michaelpardo/activeandroid/3.1.0-SNAPSHOT/maven-metadata.xml
file:/Users/user/AndroidSDK/extras/google/m2repository/com/michaelpardo/activeandroid/3.1.0-SNAPSHOT/activeandroid-3.1.0-SNAPSHOT.pom
file:/Users/user/AndroidSDK/extras/google/m2repository/com/michaelpardo/activeandroid/3.1.0-SNAPSHOT/activeandroid-3.1.0-SNAPSHOT.jar
Required by:
Condeco:app:unspecified > Condeco:common:unspecified
我正在添加我的库模块:
dependencies {
compile project(':common')
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
}
要删除此错误,我必须以相同的方式将存储库添加到主应用程序模块:
repositories {
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
}
当我这样做时,项目编译得很好。
我是否可以使用仅在库项目中定义的存储库来编译我的项目,而无需将存储库添加到主应用程序模块?我只想让图书馆模块照顾好自己。
答案 0 :(得分:0)
我也遇到了这个错误,解决方案就是这样。
您必须编辑build.gradle
模块的app
。
apply plugin: 'com.android.application'
// Add this block
buildscript {
repositories {
}
dependencies {
}
}
repositories {
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
}
// End of this block
android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
..... //Replace dots with your code
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
.... //Replace dots with your code
compile 'com.michaelpardo:activeandroid:3.1.0-SNAPSHOT' //Add this line
}
希望这有帮助。