Hey I'm pretty new to android studio, and relatively new to android development and it recently occurred to me that I'm not sure whether to put libraries in the libs folder or set them up as as an external library - what's the difference?
Most of what I've found online explains how to include jar files in the libs folder and then compile in the app gradle. This is what I've tended to do, but I've seen projects that work differently and I'm wondering what the protocol is for this.
Also how do you make an external library? Do you just place the jar file in it?
Thanks!
There is no way to create an external library directly in Android Studio. You add a library to your libs folder or add a dependency to your build.gradle, then you reimport the project, and it appears as an external library.
In other words, there is no difference - it's the same thing.
Related
Has anyone found a good way to utilize Android .aar libraries within Unity3D, other than unzipping them?
Snippets from the Unity 4.2 Release Notes:
Android: Added support for Android Library Projects (no compilation
support, so the libraries have to be pre-compiled).
Android: Remove Eclipse project support in favor of Android project support.
Android: Support for Android SDK rev22.
The Unity documentation clarifies
Pre-compiled means all .java files must have been compiled into jar files located in either the bin/ or the libs/ folder of the project.
I'm familiar with using the jar + res/ solution; but I am specifically trying to identify the best way of incorporating the precompiled aar. Is there something better than unzipping it?
With Unity 5, just place .aar files in the project. (They don't even need to be in /Plugins/Android anymore, just check the inspector and make sure they are turned on for Android platform).
This seems to be a common issue when exporting jars with Eclipse. Now, my context.
I'm attempting to write Java plugins to use in Unity applications. When I did a simple plugin with no external libraries (except the classes.jar so I can call a UnityPlayerActivity), it worked pretty well. "Now, let's use some utils libraries". So I wrote a plugin which uses Jackson libraries to parse and process JSON data, so I can serialize it to a Java object, or just pass RAW data, then build a Unity (C#) object.
I add the libraries directly from the file system to the 'libs' folder (copying the .jars, not linking them), add to build path, check every one in the Order and Export, clean and build, and export to JAR file (not runnable, but simple JAR file). Then, I add my new .jar to Unity Assets/Plugins/Android folder, then build my .apk. As soon as the game starts, I get the classic NoClassDefFoundError because of a constructer using a Jackson class. Checking the .jar contents, I find that Jackson libraries are, indeed, exported and within the 'libs' folder, but still it won't "find" it. The error will be thrown by the main thread, thus the application will crash.
I'm using ADT with API 17, so the libs folder must be named 'libs' (even Eclipse does create this folder when creating a new Android project), JRE 1.6 and Jackson libraries ver. 2.2.0. Already followed a lot of questions here, but none of their suggestions has worked for me.
Any pointers here? Has the Android API version anything to do here? Is there something I'm not doing?
Thanks in advance.
I'm quite new to Java, but as far as I can tell when you use an external JAR file it is dynamically linked. In other words, it stays independent - it is not merged into your library.
This was obvious in my case: The external library I used was Google Analytics. Its JAR file, libGoogleAnalyticsV2.jar, is 126 KB. After I added it to my libs directory and built my library I got an output JAR file of only 2 KB...
My solution was to copy the external library JAR file to Assets/Plugins/Android, together with the JAR file I created.
My objective is to create a single distributable jar file for Android projects which includes a few other jar files. As I understand a "standard" jar file is not allowed to have other jar files inside, so guess I need to learn a trick here.
I have been trying to set up One-Jar for this, but I keep hitting
issues. Are there any dev guides for using One-jar with Android projects (using Eclipse)?
Are there any other good alternatives out there I should look at?
jarjar is pretty good at this. When you use it together with Maven its super easy to make a large collection of dependencies a single jar.
Although, there's nothing stopping you including multiple jars as dependencies in an Android project.
I've built OpenSSL into an Android Library that I would like to reference from another Android project.
Unfortunately,
Yes, I do need OpenSSL, as I need to change the behaviour of dependant Android classes not in the public API. (not enough space here)
My experience with native code is non-existant.
The project is selected as a library in Preferences > Android
This library is referenced from a second Android project
My Questions are these
How can I reference the .so files in my Android library from Android.mk in my second project so that I can build dependant files there? I'd prefer not to put the .so files directly in my second project - but if that is the only solution I would accept reasons and directions as an answer.
How should I include/reference the .so file in files I am building in the second project?
Surely, it is something simple.
Thanks in advance.
once you generate (.so) library file, then make a folder in your applitcation's project folder named "libs/armeabi/" put (.so) file in this folder
and in your application write
System.loadLibrary("library_name");
I am trying to use Roboguice in my app, but no matter how i try to add the jars they don't seem to be added to the apk doesn't include the roboguice/guice jars. What do I do? using eclipse 3.5 and adt .9.9
where did you put the jars?
I usually put 3rd party jars in the lib folder at the root of your Project folder (same level as src, assets etc) and they seem to get picked up when building the apk. Make sure in Eclipse you are referring to the jar from the lib folder as well!