Importing android library to JAVA project on Eclipse - java

Can I import android library such as android 2.3.3 which is included android.jar on it into a JAVA project on Eclipse? How can I do it? Thanks

I don't think you can, and I don't think you should. Android's classes are made for Android mobile devices so you shouldn't use them outside of that context. Do you mind detailing exactly what your project is?

Not sure why would you do that... but yes, you can.
Go to: Project properties -> Java Build Path -> Libraries -> Add External Jar, then choose the .jar file you need, for instance:
C:\Program Files (x86)\Android\android-sdk\platforms\android-8\android.jar
Now your Java project can reference any Android-specific class.

Activate proper android nature, and your project has android libraries on compile path.
You may also add android libraries from maven central:
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>2.2.1</version>
<scope>provided</scope>
</dependency>
But keep in mind, that those libraries are good for compiling only - all classes are neutered and contain only stubs throwing runtime exception - you wull be unable to use them in tests unless you use mocking

I guess I have come across the same problem as Karate_dog, though I'm not sure how similar it is.
Here is what I did:
Go to project properties, select android, and check Android 2.3.3 and press OK. You are done.
Now you will see all the previous error notifications have gone and android API and libraries have been added to your project (I assume this is regarding an android project which running on eclipse ide.)

Related

Using Eclipse instead of Android Studio [duplicate]

I prefer eclipse over android studio, my question is if I can still use it to build projects for future development - for example the recycleview library. It is supported in eclipse too, but will future google libraries continue to support it?
My second question is, if I'm using eclipse to make an app, will it be run on new devices too, as the project structure is different in eclipse and android studio.
My final question is how can I use libraries from android arsenal if I don't use android studio (all the libraries there are for maven and gradle)?
I prefer eclipse over android studio, my question is if I can still use it to build projects for future development - for example the recycleview library. It is supported in eclipse too, but will future google libraries continue to support it?
In the end, it is all just Java, XML, and other such resources. The RecyclerView library is no exception- it is just a library that can be used in any IDE.
The IDE you use for development is just a tool to view and edit these project files. Separately, you use a build system to build the application. Your IDE, the build system, and the project files are completely separate and one doesn't depend on the other to create a functioning application. In fact, you can build an Android application without an IDE at all.
The biggest issue you might run into here is the format of libraries such as RecyclerView. In the Eclipse days (note that Eclipse Android projects typically use Ant for building), most libraries came as either JAR files or Android libraries (of source code). With the release of Android Studio and the Android Gradle plugin, everything is shifting towards Gradle dependencies.
Also be aware that Google is not going to continue supporting Eclipse development. The tools for building Android application in Eclipse will not continue to receive updates, so bugs may pop up in the future that prevent you from continuing to use it effectively.
My second question is, if I'm using eclipse to make an app, will it be run on new devices too, as the project structure is different in eclipse and android studio.
The output of building an Android application is the same regardless of how or where you build it - you get an APK with the same file structure. The structure of the built APK is independent of the structure of the source code.
My final question is how can I use libraries from android arsenal if I don't use android studio (all the libraries there are for maven and gradle)?
Eclipse can use both Gradle and Maven for building. If you want to use libraries as Gradle or Maven dependencies, you will need to set up your project to use either Maven or Gradle to build instead of Ant. Otherwise you can still find JARs for most projects that don't rely on the Android framework, or you will need to get the source code for the library and set it up as a project dependency yourself.

Right way to use Google-Play-Services in a Java SDK

We have a very simple java SDK that can be imported in any android APP to do some basic tasks. One of the functionality of this SDK is to read the AAID, so we depend on Google-Play-Services.
Our current approach is use gradle java plugin and add the play-services.jar as a dependancy to our project. The latest versions of the google-play-services are packaged as .aar. So I need to know if there is any efficient way to do this or extract the aar and add the classes.jar as dependancy. While that will still work but I feel the entire solution is hacky.
I need to know what is the right way to get this done?
Thanks

Can we use Android studio for AOSP development?

Can we use Android studio for AOSP(Android Open Source Project) development, is there a way to do it. I didnt find one. anybody got any idea on this please ?
You can use Android Studio as a IDE for AOSP, since it's just a modified version of InteliJ's IDE.
from AOSP root:
make idegen && development/tools/idegen/idegen.sh
Then just "Open Project" in Android Studio and select the android.ipr it generated.
To import AOSP source in Android Studio or Eclipse, follow the full instructions here :
https://android.googlesource.com/platform/development/+/master/tools/idegen/README
What Pedlar suggested above is one way of doing it. I ran into lot of Jar dependency issues when I tried it with IDEA community edition (Android Studio is a fork of IDEA IDE). The IDE keeps prompting you about duplicate jars etc. The generated project includes framework Java sources as well as App sources. I tried to build an App project which resulted in broken AOSP build. IMHO, IDEA is a great IDE for Java development. But didn't work well with AOSP.
What worked for me is using eclipse to browse/edit/debug framework sources, but build the code from a terminal window. To avoid AOSP build breaks, please create a shadow dir of AOSP (i.e. lndir of AOSP) and use shadow dir for eclipse project.
This is explained at Using eclipse to browse/edit AOSP link in step by step.
If you are working on AOSP, you might want to check Debugging Android framework services.

Android Project with ActionBarSherlock doesn't get built

I implemented the current version of ActionBarSherlock to my Android Project.
Everything works fine and I don't get any errors.
But when I try to debug or export my project I don't get an .apk-file out of my project. Just a .jar-file with the name of my project.
I've read about some problems the SDK had with building projects that contain external libraries but this was at SDK version 14 and so I hope, this bug is fixed...
So there might be another cause for this problem.
Does anybody know a possible solution?
You cannot get *.jar file as the result of building Android project. This seems very strange to me. There must be something wrong with your project settings (if you changed them), or the project you build is of the wrong type (i.e. it is Java Application instead of Android Application).
You didn't mention which IDE do you use, but I assume you use Eclipse.
Make sure you have installed Android SDK and Eclipse ADT correctly (just in case).
Next thing to try is to create a new Android Application project from existing sources (there should be such option during the process of creation).

java.lang.NoClassDefFoundError: how do I fix this error?

I am developing an Android application which makes use of the Osmdroid maps api. I have added the library as an external jar in my build path and I do not get any errors during compile time. However, upon device deployment I get the following error:
03-27 16:18:50.986: E/AndroidRuntime(3306): java.lang.NoClassDefFoundError: org.osmdroid.util.GeoPoint
I have done some googgling and it is still a mystery to me.
Here is my IDE configuration.
Eclipse: Indigo Release version 2
Java SDK: 1.6.0_31
Android SDK: 17
You need to go into Build Path/Order and Export, and check the libs as of SDK 17. Then clean your project.
I doubt about you and your project. From my viewpoint, I see you have a good design. But why are you working with Build Path / Order and Export? Honestly I've never gone to that tab from the first day I worked with Eclipse.
To import jar files as libraries, use tab Libraries -> add external Jars.
And I'm sorry I don't know about game programming, this is just a suggestion: make sure your engine fits what Android supports. For example Android doesn't support javax.imageio. If not, the app can be compiled with external jars, but can be crashed in runtime.

Categories

Resources