How to create a standalone library in Android using AndroidStudio? - java

I am very new to JAVA/ Android world. I come from C background. The AndroidStudio / Gradle stuff is a bit overwhelming for me.
I am looking to create a library using AndroidStudio. But when I click on "Start a new Android Studio Project" it asks me for Application name and then for activity et al. This is where it gets confusing for me. Why would these details be required to create a library module? Am I missing something here?
I know that there is a File - > New Module Menu and all that stuff, but that comes later once I have set the applicaton details. But here, I dont want to create any application, just the lib (similar to a shared library I would create in C using Makefiles/autotools).
Also, A library in Android world is basically a jar file (like we have *.so in C), right?

1) While Android tools does accept/use Java JAR files, JARs don't contain Android specific stuff like resources (bitmaps,xml) as well as the necessary meta-data to properly merge all of that into a client project. So with the 'new' Gradle based tools we now have AAR format http://tools.android.com/tech-docs/new-build-system/aar-format and the toolchain knows how to handle them.
2) Which brings you to Create aar file in Android Studio

Related

SRC folder of Google App Engine Flexible project is empty

I was fallowing a guide of creating a new java project in IntellIJ IDEA and in the end I got empty folder src without any files or sub-folders in it. Does anybody know what did I do wrong?
I work on this plugin. This is unfortunately all that is available for now using the App Engine flexible new project wizard. I would suggest instead to start from publicly available AE flex github project (such as the one referenced in this guide). You could also start with any Java 8 project as well since you are running on flex - you can then use the plugin to add App Engine flexible support to it:
Tools > Google Cloud Tools > Add App Engine support > Google App Engine Flexible
This will generate a template app.yaml for you and also expose the App Engine plugin features (like deploying to GCP).
There is nothing wrong with the project that you created. Since you were creating a new project, your project has an empty src folder with a .iml file. As eshaul commented, if you selected Create app.yaml box in the wizard, then the project will contain a template app.yaml under src/main/appengine.
Regarding this image, the files in the project helloworld are imported from Cloud Repositories. The procedure to import an existing project in Cloud Source Repositories is explained in the same tutorial that you was following (Checking out an existing project).

How to create a simple/empty Java Library project to compile as an Android Service for Unity?

Coming from someone who's only worked in Java casually / when situations absolutely called for it - I'm having a hard time trying to set this up.
I'm trying to follow along this tutorial to build a native Android plugin usable from Unity:
http://jeanmeyblum.weebly.com/scripts--tutorials/communication-between-an-android-app-and-unity
But unfortunately the author skips over the basic steps (understandable for those with prior android dev experience... but not for me!)
I've gone through a checklist of what I had to install, and so far I have:
Android SDK / Android Studio.
Java SDK / SRE 1.8.
Apache ANT.
Made sure I added all the paths required in my PATH System Environment variable to execute:
android
ant
and... java
But at this point, I have no idea what type of Android project I'm supposed to create (see image).
Other puzzling questions: Which SDK do I choose, do I just leave that to default? How do I indicate that this is only a Service JAR, and not an Activity? (assuming that's what's required to be usable in Unity3D).
And after the project is created, can I just open one of the existing classes to write my Service inside it? Or do I need to create a new class file and extend from Service / IntentService?
I can probably figure out the rest to implement in Unity3D after I can manage to compile the JAR file. It's just that initial step I have no idea how to setup.
You will choose very first one "Add No Activity"
The tutorial you are following might be outdated. Here is a good one : http://eppz.eu/blog/unity-android-plugin-tutorial-1/

Stuck with first time java for android

guys, with my friend started working on a school project - developing a java app for android. He started it, now it's my turn to do my job, so i got the code he already has, set up Android SDK for Eclipse and downloaded all the neccessary files and packages, but it still gives me errors and I can't even run the project.
One of the errors (the main one, I think) is that it can't import android.support.v7.app.ActionBarActivity
If anyone knows what can I do (I've tried all kinds of solutions from the internet, but none work) I would be very grateful.
Here is a screenshot of the code
http://s17.postimg.org/8aw952lha/Capture.jpg
See if you have imported the ActionBar project to your Eclipse workspace, also, right click on your project->properties->android and check that you have referenced/linked the ActionBar project there.
If you are using a repository without the proper ignore files it is possible that you have imported your partners configurations and then have the references to the auxiliary projects broken (you just need to update that).
Hope it helps.
android.support.v7.app.ActionBarActivity is a support library. This allows older versions of Android (before native support for an action bar was available) to use the action bar.
Since you are having difficulty importing it, I'd assume you do not have the support library installed.
Full instructions are available here:
http://developer.android.com/tools/support-library/setup.html
A snippet for adding support libraries to Eclipse:
Make sure you have downloaded the Android Support Library using the SDK Manager.
Create a libs/ directory in the root of your application project.
Copy the JAR file from your Android SDK installation directory (e.g., /extras/android/support/v4/android-support-v4.jar) into your application's project libs/ directory.
Right click the JAR file and select Build Path > Add to Build Path.

Using Android Library on a Regular Java Project

I am looking to use an android class on a regular non-android java project. Specifically I want to use FaceDetector from android.media
I know that there are OpenCV and other libraries I can use to detect a face in an image but I am looking to use androids library. Is there a way to link androids library to a java project?
Thanks
Go to build path of your java project
Add a new external jar
Browse to the location of your android platform installation
(usually C:\Program Files (x86)\Android)
Under android-sdk\platforms\android-x (where x is the version of android you have) select the android.jar file to add to the project.
Now you have the android library under the referenced libraries, and you can use whatever android classes you want in your java project.
Another way of doing that is to use the android source, get only the java files you need from the android library and put them into your java project. The good thing when you do it this way is that you can modify the code and make it more compatible with your java work.
The android library might contain some calls to the system API's. Look for them before including the library with the above mentioned steps. I would recommend you to look into the documentation of the android library and look for the hooks where it calls android system APIs.Modify the source to use your webcam's API and then include it as a library

how to use android libraries in java project

I want to include android libraries in my java project. Actually, I need to run android code in java environment , obviously, this android code would not contain any GUI based action, it will simply use android's predefined libraries ... please suggest to me how android's libraries can be included in java project.
Thanks in Advance !
Find the JAR file containing the libraries you want to use, and add them to the Java project's build classpath.
However this may not work, depending on the Android classes you want to use. Some Android classes will have dependencies on the Android platform which will make it unlikely they will work ... or even load ... on a regular Java platform.
If you want to reference a java jar as reference:
Add that to libs folder in you project
Right click on project -> Properties - > java Build path -> libraries -> add jars
If you want reference a android library project then
Right click on project -> Properties - > Android - > Add (in lower part of window)
You can use android apis in android library project
Setting up library project refer.
You can find the difference between jar library and android library here

Categories