Gradle aar library dependecy in module: failed to resolve

I’m a newbie with gradle and I’m having a dependecy problem. I have the follow project structure:

-MyApp
-MyAppLibrary
-MyAppPro
-MyAppFree
-ThirdPartyLibraryWrapper
--libs\ThirdPartyLibrary.aar

Both MyAppPro and MyAppFree depend on MyAppLibrary, which depends on ThirdPartyLibraryWrapper. As the name suggests, ThirdPartyLibraryWrapper is a wrapper on an external library, namely ThirdPartyLibrary.aar.

  • How to use NumberPicker in Android app with API 7?
  • How to determine Android internet connection?
  • How to check if URL is valid in Android
  • Converting Bitmap in memory to Bitmap with Bitmap.Config.RGB_565
  • Fragment add or replace not working
  • android code for streaming shoutcast stream breaks in 2.2
  • This is my configuration:

    build.gradle MyAppPro

    apply plugin: 'com.android.application'
    android {
        compileSdkVersion 22
        buildToolsVersion "22.0.1"
    
        defaultConfig {
            applicationId "com.example"
            minSdkVersion 8
            targetSdkVersion 22
        }
    
        buildTypes {
            release {
                minifyEnabled true
                proguardFiles 'proguard.cfg'
            }
        }
    }
    
    dependencies {
        compile project(':MyAppLibrary')
    }
    

    build.gradle MyAppLibrary

    apply plugin: 'com.android.library'
    
    android {
        compileSdkVersion 22
        buildToolsVersion "22.0.1"
    
        defaultConfig {
            minSdkVersion 8
            targetSdkVersion 22
            compileOptions {
                sourceCompatibility JavaVersion.VERSION_1_7
                targetCompatibility JavaVersion.VERSION_1_7
            }
        }
    
        buildTypes {
            release {
                minifyEnabled true
                proguardFiles 'proguard.cfg'
            }
        }
    }
    
    dependencies {
        compile project(':ThirdPartyLibraryWrapper')
        compile 'com.squareup.picasso:picasso:2.5.2'
    }
    

    build.gradle ThirdPartyLibraryWrapper

    apply plugin: 'com.android.library'
    
    android {
        compileSdkVersion 22
        buildToolsVersion "22.0.1"
    
        defaultConfig {
            minSdkVersion 8
            targetSdkVersion 22
        }
    
        buildTypes {
            release {
                minifyEnabled true
                proguardFiles 'proguard.cfg'
             }
        }
    }
    repositories {
        flatDir {
            dirs 'libs'
         }
    }
    
    dependencies {
        compile(name: 'ThirdPartyLibrary-0.1.0', ext: 'aar')
        compile "com.android.support:support-v4:22.0.0"
        compile fileTree(dir: 'libs', include: 'volley.jar')
        compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.3'
    
    }
    

    When gradle sync completes, I have got this error:

    MyApp/MyAppFre/ build.gradle: failed to resolve ThirdPartyLibrary-0.1.0
    MyApp/MyAppLibrary/ build.gradle: failed to resolve ThirdPartyLibrary-0.1.0
    MyApp/MyAppPro/ build.gradle: failed to resolve ThirdPartyLibrary-0.1.0
    

    Can someone help me figure out where is the issue?

    Related posts:

    Android - Losing incoming (hi-speed) USB data
    Recycler view of vertical scrolling list with Horizontal scrollable row
    Android For loop
    Can code be called when my Android application is uninstalled?
    how to start contextual action bar for text view programatically with default opions copy and select...
    Android: Using JNI from NativeActivity
  • TextView:shadowDx/Dy/Radius in dip?
  • How to get Android compass reading?
  • Android: Spinner hint
  • Android check GPS availability on device
  • Streaming to the Android MediaPlayer
  • getheight() px or dpi?
  • One Solution collect form web for “Gradle aar library dependecy in module: failed to resolve”

    The other projects are seeing that the :ThirdPartyLibraryWrapper project depends on an artifact called ThirdPartyLibrary-0.1.0:aar. Java (and Android) libraries do not bundle their own dependencies together – instead, they simply publish a list of their dependencies. The consuming project is then responsible for loading not only the library it directly depends on, but all of the libraries that library depends on.

    The net effect of this is that :MyAppFree is loading in :ThirdPartyLibraryWrapper, then seeing that :ThirdPartyLibraryWrapper depends on ThirdPartyLibrary-0.1.0:aar and so thus trying to load that in as well. However, :MyAppFree doesn’t know where ThirdPartyLibrary-0.1.0:aar lives.. and so it fails.

    The solution will be to place similar repositories blocks in all your other projects. Try this:

    repositories {
        flatDir {
            dirs project(':ThirdPartyLibraryWrapper').file('libs')
        }
    }
    

    Using the project(...).file(...) method will free you from having to hardcode paths, and will instead use the Gradle DSL to resolve the filesystem path by looking up the project and having it do the resolution dynamically.

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.