Ok, this is going to be a really stupid question but I can't figure out a solution. So I added a .jar file to Android Studio the following way:
exported .jar file using IntelliJ IDEA
copied .jar to libs folder under app folder in the Project view in Android Studio
Right clicked the .jar and selected "Add as Library"
The line compile files('libs/MyJar.jar') was added to the build.gradle file. However I cannot figure out how to actually use the classes in the jar. I can't seem to import it at all, and it is as if I didn't actually add anything. What am I doing wrong?
I know this is an idiotic question, but I can't find a solution.
If you've added the jar as you say and if gradle builds successfully after adding the jar then you can just start coding in your Activity you'll get an prompt to import the associated class file in your .jar.
Related
So I have an Eclipse project I have been working on for quite sometime now and my program that backs up the project hasnt been doing it for months, and I never bothered to check the back ups (stupid me). Well the project got corrupt and I lost all the files and dont have a back up that is even close to up to date. However I do have the jar file that is fairly recent (it only contains .class files) and I was curious if anyone knew how to convert a jar file with .class files into an eclipse project. Thanks for the help!
You can follow the steps given below:
Make sure you have a working decompiler in eclipse. If not, please install https://marketplace.eclipse.org/content/enhanced-class-decompiler into your eclipse.
Create a new Java project in eclipse > Right-click the src folder > Click import > Select Archive from the list to import your JAR
Expand the JAR in eclipse and double click a class file to decompile it.
i've been searching all the web for a definitive solution for this simple problem of adding an external directory with .java files and .jar libraries to my Android Studio project.
Here's what I want to do:
Create a default project in Android Studio, and import from git the library I will work on, which is a bunch of .java files and a .jar (jsoup). These java files need this jsoup. The java files are not for Android, just simple java files.
I need it to be from github because I'm working on this lib and I need AndroidStudio to automatically update it to its newest version.
This is how I compile my project:
javac -cp ".:jsoup-1.8.3.jar" Main.java Class1.java Class2.java;
Then I run:
java -cp ".:jsoup-1.8.3.jar" Main
Well, I already loaded this library from github using Android Studio, so now I have:
Project/app/src/main/java/com.myname.myapp
Project/MyLibraryFromGithub
Of course I seen answers like this and I followed everything, but there are some problems. For example, it kept searching for a AndroidManifest.xml file which I don't know how to write because it's a simple java project, not a Android Project. Also, I think this answer is outdated, and won't work properly in AndroidStudio 2.0.
I've read some tutorials on Gradle but it won't say anything about external folders and so. Also, when I make it happen, how do I import my library? For example, in
Project/app/src/main/java/com.myname.myapp/Main.java
How do I import the library? import myLibrary? Or I just need to create new objects with the classe's names? Like Class1 myObject = new...?
This is so congusing! I whish I could compile everything by hand, Gradle is hiding too much from me and I can't find a good tutorial.
To add an external jar to your project you should do the following steps:
Select File >> New >> New Module.
Select Import JAR/AAR Package.
Give the file name in the File name text box and click on Finish.
Select File >> Project Structure.
Select app under the modules section on the left hand side.
Choose Dependencies tab at the top.
Click on the + on the right hand side.
Select Module Dependency
Select the JAR file that you have just imported.
Close both the open windows by clicking OK
Have you tried this?
Place X.jar into the libs folder
Right click on X.jar and 'Add as Library'
(In build.gradle) Place this in dependencies: compile files('libs/X.jar')
I'm trying to import a jar named Security.jar into an Android app that I'm currently working on, however, no matter what I do I cannot get AS to recognize the package that I'm importing. I pasted the jar into the libs folder that I created for the app and synced the gradle files, as well as modified the dependancies, all to no avail. If anyone sees ANYTHING that's wrong please let me know! Here's a link to some pictures pertaining to the issue.
http://imgur.com/a/sEoXi
error log build.gradle
I believe that you should do this:
compile files('libs/your.api.jar')
When you've pasted the jar file in the libs folder. Give it a shot.
A good way to add external JARs to your Android project or any Java project is:
right click on your project ..
then goto properties..
then click on java build path..
then click on libraries...
then click on add External JARs..
select jar file ..
click on ok
I am new to Java so please forgive me if this has a simple solution (and I hope so though). I have added previously coded .java class files to my existing project in eclipse, while trying to import com.abc. and ctrl+space it even shows these packages and classes.
However when I try to compile it says "package xxx does not exist". I've spent hours researching on this but most of the solutions focus on .JAR files and I don't have a jar file. I even tried creating a .JAR file and then importing but I think I couldn't manage to success that.
I really need help about this and thanks for your help.
Regards
First of all you need to understand how to add jar files in eclipse project. You can place you're jar files in webinf lib folder.
And after that you can configure the project build path. By
Right click on project (in eclipse project explorer) > buildpath > you find configure build path.
I downloaded the source to spareparts here
https://android.googlesource.com/platform/development/+/gingerbread-release/apps/SpareParts
It includes Android.mk, AndroidManifest.xml, Notice, res and src folders.
My question is how can I compile this source code in Eclipse? I see there is a make file (Android.mk) which I'm guessing I need to use but I can't figure out what to do to get this thing imported into Eclipse without having 500+ errors.
This article seems to have the answer. According to it you would need to download all of the source just to build one of the apps, though.
Brute force always works :)
Create a new android project in Eclipse named SpareParts
Use the explorer to replace both the src/ and res/ folders inside workspace/SpareParts with the ones downloaded form git
Click with the right button on the SpareParts entry in the project tree in Eclipse -> Refresh
enjoy
I looked into the files and it does not seem that it uses any external library.
If you try to build it by itself, you will still have problems due to these three classes that are not in android.jar:
import android.app.ActivityManagerNative; //cannot be resolved
import android.os.ServiceManager; //cannot be resolved
import android.view.IWindowManager; //cannot be resolved
In Eclipse try File->Import... and General->Existing Projects into Workspace, add the project folder and then try to compile it. Hope it helps.