I have worked on an Android library (an API client) that uses Retrofit and Joda DateTime.
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'joda-time:joda-time:2.8.1'
}
Now that the library is completed I compiled it into an AAR file and I want to use it in an application, so I added it to the libs folder of the application and included it in the build.gradle file like so :
dependencies {
compile(name:'s3papiandroidclient', ext:'aar')
//Some other things
}
However, when I try to initialize the API client from the library, the application crashes when it comes to calling objects from RetroFit or DateTime (For instance, retrofit.RestAdapter). It looks like Gradle does not read the dependencies from the AAR library, thus doesn't install Retrofit and DateTime in my application. I tried to use the transitive=true parameter on my AAR file, does not help.
Other point that might help, I tried to generate a POM file, and the dependencies don't appear in it either. It looks like there's really something going on with these and I am completely stuck on that.
The only workaround I could find is to add manually the dependencies from the AAR file to the app's build.gradle file but it doesn't make sense, I assume Gradle can import dependencies on its own !
Regards,
Gyoo.
It looks like Gradle does not read the dependencies from the AAR library
That is because there are no dependencies in an AAR file.
I tried to generate a POM file, and the dependencies don't appear in it either
Then there is a problem in how you are generating the POM file. Plus, AFAIK, you would need to put the AAR and its POM file in a repository, in order for Gradle to recognize the POM and use the dependency information inside of it.
Related
I have created a library that I share with the world through JFrog Bintray.
I now added a local .aar dependency to my module that I would like to be part of the uploaded package and I don't know how to do it.
I added the local aar via implementation project(path: ':myLocalDependency-1.3.1') but I also need it in the pom I create via a script for the bintray I guess, and have no clue how to do it. Please help
I ended up using Kezong:
apply plugin: 'com.kezong.fat-aar'
I will create a fat arr containing all the dependencies you want.
In your gradle.build file you and the dependency to your local aar like this:
embed project(path: ':myLocalARR-1.3.1-release')
Using embed will ensure that your final arr will contain the java files from your local dependency.
After creating .aar of the module, put that .aar file inside libs folder on project/Module project. Make sure you have added below code in build.gradle
implementation fileTree(dir: 'libs', include: ['.jar', '.aar'])
In an Android gradle project, I see the use of a library called Koin. Normally, as in all Android projects, you include the library in build.gradle like this:
implementation "org.koin:koin-core:$koin_version"
However in this project, there is nothing in any of the gradle files that contain this. I even did a file search to see where it is defined. The only place where I have seen it defined is when you select:
File > Project Structure > Dependencies
But when I build the project, it builds without any problems. How does gradle reference this dependency since it's not in the build.gradle file? Even though it's defined under:
File > Project Structure > Dependencies
there is no clear indication how gradle knows about this.
The dependencies can be located on your machine or in a remote repository, and any transitive dependencies they declare are automatically included as well.
dependencies {
// Dependency on a local library module
implementation project(":mylibrary")
// Dependency on local binaries
implementation fileTree(dir: 'libs', include: ['*.jar'])
// Dependency on a remote binary
implementation 'com.example.android:app-magic:12.3'
}
for more details Android build dependencies and kotlin Gradle
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
I have made an AAR using Android Studio and I can successfully use it in any app. Problem is I have to add all the dependencies it needs manually to the app build.gradle (like compile 'org.slf4j:slf4j-android:1.7.10').
I want the AAR to actually include all these third-party dependencies it requires so I won't have to add them manually in the app. Is there a way you would know of?
If you use
compile fileTree(dir: 'libs', include: ['*.jar'])
and put a jar in libs folder, this jar will be included in the AAR.
But you have to put the jar yourself.
As far as I know, there is no way to put a repository dependency inside an AAR.
I'm using Square's Wire library for my Android app, using Android Studio with Gradle.
I originally added the wire-runtime-1.2.0.jar into a libs folder in my module, and added the dependency to Gradle like this in my build.gradle file:
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
That worked fine.
I'm new to Gradle and Android Studio, but based on the way I'm depending on the Google Support and Play Services libraries, I thought I might be able to remove the wire-runtime-1.2.0.jar library from my repository and just declare a dependency like this (the line is from the Maven repository):
dependencies {
compile 'com.squareup.wire:wire:1.0.0'
}
But if I do that then I hit this error:
Gradle: package com.squareup.wire does not exist
Is there a way to set up this dependency without importing the JAR file directly? Or does that only work for libraries that you can install through the SDK Manager?
Some packages, like com.squareup.wire, have multiple artifacts in Maven Central. You need to choose the right one for your needs. In this case, the equivalent of wire-runtime-1.2.0.jar is the wire-runtime artifact, not the wire artifact.
Here's what your dependencies section should look like:
dependencies {
compile 'com.squareup.wire:wire-runtime:1.2.0'
}