Android aar file required dependencies are not loading

Question!

I have a issue in loading the dependencies from maven centeral repository I have a library project and my different client uses my library. My library has dependency on GoolgePlayService as well as appcompat-v7. Recently I start using Gradle instead of ant. So I used andoird-library plugin and I pushed my library.aar file into my local depenency. Now in my TestApp I loaded aar file from local maven, but it is not loading the depenecy file from maven central repository.

The below is my build.gradle file

apply plugin: '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/")
    }
  }
}

When I run "gradle uploadArchives" it is able to upload into my local mavel repository and its pom file looks as below

<?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> 

The below is my TestApp build.gradle file 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:[email protected]')
    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'.  

However it is working fine if I again speciy my library dependencies in my TestApp build.gradle file dependencies section. This mean its loading my library.aar file from local maven repository but not loading appcompat-v7 from maven central repository.

I don't know what the mistake I did here.

Thanks in advance Samba Damerla



Answers

Currently, gradle does not handle transitive dependencies

See this answer for more detail: http://stackoverflow.com/a/20530181/115145

"Only the repository declarations for the project whose configuration is currently resolved are taken into account, even when transitive dependencies are involved."



This video can help you solving your question :)
By: admin