Gradle composite build dependency substitutions do not get applied - android

I have an android application with a library dependency which I would like to be substituted by a local project as described in composite builds
build.gradle (Module: MyApp.app)
dependencies {
implementation 'com.github.myname:lib_project_name:dev-SNAPSHOT'
}
settings.gradle (Project Settings)
include ':app'
includeBuild('../lib_project_name') {
dependencySubstitution {
substitute module('com.github.myname:lib_project_name') using project(':')
}
}
The lib project consists of two subprojects (an example app and the lib itself)
settings.gradle (Project lib_project_name)
include ':app'
include ':lib'
After syncing project with gradle files the lib got displayed in Android Studio as subproject but gradle throughs the warning
Unable to resolve dependency for ':app#debug/compileClasspath':
Could not resolve com.github.myname:lib_project_name:dev-SNAPSHOT.
Any ideas how to solve this?

I've read the documentation more closely and found that
the composite build will substitute any dependency on [module] with a dependency on the root project of [library]
Changing using project(':') to using project(':lib') solved the problem.

Related

Migrating to Gradle Catalogs from BuildSrc in android studio -> "unknown property libraries"

I'm trying to migrate my project from BuildSrc for libraries etc to Gradles "new" Catalogs. But I keep running in to the following error when building:
Could not get unknown property 'libraries' for extension 'libs' of
type org.gradle.accessors.dm.LibrariesForLibs.
Gradle 7.5.1 is running on the project.
I have created ./gradle/libs.libraries.toml which only has one library for testing and looks like this:
[libraries]
somelib = { module = "androidx.annotation:annotation", version = "1.4.0" }
and in a module build.gradle file I'm trying the following:
dependencies {
implementation libs.libraries.somelib
}
But when building the project it keeps crashing on the implementation line saying that libraries is an unknown property. libs however is found.
I have done all the usual cleaning of the project but this persists. Suggestions?
Just skip the 'libraries' part:
dependencies {
implementation libs.somelib
}

Use buildSrc module versions in app module

I'm following this tutorial on how to manage Gradle dependencies with Kotlin in my Android app and now I would like to use the versions defined in my Versions object in my app module (the scenario is that I have an open source screen and I want to show the library versions). How can I do this?
I have tried adding the buildSrc directory to settings.gradle:
include ':app', ':buildSrc'
and then in my build.gradle file, adding it to the dependencies block:
dependencies {
implementation project(':buildSrc')
}
However, when I try to compile and run, the following error is thrown:
Don't know how to compute maven coordinate for artifact 'Gradle API' with component identifier of type 'class org.gradle.internal.component.local.model.OpaqueComponentIdentifier'.
and there is no much information in the web about this error.
Try to remove the buildSrc module from your settings & build.gradle. Its automatically build and accessible for all other modules in this project.

Android Studio 3: how do I import a source code library into a project

The build.gradle in the appfolder contains the following code:
dependencies {
...
compile project(':sclibrary')
}
The settings.gradle file in the project folder contains:
include ':app', ':sclibrary'
project(':sclibrary').projectDir = new File(rootProject.projectDir, '../sclibrary4')
When I synchronize my project I get an error that says "Missing dependencies: unable to find module with Gradle path ':sclibrary' (needed by module 'app'.)"
EDIT:
"sclibrary4" is located in the folder as the "sc" and "ScLite" applications; these applications use common code located in "sclibrary4"
When I try to use the "File>New>Import Module" command, I get the error message "This location is already imported" although
and
Something like this can be fixed with:
remove project dependency from settings.gradle file
remove dependency from build.gradle
gradle sync
Android Studio should show an info that a dependency has been removed
add dependencies again
This worked for me on several occasions, e.g. with Android Studio 3.1.2

Dependency error when using aar library

I have a module with a .aar file in libs folder. I used the solution posted here
[1]: http://kevinpelgrims.com/blog/2014/05/18/reference-a-local-aar-in-your-android-project/ to add the .aar file as dependency and was able to compile the module properly.
Now I want to use this module as a dependency to the main module in my project and compile. However when i try to compile, i do see an error which says that gradle was not able to find the particular .aar file. why would my main module not find a file which is in the libs folder of my sub module. Was wondering if anyone came across this issue.
my project structure is like this
--mainmodule
--build.gradle (submodule as a dependency)
--submodule
--libs
-- abc.aar
Here is the error gradle throws: When unzipping library ':abc:, either group, name or version is empty
If I understand your problem right and you've followed the steps described in the link you shared, then adding this to your mainmodule's build.gradle should do the job:
flatDir {
dirs "../submodule/libs"
}
You basically have the same issue that you fixed in your submodule, since the mainmodule is struggling to resolve transitive dependencies (abc.aar) of submodule.
Recommended way:
While the answer above should fix your issue, Android Studio supports a better way to do this. Import a local aar file via the File>New>New Module>Import .JAR/.AAR Package option in Android Studio v1.3+.
You can then have your submodule depend on that aar-module as follows:
dependencies {
compile project(':aar-module')
}

importing ShowcaseView with gradle

I'm trying to use the ShowcaseView project in my app but can't get the project to build.
when I run 'gradle clean installDebug' I get the following error:
A problem occurred evaluating root project 'hows-it-going'.
Could not find method compile() for arguments [project ':ShowcaseView'] on root project 'hows-it-going'.
I'm using gradle 1.11 and Android Studio 0.54.
I've downloaded the source, and imported the project using file -> Import module -> ShowcaseView
which makes my project structure like:
-project
--app
--ShowcaseView
my settings.gradle file looks like:
include ':app', 'ShowcaseView'
and in my project level build.gradle I have the following:
dependencies {
compile project (':ShowcaseView')
}
Any help with how to include this properly would be much appreciated. Thanks.
The latest version of ShowcaseView is available as a .AAR dependency. To use it, add:
repositories {
mavenCentral()
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots'
}
}
To your build.gradle file and, under the dependencies block, add:
compile 'com.github.amlcurran.showcaseview:library:5.0.0-SNAPSHOT'
I'll get a stable, non-snapshot, version out soon.
It should actually be
compile 'com.github.amlcurran.showcaseview:library:5.0.0-SNAPSHOT#aar'
That way Maven will use .AAR file
I recently just added ShowcaseView to an Android Studio project, and I hope this can push you in the correct direction.
My file structure looks something like this:
project
app
build.gradle
libraries
showcase
build.gradle
settings.gradle
Add the files from the library
folder
of ShowcaseView to the showcase directory in the libraries
directory.
Add the showcase directory as a module to your project.
Change your app's build.gradle file to include:
dependencies {
compile project(':libraries:showcase')
}
Change your settings.gradle to include:
include ':libraries:showcase'
Sync Project with gradle files
This StackOverflow answer goes over how to do this is much more detail if you have any troubles, but this method works for any library.
The compile dependency on ShowcaseView should likely be defined in app/build.gradle, not in the root project's build.gradle. Unless a project explicitly (configurations block) or implicitly (by applying a plugin such as java) defines a compile configuration, it won't have one, and an attempt to add a compile dependency will result in the error you mentioned.
I added this in build.gradle and it worked
compile 'com.github.amlcurran.showcaseview:library:5.4.3'

Categories

Resources