Could not find ....unspecified - android

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'

Related

Android Studio Gradle dependency doesn't show up in External Libraries

I'm using Android Studio 3.0.1 and I'm trying to add an online dependency and while Gradle initially syncs without a problem it doesn't show my dependency in External Libraries and my code that references the dependency doesn't work.
Here's a snippet of what my build.gradle file looks like:
repositories {
mavenCentral()
maven { url 'https://oss.sonatype.org/content/groups/public/' }
}
dependencies {
compile group: 'com.fortysevendeg.android', name: 'swipelistview', version: '1.0-SNAPSHOT'
}
I'm pretty new to android development (took over an existing project from a dev who quit without leaving any documentation) so I'm not sure if this is a mistake with how to add a project dependency or if there is a problem with the dependency that I'm trying to add. Any help would be greatly appreciated!
I was able to get this to work by changing the dependency declaration to:
compile group: 'com.fortysevendeg.android', name: 'swipelistview', version: '1.0-SNAPSHOT', classifier: 'jar-with-dependencies'
The library artifacts up on the repository include an apklib and a JAR with a special classifier. The apklib format is not supported by Android Studio, and unfortunately the classifier on the JAR means that it's not accessible simply using the group-name-version format when declaring dependencies.
Your build.gradle file seems fine. If you want to keep the library specified as an external library, you can try and define the dependency using the alternative notation, replace:
compile group: 'com.fortysevendeg.android', name: 'swipelistview', version: '1.0-SNAPSHOT'
with:
compile 'com.fortysevendeg.android:swipelistview:1.0-SNAPSHOT'
The alternative approach is to download the jar file yourself and use it as a local dependency. If you navigate to the maven repository you can inspect the package which is included as a dependency and download the jar directly. Place the jar file in the libs folder of your project and add the following to your build.gradle file:
compile fileTree(dir: 'libs', include: ['*.jar'])
For further details on how to configure the dependencies of your gradle project, check out the Android Studio documentation here.
Based on the information you have provided, this should fix your issues. If this does not solve the error then there may be other issues with the project.
Your dependencies should not placed in the top-level build.gradle file where the repositories are defined. There is even a comment in that file that says so, by default.
You app dependencies should be the module's build.gradle along with the others like android-support
Additionally, that library is very old, and is a SNAPSHOT build, meaning it isn't meant to be generally used in a release environment. You should find an alternative... And there are plenty of other ListView swiping ones

Gradle can't find transitive dependency for module dependency

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.

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

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