我在从 Maven 中心存储库加载依赖项时遇到问题我有一个库项目,而我的不同客户端使用我的库。我的库依赖于 GoolgePlayService 以及 appcompat-v7。最近我开始使用 Gradle 而不是 ant。所以我使用了 andoird-library 插件并将我的 library.aar 文件推送到我的本地依赖项中。现在在我的 TestApp 中,我从本地 maven 加载了 aar 文件,但它没有从 maven 中央存储库加载依赖文件。
下面是我的 build.gradle 文件
应用插件:'android-library'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.0'
}
}
apply plugin: 'maven'
version = "1.0.0_Build-1"
group = "com.sflibrary"
repositories {
mavenCentral()
}
dependencies {
compile ('com.google.android.gms:play-services:4.0.30') {
exclude module: 'support-v4'
}
compile 'com.android.support:appcompat-v7:+'
compile files('libs/android-support-v4.jar')
compile files('libs/libGoogleAnalyticsServices.jar')
}
android {
buildToolsVersion "17.0.0"
compileSdkVersion 17
defaultConfig {
minSdkVersion 14
targetSdkVersion 17
}
lintOptions {
abortOnError false
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('tests')
}
}
uploadArchives {
repositories {
mavenDeployer {
repository(url: "file://${System.env.HOME}/.m2/repository/")
}
}
}
当我运行“gradle uploadArchives”时,它能够上传到我的本地 mavel 存储库,它的 pom 文件如下所示
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.sflibrary</groupId>
<artifactId>library</artifactId>
<version>1.0.0_Build-1</version>
<packaging>aar</packaging>
<dependencies>
<dependency>
<groupId>com.google.android.gms</groupId>
<artifactId>play-services</artifactId>
<version>4.0.30</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.android.support</groupId>
<artifactId>appcompat-v7</artifactId>
<version>+</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
以下是我的 TestApp build.gradle 文件
apply plugin: 'android'
apply plugin: 'maven'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
repositories {
mavenCentral()
mavenLocal()
}
dependencies {
compile('com.snapfish:library:1.0.0_Build-1@aar')
compile files('libs/httpmime-4.2.1.jar')
}
android {
buildToolsVersion "17.0.0"
compileSdkVersion 17
defaultConfig {
minSdkVersion 14
targetSdkVersion 17
}
lintOptions {
abortOnError false
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
instrumentTest.setRoot('tests')
}
}
I am getting below error
Error Code:
1
Output:
/opt/usr/dev/gradel/AndroidSDK/TestApp/build/res/all/debug/values/values.xml:1549: error: Error retrieving parent for item: No resource found that matches the given name '@style/Widget.AppCompat.Light.ActionBar.Solid'.
/opt/usr/dev/gradel/AndroidSDK/TestApp/build/res/all/debug/values/values.xml:1552: error: Error: No resource found that matches the given name: attr 'background'.
/opt/usr/dev/gradel/AndroidSDK/TestApp/build/res/all/debug/values/values.xml:1556: error: Error: No resource found that matches the given name: attr 'subtitleTextStyle'.
但是,如果我再次在我的 TestApp build.gradle 文件依赖项部分指定我的库依赖项,它工作正常。这意味着它从本地 maven 存储库加载我的 library.aar 文件,但不从 maven 中央存储库加载 appcompat-v7。
我不知道我在这里犯了什么错误。
在此先感谢 Samba Damerla