To resolve my previous question (How to create a floating action button (FAB) in android, using AppCompat v21? ), i found a nice library here: http://android-arsenal.com/details/1/824 , and i downloaded a .zip file.
The web site contains some instructions about the use of the library, but not how to add it to the project with Android Studio (for example: where to copy the downloaded files, and what files i need to copy)
It is the first time that i use a library, and i don't know what i to do.
How do I put it to my project?
Well this was a problem I faced few days back.
Follow the steps and it will definitely work.
STEP 1:
Extract the JAR File from the library and keep it in the Desktop.
STEP 2:
In Android Studio, on the left side,There is a Directory View. There is a dropdown menu on top, which has three choices. Project, Packages and Android - choices. Select the 'Project' section.
Now under that, you will find two Folders - 'Your Application' and 'External Libraries'.
Click on ur Application name and under that, click on the 'app' folder.
Now under that there is a folder called 'libs'. This is the folder where you will paste the JAR file you extracted.
Step 3:
Paste the JAR file inside the 'libs' folder.
After that there is one more important step.
Step 4:
Right-click on the file that you pasted on the 'libs' folder and select the option 'Add As Library'.
Then a popup will appear asking to create the library.
Under 'Add to Module', select 'App'.
Then press ok.
Wait for a while for the Gradle to build it.
After that , Enjoy.
Your new Library is available in your 'imports'.
It's is very simple: Follow the instruction below
copy the line below and navigate to build.gradle file on your project & the open it.
compile 'com.melnykov:floatingactionbutton:1.2.0'
Paste the copied text here:
dependencies {
............................
compile 'com.melnykov:floatingactionbutton:1.2.0'
............................
}
Click the sync gradle file icon on the toolbar.
Enjoy !
If I remember correctly you just drag and drop the library to the AS project. you have to unzip first to have a .jar file.
If you want to use Maven you have to add the dependencies to the gradle.
Related
My question is, I don't want to write XML code for dependencies in the POM.xml again and again.
For example, I want to use the log4j JAR in my project. instead of writing XML code is there any option to download the related JAR files?
Alternate method is downloading the jars from sites like maven or java2s.com and add them to your build path.
You can add a jar in Eclipse by right-clicking on the Project → Build Path → Configure Build Path. Under Libraries tab, click Add Jars or Add External JARs and give the Jar.
Hope that helps
Of course you can download (or copy) these jars, and then manually add them to your build path.
For instance in eclipse, you can select all the libraries under the "Maven Dependiences" and copy them to other folder eg. in other project. Then you need to select these libraries and using the right mouse button add them to build path, done :)
You do not need to write them again and again. You can define and install a parent pom with the common dependencies you use and refer to it in each project pom.
First you could download jars you need in your project from corresponding websites.
Next,follow the steps below:
Step 1: Create a folder under the project to save the JAR package.We usually store jar packages from the outside in the [lib] folder.
Step 2: Copy the jar to the lib folder.
Step 3: Right-click on the project name, and select it in turn [Build Path] - > [Configure Build Path...]
Step 4: In the open window, select the Libraries page and click on the right button the [add JARs...] then select the jar package we just copied into the project, and then click [OK] to close the window.
Finally, we can use this jar package in Eclipse
Yes you can add them through the java build path from your IDE. However, I would recommend that you add these jars as dependencies in the pom.xml and build your project through maven. This will make sure that you will not run into any error regarding the missing dependencies in case any jar gets deleted accidentally or if you want the same set of jars for a new project. And understanding a pom.xml is not a difficult task
I have an android project that consist of .jar file's library and some library project's that have not any gradle file's, when i import this project in Android studio i faced to some error's that tell me this librarie's are not applied how can solve this problem?
To add a Jar Dependency in Android Studio. put that jar file in Your project-->app-->libs folder. and then follow these steps
Go to File --> Project Structure
On the left hand side you will see app module. click on that and then on the right hand side select Dependencies tab
Now click (+) button on the right
Select file dependency
A dialog will appear that let you choose your jar file
select the jar you want to add and click ok. DONE
You need to make sure all your modules that have the support library as dependency also have the compile SDK set to 21 . So go to Project Structure and check all the modules on the left hand side.
I have a library beside my main project in an android project.
How can I set compiler to it always compile library first and then compiles my main code?
Currently I have to compile two times on every build.
To Add Library project to Your Project
1.If you have a jar file then place the jar file in the libs folder in your project.
then right click on it and Build Path-->Add to Build Path
2.If you have a library as a project then right click on your Main project
Properties-->Android-->Add then select your library project(make sure here library projects with librariesonly appear)
3.if your library project is not appearing in this list then rigth click on your library project Properties-->Android tick isLibrary option there)
you can cjheck out the image like..
if you want to change the priority of your Library
Right Click on your Project Build path--> Configure Build path --> Order and Export
there you will see your library select your library click on top at the right side
the image is like below.
I am developing android library project.I don't want share my source code.I want to create something like jar file.But i can't create jar file as it includes xml layouts.so is there any way to build project without including source code?
I can give you an example of such library. Open Android SDK manager and download Google play services library.
This library contains 'libs' folder with google-play-services.jar which contains all the source code. Also there is 'res' folder and android manifest file to be able to add this library to every android project.
First thing is to have the full library-project ( example : FullProject).
Then I import the full library project (FullProject) in a new workspace and check “Copy Projects into workspace”. This new project must have the same name ( FullProject)
in the copy, i removed the source code.
in the app-project i added the source-less-library-project as android library
in the app-project i added the .jar file with all the binary classes from the full library-project ( right clic on directory “source” of the full library-project, export as jar and check « Add directory entry » ).
in the build path of the app project, in "order and export", check the .jar exported
update the manifest file of the app project with all views of the library project .
clean the app project
It’s all !
In my project, I need to use external library. That library consists of .class files. I have added folder with this library to my project using properties -> Java Build Path -> Libraries -> Add class folder. I can compile project without any problem, but when I run it, I get failed resolving xy and debugger stops on line where I create instance of class from imported files.
I guess the external library I use isnt linked to my .apk file. How can I fix this? I have tried to check this library on "Order and Export" tab assuming that, it will export the library with my application. But it didnt work.
How can I link this library to my project .apk? Do I need to somehow install this library on device first? Do I need to copy this library in application folder?
PS: I'm using Eclipse Juno, android SDK target 10.
Thank you
UPDATE
I have this library copied in libs folder. External library path is:
my_project/libs/sk/aicit/leg/libraries*.class
I have added ./libs folder in Libraries settings of project.
I do not have .jar version of this library, only .class files.
I have also souce code of this library, but I didnt want to include its classes in my project, it has its own dependencies, I wanted to just "link" it like library. Its an external library I havent written.
UPDATE 2
I have copied all the source files from library to my projects "src/" dir. I have removed Library from Java build path. I can stil compile my project, but when I run it Iget
FATAL EXCEPTION:main
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{
com.example/myvideorecord/com.example.myvideorecord.Robot}: java.langNullPointerException
...
What can I do, how to debug this error? :(
steps
Copy the library file into libs folder
select jar file -> right click -> Build Path -> Add to Build Path
clean the project Project-> Clean -> select your project -> ok
Android Studio
For importing a Android library into Android Studio, use the following steps:
1) (Optional) I like having my main Android project contain everything it needs to compile correctly, so I move external libraries into the libs/ directory. Generally, you only need to keep the following directories:
res
src
AndroidManifest.xml
*.iml (This will typically be the name of the library you're importing.)
2) Go to your Project Properties.
3) Go to Modules.
4) Import a New Module (Command + N and then Import Module).
5) Navigate to the library directory you want to import.
6) Create module from existing sources.
7) Click Next three times to add the necessary files.
8) Click Finish to complete the module additional.
9) Click on your project in the module list and go to the Dependencies tab.
10) Click the + button at the bottom and click Module Dependency....
11) Make sure your library you're importing is selected and click OK.
12) Click OK in the Project Properties window.
And you should be good to go.
Copy that library file into libs folder
if u have the source code of the library you can import it in eclipse .
Right click on your project -> properties->android -> reference-> add
and add the library project which u have imported. This will include only .class files of the library in ur project