Skip to main content
Notice removed Draw attention by Dan J
Bounty Ended with lance-java's answer chosen by Dan J
Notice added Draw attention by Dan J
Bounty Started worth 100 reputation by Dan J
added 91 characters in body
Source Link
ZakTaccardi
  • 12.5k
  • 16
  • 64
  • 112

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?

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').

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

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?

deleted 233 characters in body
Source Link
ZakTaccardi
  • 12.5k
  • 16
  • 64
  • 112

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" // <-- this line fails with error } } // 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.

It looks like theThe issue has to do with how Android Studio runs the repositories block and caches that information.timing of ../mybinaryImplementation(name: 'my-library/build/outputs/aar will exist with a valid .aar-release', ext: 'aar'), but Android Studio will still report the error.

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

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" // <-- this line fails with error } } // 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') } 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.

It looks like the issue has to do with how Android Studio runs the repositories block and caches that information. ../my-library/build/outputs/aar will exist with a valid .aar, but Android Studio will still report the error.

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

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').

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

Source Link
ZakTaccardi
  • 12.5k
  • 16
  • 64
  • 112

Failed to resolve local AAR built from local source module

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" // <-- this line fails with error } } // 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') } 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.

It looks like the issue has to do with how Android Studio runs the repositories block and caches that information. ../my-library/build/outputs/aar will exist with a valid .aar, but Android Studio will still report the error.

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