Failed to resolve local AAR built from local source module











up vote
6
down vote

favorite












I have a library module that I want to include as an AAR dependency into a sample app:



:my-library
:sample-app


So in sample/build.gradle, I do the following:



repositories {
flatDir {
dirs "../my-library/build/outputs/aar"
}
}

// I have different flavors that specify whether to use the source or binary (aar) dependency

flavorDimensions "SOURCE_OR_BINARY"
productFlavors {
source { }
binary { }
}

dependencies {
sourceImplementation project(':my-library')
binaryImplementation(name: 'my-library-release', ext: 'aar') // <-- this line fails with error
}

tasks.whenTaskAdded { task ->
def taskName = task.name.toLowerCase()
if (taskName.toLowerCase().contains("binary")) {
// Prepare libs as binaries
task.dependsOn ('my-library:assembleRelease')
}
}


This works fine with ./gradlew on the command line, but Android Studio reports a Failed to resolve: :my-library-release: during gradle sync. If I do a ./gradlew assemble on the command line, then sync Android Studio, the the AS Gradle sync succeeds.



The issue has to do with the timing of binaryImplementation(name: 'my-library-release', ext: 'aar'). When Gradle Sync is executed, the aar does not exist yet because it has yet to be built.



Is there a better way to do this that will avoid the Failed to resolve Android Studio Gradle sync error?










share|improve this question
























  • Are you sure there isn't any other task that contains 'binary'?
    – lelloman
    Nov 19 at 19:20










  • Are you are building an Android lib along with the application? If YES, I would suggest adding the lib module as a dependency from Project settings window. And once your lib is ready for production you can build aar from lib module and you can add to the app.
    – Nikhil
    Nov 20 at 12:28















up vote
6
down vote

favorite












I have a library module that I want to include as an AAR dependency into a sample app:



:my-library
:sample-app


So in sample/build.gradle, I do the following:



repositories {
flatDir {
dirs "../my-library/build/outputs/aar"
}
}

// I have different flavors that specify whether to use the source or binary (aar) dependency

flavorDimensions "SOURCE_OR_BINARY"
productFlavors {
source { }
binary { }
}

dependencies {
sourceImplementation project(':my-library')
binaryImplementation(name: 'my-library-release', ext: 'aar') // <-- this line fails with error
}

tasks.whenTaskAdded { task ->
def taskName = task.name.toLowerCase()
if (taskName.toLowerCase().contains("binary")) {
// Prepare libs as binaries
task.dependsOn ('my-library:assembleRelease')
}
}


This works fine with ./gradlew on the command line, but Android Studio reports a Failed to resolve: :my-library-release: during gradle sync. If I do a ./gradlew assemble on the command line, then sync Android Studio, the the AS Gradle sync succeeds.



The issue has to do with the timing of binaryImplementation(name: 'my-library-release', ext: 'aar'). When Gradle Sync is executed, the aar does not exist yet because it has yet to be built.



Is there a better way to do this that will avoid the Failed to resolve Android Studio Gradle sync error?










share|improve this question
























  • Are you sure there isn't any other task that contains 'binary'?
    – lelloman
    Nov 19 at 19:20










  • Are you are building an Android lib along with the application? If YES, I would suggest adding the lib module as a dependency from Project settings window. And once your lib is ready for production you can build aar from lib module and you can add to the app.
    – Nikhil
    Nov 20 at 12:28













up vote
6
down vote

favorite









up vote
6
down vote

favorite











I have a library module that I want to include as an AAR dependency into a sample app:



:my-library
:sample-app


So in sample/build.gradle, I do the following:



repositories {
flatDir {
dirs "../my-library/build/outputs/aar"
}
}

// I have different flavors that specify whether to use the source or binary (aar) dependency

flavorDimensions "SOURCE_OR_BINARY"
productFlavors {
source { }
binary { }
}

dependencies {
sourceImplementation project(':my-library')
binaryImplementation(name: 'my-library-release', ext: 'aar') // <-- this line fails with error
}

tasks.whenTaskAdded { task ->
def taskName = task.name.toLowerCase()
if (taskName.toLowerCase().contains("binary")) {
// Prepare libs as binaries
task.dependsOn ('my-library:assembleRelease')
}
}


This works fine with ./gradlew on the command line, but Android Studio reports a Failed to resolve: :my-library-release: during gradle sync. If I do a ./gradlew assemble on the command line, then sync Android Studio, the the AS Gradle sync succeeds.



The issue has to do with the timing of binaryImplementation(name: 'my-library-release', ext: 'aar'). When Gradle Sync is executed, the aar does not exist yet because it has yet to be built.



Is there a better way to do this that will avoid the Failed to resolve Android Studio Gradle sync error?










share|improve this question















I have a library module that I want to include as an AAR dependency into a sample app:



:my-library
:sample-app


So in sample/build.gradle, I do the following:



repositories {
flatDir {
dirs "../my-library/build/outputs/aar"
}
}

// I have different flavors that specify whether to use the source or binary (aar) dependency

flavorDimensions "SOURCE_OR_BINARY"
productFlavors {
source { }
binary { }
}

dependencies {
sourceImplementation project(':my-library')
binaryImplementation(name: 'my-library-release', ext: 'aar') // <-- this line fails with error
}

tasks.whenTaskAdded { task ->
def taskName = task.name.toLowerCase()
if (taskName.toLowerCase().contains("binary")) {
// Prepare libs as binaries
task.dependsOn ('my-library:assembleRelease')
}
}


This works fine with ./gradlew on the command line, but Android Studio reports a Failed to resolve: :my-library-release: during gradle sync. If I do a ./gradlew assemble on the command line, then sync Android Studio, the the AS Gradle sync succeeds.



The issue has to do with the timing of binaryImplementation(name: 'my-library-release', ext: 'aar'). When Gradle Sync is executed, the aar does not exist yet because it has yet to be built.



Is there a better way to do this that will avoid the Failed to resolve Android Studio Gradle sync error?







android gradle android-gradle






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 16 at 19:58

























asked Nov 16 at 15:02









ZakTaccardi

5,71273472




5,71273472












  • Are you sure there isn't any other task that contains 'binary'?
    – lelloman
    Nov 19 at 19:20










  • Are you are building an Android lib along with the application? If YES, I would suggest adding the lib module as a dependency from Project settings window. And once your lib is ready for production you can build aar from lib module and you can add to the app.
    – Nikhil
    Nov 20 at 12:28


















  • Are you sure there isn't any other task that contains 'binary'?
    – lelloman
    Nov 19 at 19:20










  • Are you are building an Android lib along with the application? If YES, I would suggest adding the lib module as a dependency from Project settings window. And once your lib is ready for production you can build aar from lib module and you can add to the app.
    – Nikhil
    Nov 20 at 12:28
















Are you sure there isn't any other task that contains 'binary'?
– lelloman
Nov 19 at 19:20




Are you sure there isn't any other task that contains 'binary'?
– lelloman
Nov 19 at 19:20












Are you are building an Android lib along with the application? If YES, I would suggest adding the lib module as a dependency from Project settings window. And once your lib is ready for production you can build aar from lib module and you can add to the app.
– Nikhil
Nov 20 at 12:28




Are you are building an Android lib along with the application? If YES, I would suggest adding the lib module as a dependency from Project settings window. And once your lib is ready for production you can build aar from lib module and you can add to the app.
– Nikhil
Nov 20 at 12:28












3 Answers
3






active

oldest

votes

















up vote
0
down vote













You need to add this to your app main build.gradle.



    repositories {
/...
/...
flatDir {
dirs 'libs'
}
}


Lets say if you .aar file in the lib folder,then you could do something like this.



implementation files('libs/assembleRelease.aar')





share|improve this answer





















  • this still fails. When Gradle Sync is executed, the aar does not exist yet because it has yet to be built. Unable to resolve dependency for ':sample@binaryDebug/compileClasspath': Failed to transform file 'my-library-release.aar' to match attributes {artifactType=processed-aar} using transform IdentityTransform
    – ZakTaccardi
    Nov 16 at 19:58


















up vote
0
down vote













You can try import with this way,



File -> New Module -> Import .Jar/.AAR package






share|improve this answer




























    up vote
    0
    down vote



    +100










    I suggest that you use a local maven repository rather that flatDir. Dependencies which come from FileCollection and/or flatDir are not as full-featured as those coming from a "real" repository (eg maven/ivy)



    Eg:



    repositories {
    maven {
    url file("${rootProject.projectDir}/mavenRepo")
    }
    }
    dependencies {
    binaryImplementation "my-group:my-library:1.0@aar"
    ...
    }


    You'd then store the artifact using the maven repository directory layout. Eg:



    rootProject/mavenRepo/my-group/my-artifact/1.0/my-artifact-1.0.aar





    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53340361%2ffailed-to-resolve-local-aar-built-from-local-source-module%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      0
      down vote













      You need to add this to your app main build.gradle.



          repositories {
      /...
      /...
      flatDir {
      dirs 'libs'
      }
      }


      Lets say if you .aar file in the lib folder,then you could do something like this.



      implementation files('libs/assembleRelease.aar')





      share|improve this answer





















      • this still fails. When Gradle Sync is executed, the aar does not exist yet because it has yet to be built. Unable to resolve dependency for ':sample@binaryDebug/compileClasspath': Failed to transform file 'my-library-release.aar' to match attributes {artifactType=processed-aar} using transform IdentityTransform
        – ZakTaccardi
        Nov 16 at 19:58















      up vote
      0
      down vote













      You need to add this to your app main build.gradle.



          repositories {
      /...
      /...
      flatDir {
      dirs 'libs'
      }
      }


      Lets say if you .aar file in the lib folder,then you could do something like this.



      implementation files('libs/assembleRelease.aar')





      share|improve this answer





















      • this still fails. When Gradle Sync is executed, the aar does not exist yet because it has yet to be built. Unable to resolve dependency for ':sample@binaryDebug/compileClasspath': Failed to transform file 'my-library-release.aar' to match attributes {artifactType=processed-aar} using transform IdentityTransform
        – ZakTaccardi
        Nov 16 at 19:58













      up vote
      0
      down vote










      up vote
      0
      down vote









      You need to add this to your app main build.gradle.



          repositories {
      /...
      /...
      flatDir {
      dirs 'libs'
      }
      }


      Lets say if you .aar file in the lib folder,then you could do something like this.



      implementation files('libs/assembleRelease.aar')





      share|improve this answer












      You need to add this to your app main build.gradle.



          repositories {
      /...
      /...
      flatDir {
      dirs 'libs'
      }
      }


      Lets say if you .aar file in the lib folder,then you could do something like this.



      implementation files('libs/assembleRelease.aar')






      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered Nov 16 at 17:15









      Ramesh Yankati

      58838




      58838












      • this still fails. When Gradle Sync is executed, the aar does not exist yet because it has yet to be built. Unable to resolve dependency for ':sample@binaryDebug/compileClasspath': Failed to transform file 'my-library-release.aar' to match attributes {artifactType=processed-aar} using transform IdentityTransform
        – ZakTaccardi
        Nov 16 at 19:58


















      • this still fails. When Gradle Sync is executed, the aar does not exist yet because it has yet to be built. Unable to resolve dependency for ':sample@binaryDebug/compileClasspath': Failed to transform file 'my-library-release.aar' to match attributes {artifactType=processed-aar} using transform IdentityTransform
        – ZakTaccardi
        Nov 16 at 19:58
















      this still fails. When Gradle Sync is executed, the aar does not exist yet because it has yet to be built. Unable to resolve dependency for ':sample@binaryDebug/compileClasspath': Failed to transform file 'my-library-release.aar' to match attributes {artifactType=processed-aar} using transform IdentityTransform
      – ZakTaccardi
      Nov 16 at 19:58




      this still fails. When Gradle Sync is executed, the aar does not exist yet because it has yet to be built. Unable to resolve dependency for ':sample@binaryDebug/compileClasspath': Failed to transform file 'my-library-release.aar' to match attributes {artifactType=processed-aar} using transform IdentityTransform
      – ZakTaccardi
      Nov 16 at 19:58












      up vote
      0
      down vote













      You can try import with this way,



      File -> New Module -> Import .Jar/.AAR package






      share|improve this answer

























        up vote
        0
        down vote













        You can try import with this way,



        File -> New Module -> Import .Jar/.AAR package






        share|improve this answer























          up vote
          0
          down vote










          up vote
          0
          down vote









          You can try import with this way,



          File -> New Module -> Import .Jar/.AAR package






          share|improve this answer












          You can try import with this way,



          File -> New Module -> Import .Jar/.AAR package







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 22 at 13:51









          jefry jacky

          361510




          361510






















              up vote
              0
              down vote



              +100










              I suggest that you use a local maven repository rather that flatDir. Dependencies which come from FileCollection and/or flatDir are not as full-featured as those coming from a "real" repository (eg maven/ivy)



              Eg:



              repositories {
              maven {
              url file("${rootProject.projectDir}/mavenRepo")
              }
              }
              dependencies {
              binaryImplementation "my-group:my-library:1.0@aar"
              ...
              }


              You'd then store the artifact using the maven repository directory layout. Eg:



              rootProject/mavenRepo/my-group/my-artifact/1.0/my-artifact-1.0.aar





              share|improve this answer



























                up vote
                0
                down vote



                +100










                I suggest that you use a local maven repository rather that flatDir. Dependencies which come from FileCollection and/or flatDir are not as full-featured as those coming from a "real" repository (eg maven/ivy)



                Eg:



                repositories {
                maven {
                url file("${rootProject.projectDir}/mavenRepo")
                }
                }
                dependencies {
                binaryImplementation "my-group:my-library:1.0@aar"
                ...
                }


                You'd then store the artifact using the maven repository directory layout. Eg:



                rootProject/mavenRepo/my-group/my-artifact/1.0/my-artifact-1.0.aar





                share|improve this answer

























                  up vote
                  0
                  down vote



                  +100







                  up vote
                  0
                  down vote



                  +100




                  +100




                  I suggest that you use a local maven repository rather that flatDir. Dependencies which come from FileCollection and/or flatDir are not as full-featured as those coming from a "real" repository (eg maven/ivy)



                  Eg:



                  repositories {
                  maven {
                  url file("${rootProject.projectDir}/mavenRepo")
                  }
                  }
                  dependencies {
                  binaryImplementation "my-group:my-library:1.0@aar"
                  ...
                  }


                  You'd then store the artifact using the maven repository directory layout. Eg:



                  rootProject/mavenRepo/my-group/my-artifact/1.0/my-artifact-1.0.aar





                  share|improve this answer














                  I suggest that you use a local maven repository rather that flatDir. Dependencies which come from FileCollection and/or flatDir are not as full-featured as those coming from a "real" repository (eg maven/ivy)



                  Eg:



                  repositories {
                  maven {
                  url file("${rootProject.projectDir}/mavenRepo")
                  }
                  }
                  dependencies {
                  binaryImplementation "my-group:my-library:1.0@aar"
                  ...
                  }


                  You'd then store the artifact using the maven repository directory layout. Eg:



                  rootProject/mavenRepo/my-group/my-artifact/1.0/my-artifact-1.0.aar






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Nov 26 at 17:07

























                  answered Nov 26 at 17:00









                  lance-java

                  16.3k12960




                  16.3k12960






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53340361%2ffailed-to-resolve-local-aar-built-from-local-source-module%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown