Gradle can't find transitive dependency for module dependency - android

I have a project with two Android Gradle modules: a library, :mylib, and an app, :demo. In the build.gradle for :demo, I added a dependency on :mylib:
dependencies {
compile project(':mylib')
}
In turn, :mylib has this dependency:
dependencies {
compile 'com.google.code.ksoap2-android:ksoap2-android:3.5.0'
}
The repo is set up correctly, and :mylib built fine before I added the :demo module to the project. But now when I build, I get this:
Error:Gradle: A problem occurred configuring project ':demo'.
> Could not resolve all dependencies for configuration ':demo:_debugCompile'.
> Could not find com.google.code.ksoap2-android:ksoap2-android:3.5.0.
Searched in the following locations:
https://jcenter.bintray.com/com/google/code/ksoap2-android/ksoap2-android/3.5.0/ksoap2-android-3.5.0.pom
https://jcenter.bintray.com/com/google/code/ksoap2-android/ksoap2-android/3.5.0/ksoap2-android-3.5.0.jar
file:/home/kevin/local/android-sdk-linux/extras/android/m2repository/com/google/code/ksoap2-android/ksoap2-android/3.5.0/ksoap2-android-3.5.0.pom
file:/home/kevin/local/android-sdk-linux/extras/android/m2repository/com/google/code/ksoap2-android/ksoap2-android/3.5.0/ksoap2-android-3.5.0.jar
file:/home/kevin/local/android-sdk-linux/extras/google/m2repository/com/google/code/ksoap2-android/ksoap2-android/3.5.0/ksoap2-android-3.5.0.pom
file:/home/kevin/local/android-sdk-linux/extras/google/m2repository/com/google/code/ksoap2-android/ksoap2-android/3.5.0/ksoap2-android-3.5.0.jar
Required by:
MyProject:demo:unspecified > MyProject:mylib:unspecified
I don't understand why :demo is even aware that :mylib uses ksoap2, let alone why it tries to resolve the dependency itself. I don't think there's anything public or even protected in :mylib that exposes its use of ksoap2.

Since you are including a module, gradle is trying to resolve all nested dependencies (somenthing similar to a pom file).
The library com.google.code.ksoap2-android isn't in the jcenter or maven central repository and it is the reason of your issue.
Just add the repository where gradle can find this library.

Related

Gradle composite build dependency substitutions do not get applied

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.

Could not find ....unspecified

I recently wrote a java module and pushed it to maven but when I test it,there are some errors:
Error:Could not find PreferenceAnnotion:preference-annotation:unspecified.
Searched in the following locations:file:/Applications/Android Studio.app/Contents/gradle/m2repository/PreferenceAnnotion/preference-annotation/unspecified/preference-annotation-unspecified.pom
....
Required by:
TestPlugin:app:unspecified > com.github.merlinyu:preference-processor:1.0.0
My module code dependencies:
compile project(':preference-annotation')
I don't know how to fix it.
the github :https://github.com/MerlinYu/PreferenceAnnotation
When you add Gradle dependency this way:
compile project(':preference-annotation')
Gradle searches for local Gradle module named preference-annotation.
It doesn't resolve the dependency through maven.
To include a dependency coming from a Maven repository you have to use this meta format (replace with proper values):
compile 'groupId:artifactId:version(:classifier)(#packaging)'
In your case you have to add:
compile 'com.github.merlinyu:preference-annotation:1.0.0'

getting issues while adding other gradle project as library

actually i have been trying to import another gradle project as library from github and i know that there are two ways to do that
1)by adding url to dependencies in build.gradle file
this method gave lot of errors
2)manually download library and import it as module, then add dependencies
and i somehow succeeded by using second method ..
after that gradle sync worked correctly but while running application it gives some bizzare errors like
Error:(23, 0) Gradle DSL method not found: 'ompile()'
Possible causes:The project 'AppIntro' may be using a version of Gradle that does not contain the method.
Open Gradle wrapper fileThe build file may be missing a Gradle plugin.
Apply Gradle plugin
and the github link is as follows
https://github.com/PaoloRotolo/AppIntro
i imported folder called as library in that....
You can add this library in many ways:
Add a simple dependency in your build.gradle file
Just use:
dependencies {
compile 'com.github.paolorotolo:appintro:3.4.0'
}
Use the jitpack plugin
Just add this repo to your build.gradle
repositories {
// ...
maven { url "https://jitpack.io" }
}
And the dependency:
dependencies {
compile 'com.github.User:Repo:Tag'
}
download the module (the library folder) locally.

Gradle sync not auto-resolve Android library project dependencies with #aar annotation

I've created an Android library project found here: https://github.com/dbotha/Android-Photo-Picker
The photo-picker library project itself has several dependencies of it's own:
// library build.gradle
dependencies {
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.squareup.picasso:picasso:2.5.2'
}
I've made this library project available on Maven Central so that it can be easily added to applications as a dependency:
// application build.gradle
dependencies {
compile 'ly.kite:photo-picker:1.1.2#aar'
}
The problem though is that when I come to add it as a dependency to a new Android application project it crashes because it can't find the Picasso dependency from the library project:
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.squareup.picasso.Picasso" on path
It's only when I explicitly add this dependency to the applications build.gradle do things work.
My libraries POM file dependencies looks correct: https://repo1.maven.org/maven2/ly/kite/photo-picker/1.1.2/photo-picker-1.1.2.pom
So I'm curious if applications that include my photo-picker library as a dependency always need to explicitly add all the photo-picker library dependencies too?
You are using the #aar notation.
It means that you want to download only the aar artifact, and no dependencies.
You can check this part of documentation:
Check the 1.4.1.2. Artifact only notation section:
An artifact only notation creates a module dependency which downloads only the artifact file with the specified extension. Existing module descriptors are ignored.
Using the #aar notation if you want to download the dependencies, you should add transitive=true.
I'd expect that omitting #aar it should work.

Gradle incorrectly resolving dependency artifactId

I have a dependency that looks like this:
dependencies {
apt 'io.sweers.barber:barber-compiler:1.3.0'
compile 'io.sweers.barber:barber-api:1.3.0'
}
This dependency does exist in both jcenter and mavenCentral, but whenever gradle resolves it, it uses the incorrect artifactId (dropping the "barber-" prefix).
Error:Could not find io.sweers.barber:api:1.3.0.
Searched in the following locations:
https://jcenter.bintray.com/io/sweers/barber/api/1.3.0/api-1.3.0.pom
https://jcenter.bintray.com/io/sweers/barber/api/1.3.0/api-1.3.0.jar
https://maven.fabric.io/public/io/sweers/barber/api/1.3.0/api-1.3.0.pom
https://maven.fabric.io/public/io/sweers/barber/api/1.3.0/api-1.3.0.jar
file:/Users/hsweers/dev/android/android-sdk/extras/android/m2repository/io/sweers/barber/api/1.3.0/api-1.3.0.pom
file:/Users/hsweers/dev/android/android-sdk/extras/android/m2repository/io/sweers/barber/api/1.3.0/api-1.3.0.jar
file:/Users/hsweers/dev/android/android-sdk/extras/google/m2repository/io/sweers/barber/api/1.3.0/api-1.3.0.pom
file:/Users/hsweers/dev/android/android-sdk/extras/google/m2repository/io/sweers/barber/api/1.3.0/api-1.3.0.jar
Required by:
MyAppProject.app:unspecified > io.sweers.barber:barber-compiler:1.3.0
If the dependency would resolve correctly to https://jcenter.bintray.com/io/sweers/barber/barber-api/1.3.0/barber-api-1.3.0.pom
If it helps, the library can be found here: https://github.com/hzsweers/barber
Turns out the problem is somewhere in my library and causing the generated pom for the compiler module to use the api module name rather than its artifactId. Hotfixed it for now

Categories

Resources