Android Studio: Jar library use by import line - android

I was reading https://developers.google.com/cardboard/android/download. It said to download libraries which happened to be jar files. I've found how to add jar to my project in Android Studio. The question is
1) Can I add them to Studio so that in next projects I can use the libraries by just adding "import" line and how?
2) For the example it says "git clone https://github.com/googlesamples/cardboard-java.git". I don't know Git. I downloaded the example which is zip of file directory. Can I just open it in Studio without the "git clone" command and how (by the way, example contains jar libraries mentioned in point 1)?
Thank you very much!

You can work with project without using "git clone".
Download project archive, unpack it and open in AS with File - New - Import Project.

Related

How to import android library from GitHub to eclipse

How to add gradle library in android project.
We download the project from github.
https://github.com/michael-rapp/ChromeLikeTabSwitcher
We follow these step but it showing the error.
Import the library folder from above zip as Android project.
It create folder of main with blank src, so we copy the data from folder java
to src.
After refresh in eclips it's showing error in src folder of functions.
We also import example folder and follow the same step as above, but no luck.
Let me know if i do something wrong or can you test this library on your eclips.
Thanks..
Download archive android.jar from https://jar-download.com/download-handling.php in Downloads folder. Then connect it to android project in Eclipse by means of project Properties/Java build path. That is all.
This will be the universal solution for all your eclipse android projects while android.jar is in Downloads folder.

Can't import the volley library in eclipse

i just got the volley library from the below link..
git clone-https://android.googlesource.com/platform/frameworks/volley
in eclipse i am following steps
import>git>project from git>....etc
and the library got downloaded in C:\Users\active\git\volley
when i just want to import the volley folder to the eclipse(C:\Users\active\git\volley) it shows "Select at least one project" in IMPORT PROJECT.and their is only one project though i have selected that still it shows the same error on the top..seriously need a help...thanks in advance
You need to build the jar and then add it to your libs folder in your project.
How to build the jar:
$ git clone https://android.googlesource.com/platform/frameworks/volley
$ cd volley
$ android update project -p .
$ ant jar
source
Here is a YouTube video if that would help: https://www.youtube.com/watch?v=5bwn7DYt2AI
You can also download a non-official build on maven central.
Edit:
It looks like volley can't be built with ant anymore (correct me if I'm wrong). All I did was create a new Android Project, mark it as a library project, create package com.android.volley, copy the source over to the project, and build it.
Check whether the project name is already exists in your workspace.
Right Click any project and click on properties.
Look at the directory of current WorkSpace under location.
Delete any existing copies of Volley or project with the similar name.
Re-import Volley.

How can I use this UndoBar Library in my Android project?

I found this library to make a "undobar" (https://github.com/jenzz/Android-UndoBar), but I do not know how to install it. On some websites I read that I must right click on my project, then go to Properties-> Java Build Path-> Libraries-> Add External JARs and select the Zip file that I downloaded, but it's still not working.
What am I doing wrong?
Clone the GitHub project locally to your machine.
Import the lib as a project into Eclipse
RightKlick on your project in the Package Explorer selecting Properties / Android
Under Library klick on add and select the lib's project
Some aditational OK's should do the trick.

How to add source + javadoc for android-support-v7?

I added to my project support library android-support-v7-appcompat, but I can't add source and javadoc for it.
I downloaded https://android.googlesource.com/platform/frameworks/support/+/master package with source and in Eclipse I set Source attachment to v7/appcompat/, but it doesn't work.
Can someone help me?
E: my solution is, I have two projects in Eclipse "android-support-v7-appcompat" (original lib from android-sdk\extras\android\support\v7\appcompat) and "android-support-v7-appcompat-src" (src from android.googlesource.com) and when I compile release version, so I used original lib and for debug I used src from googlesource.com.
PS: sorry for my english
I was able to attach the source based on advice from How do I attach the Android Support Library source in Eclipse?.
Here's what I did:
First, clone the source repository and get whatever version corresponds to the released library (which I guessed):
git clone https://android.googlesource.com/platform/frameworks/support
cd support
git checkout android-4.3.1_r1
Next, in Eclipse:
Right-click project and choose Properties.
Select Java Build Path
Select the Libraries tab
Add External JARs > YourProject/libs/android-support-v7-appcompat.jar (I know your project had already referenced to it but don't worry, just add it again).
Expand jar and attach Source to the External Jar: WhereverYouHaveTheSource/support/appcompat
Switch to the "Order and Export" tab, move the external jar above the "Android Dependencies"
Or the same using #andr answer to How do I attach the Android Support Library source in Eclipse?
git clone https://github.com/android/platform_frameworks_support android_sources_folder
add android-support-v7-appcompat.jar.properties file into libs (next to android-support-v7-appcompat.jar) with content
src=D:\\android_sources_folder\\platform_frameworks_support\\v7\\appcompat\\src
close and reopen project
Sources for appcompat-v7 are available within "API21/Sources for Android SDK" package which can be downloaded with SDK Manager, the path is \sdk\sources\android-21\android\support\v7\
Android Studio will allow you to browse lib source code when you point this dir as appcompat-v7 source dir root.

Why can't android find com.google.gson.Gson

I'm trying to use GSON in my project, but my application is crashing, with logcat saying that com.google.gson.Gson cannot be found. I've put import com.google.gson.Gson on my class files, I have gson in my package explorer, and added it by Right click -> build path -> add libraries. It also shows up in Project->properties->java build path->libraries tab->gson. What have I done wrong?
What worked for me: Check the checkbox next to the lib (gson-2.0.jar) in: 'Project Properties' -> 'Java Build Path' -> 'Order and Export' tab. Then do a clean/build.
This adds the exported=true attribute to the classpath entry
<classpathentry exported="true" kind="lib" path="libs/gson-2.0.jar"/>
Have you put the jar file in the libs folder of the project? If not , try moving it there, creating the folder if required. Should be at the same level as the src folder.
I had a similar issue trying to get an app built and that solved it.
I'm using IntelliJ, not eclipse but here is how I did it:
Download the source files from https://google-gson.googlecode.com/files/google-gson-2.2.4-release.zip
Unpack them
Copy them into the "libs" folder of your project. I did this manually by using the terminal but you can do it by going in your project folder located in your computer. Your Project_Name >app >Libs [paste them here]
Go to your editor (IntelliJ in my case) You should see the the following 3 files in the libs folder of the project structure:
gson-2.2.4.jar
gson-2.2.4-javadoc.jar
gson-2.2.4-sources.jar
Open your build.gradle file and insert the following line in the dependencies section:
compile files('libs/gson-2.2.4.jar', 'libs/gson-2.2.4-javadoc.jar', 'libs/gson-2.2.4-javadoc.jar')
Right click on each of the source files and select "Add as Library..."
Use the following options:
Name: name of the jar file
Level: Project Library
Add to Module: select project your adding to
Rebuild project
Build > Rebuild project
Import and use it!
import com.google.gson.Gson;
I have observed today that it doesn't like when you add your library.
The solution that worked for me was to add it as an external jar only. I have observed it by doing the steps described by author of this post i.e. Properties -> Java Build Path -> Libraries -> Add External JARs and point to the downloaded gson library.
I ran into the same issue (when installed SDK 17) ...
The solution is, that you just put the pure jar files into the "libs" folder (without subfolders).
You also don't need to declare them, android wil find them itself. You may need to do a Project > Clean
I had similar problem, but I guess my requirement was more complicated as the GSON libarary was used by an Android Library Project that my main Android project depended on. I have tried both approaches above but none of them worked for me. If I add the GSON jar file directly to the main Android project it works, but that is not what I wanted.
With a bit of investigation I have realised that the GSON jar does not use any dependencies (third party libraries) itself. So my solution was to copy the source file of the GSON project to my Android Library project's src filder and it worked like a charm. so you can use the Source code rather then the binary code. The source code is part of the download in a jar file, just unzip it.
i'm sure you have copied the jar into "libs",
and also added property> Java Build Path >(tab) Libraries, right?
my issue was stupid...
please check other than Gson jar, if you have two stuffs at least in above tab:
android x.x
Android Dependencies (especially this one, i missed this, eclipse show me an error of "could not find class com.google.gson.xx" )
simply do a project copy will solve this problem...
Do not edit .classpath file directly or even put files into lib folders out of Eclipse.
Instead use the Java Build Path->Order and Export tab to select libraries to be exported in the final deployment unit (eg war/apk)
To be on safer side, do a Project->Clean after you change the build path.
I faced the same thing.But the solution was quite easy,just Right-Click on your project->Properies->Libraries->Add external jars->OK and thats it.It solved my problem.hope it will solve yours as well
If Projct Properties -> Java build path -> Add external jars doesn't work and your project is a web project, try adding the gson jar directly to the server lib folder. Example: for apache Tomcat to apache-tomcat/lib.
I have been trying the same thing and read so many answers and tried so many things but to not vial, but i solved this problem by doing just one click and its simple.
1) Add your .jar file in libs folder make sure its libs not lib
2) Clean and Build your project you will see that file under libs folder
3) right click the file and go to build path and select add to build path
Run your project it will work fine. Hope this helps
I am using Android Studio
I had the same problem I had solve it by
select project press f4 from popup
click app and in dependencies
select file dependency and select the three folders which I had pasted in lib directory

Categories

Resources