Android Studio Library Project Not Generating Jar File - android

How do I build a JAR file from an Android Studio project? I've followed a lot of guides without much success. I tried compiling as a regular and library project but no JAR file get automatically generated. Do I have to do it manually or resort to Ant to get the Jar file?

Android Studio will compile your library into an AAR not a JAR. AARs are a little different since we rely on the SDK rather than a JAR to give use the Android API.
You will find the AAR under LibraryName/build/libs/LibraryName.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.

Android Studio 1.3, why aren't .so files included in my APK

I am new to Android Studio. I am using Android Studio 1.3 because it has built in NDK support. I have a project that can be used as an application or as a library project. When I imported it to Android Studio as an application (and modified the gradle scipts as documented), it built the .so files and included them in the .apk output. When I modified it to be a library project, it is building the .so files, but not including them in the .aar output and hence they are missing in the final .apk. Should I have to do anything to inform it to put the .so files into the .aar? If so, what should I do?
Are you building your .so files by calling ndk-build or by using the gradle or gradle-experimental plugin ?
If your .so files are already built, you can just drop them inside src/main/jniLibs/ folders and they should get included into the .aar as well as the APK.

Can Android Studio library contain resources

I know there was an issue in the past with Eclipse ADT where you could not compile a library project to a JAR if it contained resources.
Is it possible to do this with Android Studio and compile to an AAR file? I would also like to convert the AAR file to JAR and need to know if this will cause issue.
Thanks
With the Android Gradle Plugin, you can package a library as aar or, if your library doesn't contain Android resources, as a jar using this method.

Library Project Supporting Eclipse and Android Studio

I'm working on a library project that provides access to a service. We started the project few months ago and we were supporting Eclipse only (since Android Studio was a prewview edition).
Now that Android Studio has become a "beta" version, and its popularity has increased greatly, we had the intention to support it as welll, but we are facing the problem of how to support both "styles" with the same base (project structure and code).
The library we are building has a UI that forced us to have the library as library project instead of just a simple jar. We have this project working with ANT to build the required files (jars) and packaging everthing in a library project.
Android Studio now introduces the .aar library files, that can also contain UI.
So our problem is finding examples of other library projects containing UI that are also supporting both IDE's. Wondering if someone else have face this same situation.
Is is possible to have a Library Project to support both IDEs? (Eclipse and Android Studio)
Thanks to #CommonsWare. When I looked at your projects I realize that we didn't need our project to be "Android Studio compatible". Since we wanted to share the project as an .aar file, I had only to make a build.gradle at the root of my library project and add the gradle folder (containing the gradle wrapper jars).
In this way I can use the console and create a .aar file using "./gradlew aR" command. Now I can distribute the library project for Eclipse users or the .aar file for Android Studio users.
I'm testing the .aar file, and the only problem I have right now is that classes inside a jar file within libs folder inside the .aar file are not recognized, just the classes present inside "classes.jar", but I think I would create another question here in SOF since is not relevant for this question.

How to distribute an Android Library

I've been spinning a jar for android library project and including this jar in my other apps. But on developer.android.com, I see this statement that I can't distribute a library in a jar:
You cannot export a library project to a JAR file
A library cannot be distributed as a binary file (such as a JAR file).
This will be added in a future version of the SDK Tools.
I really don't understand what does that mean.
It is possible to create an Android library project that does not
include source code. The limitations are:
You still have to ship the resources.
You have to rewrite your code to avoid using R. values, as they
will be wrong. You will have to look up all resource IDs using
getResources().getIdentifier() and/or reflection.
I have the instructions in The Busy Coder's Guide to Advanced Android
Development (http://commonsware.com/AdvAndroid), though the
instructions are new enough that none of my free versions have them.
Quoting some of the instructions from the current edition:
"You 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."
Personally, I'd just wait a bit. I am hopeful that the official
support for library-projects-as-JARs will be available soonish.
It means that (at the current time) you must distribute your entire project folder. Rather than just a jar file like you can for java libraries.
When someone wants to use your library they will import your project into eclipse, and then in project properties->android they will add your project as an android library.
A few common ways used to distribute a Library project are by using git, or zipping your project folder and making it available online.

Categories

Resources