People say they are the same but they are used in different situations as said in developer site
1-Adding libraries without resources
To add a Support Library without resources to your application project:
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., <sdk>/extras/android/support/v4/android-support-v4.jar) into your application's project libs/ directory.
2-Adding libraries with resources
To add a Support Library with resources (such as v7 appcompat for action bar) to your application project:
Make sure you have downloaded the Android Support Library using the SDK Manager.
Create a library project and ensure the required JAR files are included in the project's build path:
Select File > Import.
Select Existing Android Code Into Workspace and click Next.
Browse to the SDK installation directory and then to the Support Library folder. For example, if you are adding the appcompat project, browse to <sdk>/extras/android/support/v7/appcompat/.
Click Finish to import the project. For the v7 appcompat project, you should now see a new project titled android-support-v7-appcompat.
In the new library project, expand the libs/ folder, right-click each .jar file and select Build Path > Add to Build Path. For example, when creating the the v7 appcompat project, add both the android-support-v4.jar and android-support-v7-appcompat.jar files to the build path.
Right-click the library project folder and select Build Path > Configure Build Path.
In the Order and Export tab, check the .jar files you just added to the build path, so they are available to projects that depend on this library project. For example, the appcompat project requires you to export both the android-support-v4.jar and android-support-v7-appcompat.jar files.
Uncheck Android Dependencies.
Click OK to complete the changes.
You now have a library project for your selected Support Library that you can use with one or more application projects.
when should I use appcompat_v7 (which is generated with the project automatically )
and when to use android-support-v7-appcompat ?
In which case the programmer needs to add library with the resources in the project ?
please feed me with your experience
android-support-v7-appcompat.jar is a JAR file, containing only compiled Java classes. appcompat_v7 is a Library Project, which contains the previous JAR file, no actual source code, and a great many resources (layouts, images, &c).
In the particular case of appcompat-v7, you need to use the Library Project, since it contains necessary UI resources.
Other libraries (such as v7 MediaRouter or v7 Palette) do not contain these resources, and therefore the JAR file can be used directly.
Note that the difference applies mainly to Eclipse (in which libraries with resources must be imported as a project while the others can be just placed in the libs folder). With Android Studio/gradle this is all handled by the build system and therefore the procedure is the same for both. This is well explained in the Support Library Setup documentation.
The generated appcompat_v7 contains the android-support-v7-appcompat library, along with some resources. If you let Eclipse generate your themes and layouts, they will refer to the resources in the appcompat_v7 project and your project won't build without it. I've never encountered a situation where I needed only the library without the resources, but perhaps you might if you wanted to incorporate a new support library feature into an existing project.
Related
PDFbox jar is added in intellij(Setting> Project Structure> Modules> Dependencies) and Have added the gradle dependency as
testCompile 'org.apache.pdfbox:pdfbox:2.0.1'
in gradle build and the build is successful.Even after this importing 'import org.pdfbox...' in java file shows error as cannot resolve symbol pdfbox.
Also tried File->Invalidate Caches\Restart.
Sometimes, you don't need to open the Project Structure dialog to create a library and add it to dependencies of a module. This is the case when there are .jar files within your project content roots.
You can select such .jar files in the Project tool window and use these files to create a library. When doing so, you will be able to select the library level and the module to whose dependencies the new library should be added.
In a similar way, you can use a directory containing .jar files to create a library.
Open the Project tool window (e.g. View | Tool Windows | Project).
Select the .jar file or files to be included in the library, or a directory that contains the .jar files of interest.
Select Add as Library from the context menu.
In the Create Library dialog, specify the library name, level and the module in which this library will be used.
This solved the issue.
I've just updated some things with the SDK and donwloaded update for the ADT. Now I get a red exclamation mark in the Project folder.
The console tells this:
Found 2 versions of android-support-v4.jar in the dependency list,but not all the versions are
identical (check is based on SHA-1 only at this time). All versions of the libraries must be the
same at this time.
Versions found are:
Path: C:\Media\Eclipse Workspace\project1\libs\android-support-v4.jar
Path: C:\Media\adt-bundle-windows-x86_64-20130522\sdk\extras\google\google_play_services\
libproject\google-play-services_lib\libs\android-support-v4.jar
Jar mismatch! Fix your dependencies
Had to say, that I created a project importing google-play-services_lib to set as library in other projects ass this where I had to use google maps.
In Java Build Path\Android Private Libraries I've got 2: google-play-services.jar and android-support-v4.jar.
The console is telling you that you have to different copies of the support library. When Eclipse sets up the project for the first time it will add a copy of the support library. This copy is probably different than the one that comes with google play services library. Make sure that there is a consistent version of the support library across your project.
Dont Include the android-support-v4 in the library , instead you can add it to your project as an external jar using build path menu > add external jar
You can refer to
This and This
.
For each project and library, right click on your project in Eclipse go to Android Tools > Add Support Library. This will download the latest version. Upon doing this on each referenced project and library, they should all then have the same version of the support library and you should no longer see this error message.
Finally I solved.
I removed and installed the "Google Play Services" from the SDK.
Import again the google-play-services_lib project
On Other project's properties in the android tab delete the library and add again
Copy the lastest android-support-v4.jar to the libs folder
I have 2 Java projects in my Eclipse workspace, as follows:
One is a library of code that automatically creates a .jar file whenever it builds.
The other is an application that uses classes in that library, and references the .jar file created by the library project (by right-clicking the app -> Build Path -> Configure Build Path -> Libraries -> Add JARs...)
However, whenever I modify classes in my library project, although I can see that the library .jar gets updated, the app project doesn't pick up the changes unless I remove the library .jar from the app's referenced libraries and re-add it
Am I fundamentally doing something wrong? Is there perhaps a better way to connect an app to a shared library of code? How can I make sure my app will always refer to the latest library code?
Instead of adding it as a JAR dependency you could add it as a project dependency. Right click your project and go to properties. Click on 'Java Build Path' and select the 'Projects' tab. Click 'Add..." and add your library project.
With the latest Eclipse (I'm sure it also worked the same with the ones before), doing a refresh and Clean on your library project then on your application will update the libraries referenced.
I have a Java project which is heavily used by all sorts of other Java and Android projects. The project contains some JAR libraries which shall be used by all projects, except for the Android one (in fact the Android project is a Android library project to be precise).
I marked the JARs as "export" in the Eclipse build path preferences of the Java project. However, the Android project shouldn't import these libraries (as they are Java libraries which make use of some classes which are not available on Android), but it shall import the rest of the code (which doesn't really use the libraries, but they are stored in there for convenience reasons and to ensure, that all other projects use the same library.
How can I prevent the JARs from being exported to the Android projects?
You can prevent all jars from being exported so that only the common project is a dependency for each project that needs it.
Then you can change the build path of each project to only include its necessary jars through the add jar.. dialog in build properties.
That's the easiest way.
A more extreme way would be to move to maven and then eclipse will only include the jars you specify in the pom - though that's a load of extra work for not much gain.
Alternatively, you could split the android specific code into a android-common separate project and then make your common project depend on it and export it - then your android project could rely on this android-common project instead of the existing common project.
I am using Eclipse IDE and its derivative like Spring IDE for Java development.
In a web application project, I add external jars like Spring MVC jars, Apache commons jars etc to the Web App library folder, hence they are automatically added to the build path. There are many jars in the Web App library folder.
I want to create folder in the project and add all the source files (zip/jar) of the libraries included in Web App library folder, so that I can navigate through the source of libraries from the Java editor window. Whenever I add a source zip/jar file to this folder, Eclipse should detect it and use it whenever I want to navigate to the source of a library.
Is the above possible in eclipse?
Note: I know how to add source files
for each individual jar by navigating
to the build path window and
specifying the source location. But
this is very crude way, and I need to
do for every library individually.
Also the drawback is that source path
is absolute, which means if I import
the project into another computer then
I need to create the source path or
even worse I might have to add the
source files individually again.
One way to automagically get the sources for the jars would be some kind of dependency management system. Most people would scream Maven (2/3) by now, but others exist and work well. Maven does have nice Eclipse integration, so that should be a plus.
The downside is that setting up a Maven project just for it's dependency management can seem overkill. Another point is that all the jars you depend on should be "Mavenized" as well.
As far as I know Eclipse wont automatically detect/scan source archive files and link them up to libraries in your workspace in the way you described it.
I agree with #Gressie on using Maven and the Eclipse Maven plugins -- as in that case it's just a matter of ticking a few boxes and Maven will do that for you.
If however your project is not Maven-ized, you can still do this in Eclipse but it's more tedious:
for each one of the jars in your project (which appear under the dependecies section) right click on it and select properties
in the dialog that pops up you have (at least) 2 locations you can configure: java source attachment -- simply browse to your jar with the sources -- and also javadoc location (point it to the jar with javadoc if you want the javadoc to appear as a tooltip when you hover the mouse over one of the classes/methods/etc in that library).