I read all over the net on how to import a jar file to android studio because I want to import parts of a java program I previously wrote into my android app.
So I already tried the following:
Put the jar into the libs folder and add compile files('libs/my-jar.jar') to the build.gradle (actually I tried both files, the one in app and the one in ´appname´).
Rightclick the jar and clicked "Add as Library"
Cleaned and rebuild (both via commandline and from within Android Studio)
Added the jar via "Project Structure -> Dependencies"
I litterally tried every suggestion on simmilar posts here on stackoverflow I found by googling "use jar in android studio" or "import java archive android studio" etc.
My Problem is, that Android Studio doesnt find the classes within my jar.
It still underlines my code whenever I try to create an Object of one of my classes. Im currently using Android Studio 1.2.1.1.
Do I somehow have to import them in Java Syntax (eg. import my-jar.jar.ClassXY?
I have no experience with java archives. I just exported my Java project from Eclipse by hitting "Export -> As Jar Archive". I also tried exporting as runnable jar file. Is that theoretically enough? When I searched the web it seemed to me this is enough.
Thank you for answers :)
Related
I am trying to add a JAR file into my Android build. I did a copy/paste of the JAR file into the app/libs folder in Android Studio. A quick look-up on how to next integrate indicated I then need to right-click on the jar file and select "Add as library". Strangely enough, this option does not show up. As a result, when I try to import the class, it says package not found. (Even odder, I tried it earlier today on a different JAR file and the "Add as library" option showed up and then I could import the package). It seems I need to set things up so the "Add as library" option appears when right-clicking on the JAR file after copy/paste. But how to make it so?
PS - I did see some slightly relevant stackoverflow posts on this, however, they are farther back in time and Android Studio has changed quite a bit since.
Thanks.
How can I get a jar file from a desktop libgdx project in netbeans?
I know it's a bit late and you've probably figured it out by now, but I'll still answer this for those who don't know.
Right click on your desktop project
Go to the "Tasks" menu
Click "dist"
This will create a standalone JAR file in <pathToYourProject>\desktop\build\libs called desktop-1.0.jar (or something like that).
I don't know if that's the proper way to do it, but it's the only one that worked for me.
I have no experience with this but you should be able to unpack/extract the jar file and then load then load the project into Netbeans.
If it's a gradle project.
If it's not search further since I do not know Netbeans.
Import it with Android Studio and work with my favorite IDE. Choose import none android studio project.
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.
I'm Visual Studios / C#, you can simply add a reference to a DLL file and then just use that namespace. I'm starting to dig into Android development and want to use the SimpleFTP library. Downloaded the .jar file, went to File --> Import and now I've got SimpleFTP.class and SimpleFTP.java in org\jibble\simpleftp in my Package Explorer.
But if I try to import org.jibble.simpleftp; it says it cannot be resolved. What have I done wrong?
I was hoping I could just start typing as if I had properly imported the library and it'd figure out how to correct my package, but no such luck =[
There are at least three solutions:
If you have the source code, you can place it under your src folder directly in your project.
If you have the source code, you can create an Android Library Project with the source code and connect your Android app projec to the library project.
If you have a JAR file, you can place it in the libs folder of your proejct.
Project -> Properties -> Java Path -> Libraries. There you can add your existing libraries, in several formats (jar, .zip, etc.).
Right click on your project and add build path
hi i am a new android developer. When i am searching for a logic related to my app in google, i found a java application which is related to my android app. After making some changes i succeded in getting output, but i need the code to be in an android based project. When i change to convert it i get lot of errors, is there any possible way to convert the java application into an android app by including any external jar file..... The java application is just a part of my android app, based on that i have to develop more so pls help me....
thanx in Advance
If you intend to include external Java code via .jar files, that is supported in Android. Just put the file into the libs/ directory of your Android project and use the classes as you would somewhere else.
If you are using Eclipse IDE, this might help:
After including the .jar files in the libs/ folder, right click on the required .jar file and select "build path", then click on "add to build path". After doing this, u'll notice that the .jar file is added in the "Referenced libraries" in your project. Once done, you are all good to go and import methods from these files. Hope that helps you remove your errors. Happy coding. :)