How to use Google Maven Dependency in android projects? - java

How should i change build.gradle and other files in android projects to add dependencies offline?
I downloaded Google Maven Dependency from developer.android.com but i don't know how should i use it?

The official documentation covers very useful topics, including the one you're asking about.
dependencies {
// Dependency on a local library module
implementation(project(":mylibrary"))
// Dependency on local binaries
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
}
https://developer.android.com/studio/build/dependencies

Related

Third Party SDK won't read imports, even when the dependency is in the Build Gradle

I had imported a Third party SDK from another project. I had set it up and it wouldn't read a certain Dependency, even when I had put the dependency in the build gradle.
Here's the SDK
And in the build.gradle
// dependency needed to use SDK
implementation "org.altbeacon:android-beacon-library:2.16.3" <- That's the dependency
implementation project(':parabit_beacon_sdk')
implementation 'org.jetbrains:annotations:20.1.0'
implementation "com.google.android.gms:play-services-location:21.0.1"
I've tried a few things already, but nothing seems to be working. Any help is appreciated. Thanks
There is no version 2.16.3 of org.altbeacon:android-beacon-library in Maven central repository:
https://mvnrepository.com/artifact/org.altbeacon/android-beacon-library
Unless you have configured an additional repository where this library is present, Android Studio can simply not resolve this library and thus the import statements for this library show an error.
Note that JCenter repository does no longer exists. The version you want to use was once published there but as the repository no longer exists you can not use it anymore from there.
Change your gradle config to use a version that exists on Maven central.

dependencies for a library jar using gradle

I am using gradle 6.7 and creating a library project which is compiled to a jar that is placed in my own s3 artifacts repository.
In my project I have dependencies to other artifacts and I use implementation dependency.
The jar is created (not a fat jar) and uploaded to the s3 repository.
When in another project I am using my library by fetching it as implementation dependency I am getting errors NoClassDef for other dependencies I used in my library, which means that no runtime is found for the dependencies I was using in my library.
My question is, whether it is a good idea to create a fat jar? I don't think that other libraries (e.g. springboot and others) are using fat jars, right? however when I use them as dependency other dependencies are found on runtime.
Does it mean that using implementation in my project for other dependencies is not the right way? shall I use something else? Could you please contribute a bit more about what is the right way?
Thank you
Check out the Java Library Plugin for gradle. It exists for this exact situation.
If a dependency of your library needs to be exposed to the consumer of your library, then you would use api instead of implementation. There is a nice section within the plugin documentation here that can be used to help you identify when to declare a dependency as api vs implementation.

How to include reference to library in java gradle project

I am coming from a C# background. I am used to NuGet and Visual Studio project references so the Java ecosystem has confused me quite a bit.
I have a gradle library project. I want to import org.apache.commons.codec.binary.Base64;
However I keep getting cannot resolve errors.
I am using VSCode as my IDE and I would like to include the codec dependancy. How would I achieve this in VSCode/gradle.
I have downloaded the commons-codec-1.14.jar file, but don't know where to put it in the project.
Gradle is a tool that, among other things, manages your dependencies. This means that, you do not need to manually download and add dependencies to your project. Gradle solves this for you.
See the official documenation on how to handle dependencies with Gradle.
You probably have a build.gradle file, in which you need to include your dependency. It would look something like:
dependencies {
implementation 'commons-codec:commons-codec:1.14'
}
This lets Gradle know that you have a dependency to version 1.14 of commons-codec which your codes need to build and run.
This will automatically be downloaded from a remote repository, which you also can specify in your build.gradle file:
repositories {
mavenCentral()
}
This tells gradle to download the dependencies from Maven Central, which probably is the most typical Maven/Gradle repository and most likely hosts most dependencies you would need.

How to specify dependency in a JAR library

I am creating a JAR library and publishing it to nexus using Gradle for other projects to use. How can I specify that my JAR has a dependency on another library (Commons Lang 3)?
I strongly recommend you follow the guide on building a Java library with Gradle. It contains the information you are looking for.
In short, your build file needs something like:
repositories {
mavenCentral()
}
dependencies {
implementation 'org.apache.commons:commons-lang3:3.7'
}
And the publication to a maven repository will take care of adding that information to the Maven pom file that will be used by consumers of your library.

How to add Google vision dependencies to my .aar?

I am creating an android library (.aar) that is using the Google android vision Gradle dependencies for OCRing. But I am unable to figure out how should I can add the Gradle dependency to the .aar File.
I don't want to add Google dependency separately while using my .aar because my library project already contains the same.
I have tried one solution by pushing the .aar file to local maven then using the same in the application but in that case I was still unable to find the Google Vision classes to use.
Thanks.
#user3572586, same issue faced, when you build aar file only project source added in aar not dependency lib. so you need to add externally.
Or
You need to publish your aar in maven repository (local or remote) and including it using compile (...#aar) transitive dependencies are turned off.
For more info see link below's,
Link1
Link2

Categories

Resources