Gradle only downloads pom from mavenCentral - Android - android

I have successfully deployed an AAR artifact to mavenCentral using Sonatype's OSS Nexus but when i reference it on another project gradle is only downloading the pom and it's respective ASC file to ~/.gradle/cache.
This is my build.gradle http://pastie.org/private/zaxa13hsd52e4elfpnne4w
This is the build.gradle for the library https://github.com/Machinarius/PreferenceFragment-Compat/blob/master/build.gradle
Can anyone point me in the right direction?

The aar.asc packaging is coming from this section in your gradle configuration:
configurations {
archives {
extendsFrom configurations.default
}
}
Remove those lines from your build.gradle file and deploy again. You should see the packaging be aar now.

The value for the POM's packaging element (aar.asc) looks wrong. You should nevertheless be able to fetch the artifact with something like dependencies { compile 'com.github.machinarius:preferencefragment:0.1#aar' }. With this "artifact only" notation, you won't get transitive dependencies, but you can always declare those yourself.

Related

importing an existing JAR or AAR as new project module

how to import JAR or AAR package as new project module in A new Android Studio Arctic Fox | 2020.3.1 Canary 9 ?
please let me know.
This works on Android Studio Arctic Fox Beta 02
Step 1 : Navigate to, File -> Project Structure. You can also press Ctrl+Alt+Shift+S
You will see a window just like below.
Step 2 : Click On app module as shown in image
Step 3 : Click on + icon as marked in image
Step 4 : You will see option to select jar/aar dependency. Click on it
You will see another window just like above asking you to specify path. Specify the path in which you kept the aar/jar file and hit Ok.
That should work
You can directly implement using JAR/ARR file path.
implementation files('/File Path/file.aar')
For Android Studio Bumblebee, original answer given here
I have followed steps suggested by the Android developer site:
Copy .aar file into the libs folder of the app
File -> Project Structure... -> Dependencies
Click on "+" icon and select JR/AAR Dependency and select app module
Add .aar file path in step 1.
Check your app’s build.gradle file to confirm a declaration.
Step 1: Put your aar file in the libs folder. And let’s take the file name is supernover.aar as an example.
Step 2: Put the following code in your Project level
build.gradle file,
allprojects {
repositories {
jcenter()
flatDir {
dirs 'libs'
}
}
}
and in the app level module write the below code,
dependencies {
Implementation(name:'supernover', ext:'aar')
}
Step 3: Then Click sync project with Gradle files.
If everything is working fine, then you will see library entry is made in build ->intermediates -> exploded-aar.
In my opinion, the best way to do this is to deploy the jar/aar to a local maven repository. if you install maven, you can use the mavenLocal() repository in gradle and read from there as with any other repo, regardless of the IDE you are using. All versions of Android Studio will work, all version of IntelliJ will work, VSCode will work, the command line will work, etc. Another advantage is, you'll be able to swap versions of the library as you do with all the others, just change the version in gradle (after deploying the new one), and will work for all your projects. Putting jars/aars manually into a project is just a bad practice, and reaaally outdated to top.
Once you installed maven, type this in your terminal:
mvn install:install-file -Dfile=d:\mylibrary-{version}.aar -DgroupId=com.example -DartifactId=mylibrary -Dversion={version} -Dpackaging=aar
Where you swap aar and jar depending on the type. The package name, group ID and library name are up to you, anything will work. I would use the library's package and name, and version 1.0 if you don`t have a version.
Here's an example link. Is old, but the process is the same. mvn install, then consume from mavenLocal().
For anyone in search of a solution still.
Create a new android Application project.
Convert new project into a standalone Library module.
Add maven-publish plugin to the module-level build.gradle
Connect your project to your Github repository (or create a new one).
In the module-level build.gradle, implement the Github Packages authentication flow. I'm using 'zuko' as an example - replace every instance of that name with your Github login.
android {
...
publishing {
repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/zuko/[git-repository]")
credentials {
username = 'zuko'
password = 'token' // this is a Git Personal Access Token
}
}
}
publications {
release(MavenPublication) {
groupId 'com.zuko.libraries'
artifactId 'choose-a-name'
version '1.0.0'
artifact("$buildDir/ogury-mediation-mopub-5.2.0.aar")
// you can actually put the artifact anywhere you want.
// This is the location of where you place your .aar file
}
}
}
...
}
If everything is connected properly, save your work, and run the the task: ./gradlew publish. The error logs are straightforward so just defer to the instructions and Google for more assistance.
To install a successfully published package into your desired project, use the same auth procedure for publishing.repositories, you don't need the second half, publishing.publications.
example: implementation 'com.zuko.libraries:choose-a-name:1.0.0'
You could configure a repository in you buildscript that looks for dependencies in a local directory
Use this to register a local directory as repository in your app module's build.gradle where libs is a directory under app module (<project>/app/libs/)
buildscript {
repositories {
flatDir { dirs 'libs' }
}
}
then declare your dependencies from the local file tree you registered earlier
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
}
This will include all jar/aar artifacts present under libs directory to be included in your module's dependencies.
PS: Local jar/aar artifacts will expect any transitive dependencies to be on the classpath unless they are fat-jars (package all transitive dependencies within the artifact), so these need to be added explicitly as dependencies.

Android Gradle not finding remote AAR

I was working with Gradle v5.4 and Android Gradle Plugin v3.5.2, and had no problems!
I have a remote Artifactory repository where I upload .aar files that are needed in my project.
When I updated to Gradle v6.5 and Android Gradle Plugin v4.0.1 those .aar files are no longer downloaded.
This is how I add those dependencies:
implementation "ar.com.sebasira:some-library:1.0.0#aar"
This was working just fine before the upgrade.
In the logs I can see that AndroidStudio looks for it in this location:
https://myrepo.com.ar/ar/com/sebasira/some-library/1.0.0/some-library-1.0.0.pom
If I put that URL in the browser, indeed there's nothing to be found, but if I change the last part (the extension) to .aar I can download the artifact.
I thought that adding #aar was to instruct Gradle to look for .aar file but it seems not to be working.
I've also try adding the dependency like in this other way with no luck.
implementation group: 'ar.com.sebasira', name: 'some-library', version: '1.0.0', ext: 'aar'
I've found out that since Gradle v6.0 onwards, Gradle assumes that if no .pom file is present in the remote repository is because the artifact does not exists, so it does not look for it by default. According to release notes:
If Gradle fails to locate the metadata file (.pom or ivy.xml) of a module in a repository defined in the repositories { } section, it now assumes that the module does not exist in that repository.
...
You can opt into the old behavior for selected repositories by adding the artifact() metadata source.
So the solution is to add that to repository in question, like this:
repositories {
maven {
url 'the-repo-url'
metadataSources {
artifact()
}
}
}

How to publish in my maven local repository an existing aar with gradle?

I have a project that have the following structure:
projectRoot
build.gradle
module1/
build.gradle
artifact1.aar
module2/
....
My artifact1.aar is a compiled artifact and i have no access to the sources.
my module 1 gradle build file is the following:
configurations.maybeCreate("default")
artifacts.add("default", file('artifact1.aar'))
With this the code contains in the .aar is available in module 2 by simply reference a gradle project dependency.
But i want to publish the .aar in my maven local, in order that it can be accessible for other android project.
I check the maven-publish plugin and the android-maven-publish plugin but the two seems to be called after java-library plugin or com.android.library plugin.
So my question is how to publish in my maven local repository an existing aar with gradle ?
I'm using gradle in version 4.8.
I used an rxbinding aar for this example.
As you correctly mentioned, there has to be a subproject in the "publisher" project, which must contain the aar, and a build file with the following content:
// rxbinding/build.gradle
apply plugin: "maven-publish"
configurations.maybeCreate("default")
def publishArtifact = artifacts.add("default", file('rxbinding-2.1.1.aar'))
publishing {
publications {
aar(MavenPublication) {
groupId = 'my.sample.artifact'
artifactId = 'somerandomname'
version = '1.0.0'
artifact publishArtifact
}
}
}
You can apply the maven-publish plugin to any project, but then you have to define the artifacts manually, like we've just done here. Some plugins (like the java-library plugin) are integrated with the maven-publish plugin to automatically publish the default artifacts of the project.
Now run ./gradlew rxbinding:publishToMavenLocal - This should place the artifact into your local repo
Add implementation 'my.sample.artifact:somerandomname:1.0.0' to the consumer app, in any project on your machine.
It is very important to mention any aar published this way, will not bring it's dependencies, so you have to know what libs are needed to actually use the published aar.
I have also created an example project, where you can try this.
If you have maven installed, you could use the install-file goal of the maven-install-plugin.

Third Party Android Library Format

I have downloaded a lot of libraries from Github. When I want to add it in android studio, there's no .jar file in every library I have. Why is it that it has no jar file ? How do I add those libraries in android studio?
Whenever possible, you should find the correct line to add to the dependencies block in your build.gradle file. For example, look at the README for the Boom Menu library which you mentioned in your comment. Under the heading Gradle & Maven, you see
compile 'com.nightonke:boommenu:2.1.0'
Add this line to the dependencies block in build.gradle, sync Android Studio, and then use the library as you wish.
libraries from GitHub... Example is the Boom Menu library
This one? ... Well, you're just not reading the documentation
Otherwise, if there isn't a BinTray dependency.
This is exactly what JitPack is for
To get a Git project into your build:
Step 1. Add the JitPack repository to your build file
Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Step 2. Add the dependency
dependencies {
compile 'com.github.User:Repo:Tag'
}
Regarding your questions
Why is it that it has no jar file ?
Because GitHub isn't meant for storing (potentially large) binaries of compiled code, and many Android libraries prefer BinTray over GitHub releases.
How do I add those libraries in android studio?
You could clone them directly into your project
app/
build.gradle
library/
build.gradle
settings.gradle
build.gradle
In settings.gradle
include :app, :library
In app/build.gradle
dependencies {
compile project(":library")
}

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