How to use java dependencies to xamarin android project? - android

I have an gradle dependencies:
dependencies {
implementation 'com.github.ekodevelops:eko-gateway-android-sdk:1.2.0'
}
Want to create a *.aar file and use it my Xamarin android project
How to do it?

We could use the following steps to create a Bindings Library from the .AAR file:
Create a new Java Bindings Library project.
Add a single .AAR file to the project. A binding project may only
contain a single .AAR.
Set the appropriate build action for the .AAR file.
Choose a target framework that the .AAR supports.
Build the Bindings Library.
then we could add a reference to the Bindings Library in your Xamarin.android project.
for details, please refer to Binding an .AAR

Related

Looking for JNA Library for Xamarin Android or Xamarin Form Project

one of my xamarin android / xamarin forms project has the dependency
JNA (https://github.com/java-native-access/jna)
I downloaded the jar/aar file and tried converting it to dll so that I can use it in my project but I failed doing so because the JAR file is obfuscated and was giving lot of error while creating a binding library
So my question is, is there any such prebuild library created for the same or nuget available that I can use ?
As far as I know, you can add the .jar file to your project.
Here are the steps below:
Create a new Java Bindings Library project.
Add the .JAR file to the project.
Set the appropriate build action for the .JAR file.
Choose a target framework that the .JAR supports.
Build the Bindings Library.
For more information, you can refer to the Binding a .JAR. This can help you.

Add .jar dependency to Java Library Module Android Studio

I am trying to create a Java library in Android Studio. I want to use functionality of another Java library (third party available as a .jar) in it. So I placed the library in libs folder of my java library project and added the following code in build.gradle file:
apply plugin: 'java-library'
dependencies {
implementation files('libs/libraryname.jar')
}
The .jar reference was added successfully and I can use the library methods in my code. My project also compiles successfully and I am able to generate a .jar file of my own java library project.
However, when I am using the generated .jar file in another project and try to access the methods of third party library, I get the following exception:
java.lang.ClassNotFoundException: Didn't find class
"com.packagename.classname" on path: DexPathList[[zip file
"/data/app/com.packagename-1/base.apk"],nativeLibraryDirectories=[/vendor/lib64,
/system/lib64]]
What I have tried
I have tried multiple solutions provided here and here but none of them works.
I have tried to clean and re-build the project and .jar files as well but that doesn't help as well.
I have added the .jar dependency as a module before referring it in my project but it still generates the same error.
Note:
I am using Android Studio 3.1.4
Copy .jar in your libs project folder: change the navigator to project view, than you are able to see libs directory.
Right click on your jar folder inside your project and select add as library, this will automatically import the library on your gradle dependencies

Android Studio : AAR Library dependency inside another AAR Library

I am using Android studio 1.5. I have a library project, core-speech-service.aar. This AAR file is generated correctly (all classes are built and packed inside classes.jar in the AAR file).
Now I am creating another AAR library google-speech-service.aar which depends on the first AAR (core-speech-service). So I add it as library dependency (compile) in the new AAR library project.
So far, so good. Android studio copies core-speech-service.aar in to the new library project as a library module. But when I build the google-speech-service library project, it creates an AAR file, but the packed AAR file neither contains classes from the core-speech-service.aar neither it has the core-speech-service.aar itself.
Am I missing something ?
Thanks
abhay
You will have to reference the library as an outside dependency on your apk. I believe that as of now you cannot have an aar inside another

Avoid code duplication in Android Studio modules

I've created a project and a library separately using Android Studio, each in a separate folder inside some directory.
I tried to add the library as a module to the project, and noticed that instead of just referencing the library like in Eclipse, the library was copied inside the project directory.
That means that if this happened N times for N projects, then I'll have N copies of the library and I'll need to update them all when any update is to be done.
I'm working on v 1.0.2 of Android Studio.
Any one has a better idea to do it?
Three options I know of:
You can specify the path to the external library:
Android studio add external project to build.gradle
Include the compiled jar file from the library in the libs directory of the N apps.
Publish the artifact (the jar from library project) to a gradle repository and then you can add dependencies to that project just like you would for the support library etc.
See http://gradle.org/docs/current/userguide/artifact_management.html

Build library project

all.
I've created an android library project and it's works perfectly when i reference it from main project. But when i build the library project apart it doesn't contains R.java and resources. Is there way to build a library project with resources and R.java?
It's not possible now.
Now we can create a binary-only library project via the following steps:
Create an Android library project, with your source code and such –
this is your master project, from which you will create a version of
the library project for distribution
Compile the Java source (e.g., ant compile) and turn it into a JAR file
Create a distribution Android library project, with the same
resources as the master library project, but no source code
Put the JAR file in the distribution Android library project's libs/
directory
The resulting distribution Android library project will have everything a
main project will need, just without the source code.
There is some restrictions in this solution:
We still have to ship the resources.
We have to rewrite our code to avoid using R. values, as they
will be wrong. We will have to look up all resource IDs using
getResources().getIdentifier() and/or reflection.
I use Eclipse and never manually build my Android Library Project independently, but I think the development considerations stated on official dev guide here should answer your question:
Each library project creates its own R class
When you build the dependent application project, library projects are compiled and merged with the application project. Each library has its own R class, named according to the library's package name. The R class generated from main project and the library project is created in all the packages that are needed including the main project's package and the libraries' packages.
Update with Another note quoted from the official dev giude Library Projects:
However, a library project differs from an standard Android application project in that you cannot compile it directly to its own .apk and run it on an Android device. Similarly, you cannot export the library project to a self-contained JAR file, as you would do for a true library. Instead, you must compile the library indirectly, by referencing the library in the dependent application and building that application.

Categories

Resources