I'll try to explain as much as possible as this is more of a structural problem than code problem, ok, so i have project in which i am using android-support-library-v4, now in the same project i have now added three new libraries, these libraries also include android-support-library-v4, as they are part of their own code framework,
Now the problem is this is causing a jar mismatch in my project because i now have three same android-support-library-v4 in my project.
I tried the solution of removing the android-support-library-v4 jar file from my main project but this does not resolve the jar mismatch from the other libraries i have used in the project, and i cannot delete the android-support-library-v4 jars from the libraries as they would not work without them meaning they will stop functioning...
Simple solution for this problem , What i usually do is , steps are.
Just copy any android-support-library-v4 from any lib project
Then copy and replace this to all other libs projects.
This will remove your mismatch problem
I will suggest you to use Android Studio as Google official IDE.
Related
I have been successfully using android-support-v7-appcompat library for last few months in my app to support action bar in older devices. Recently I have downloaded the Android 4.4(kitkat) updates with system image and SDK platform from the SDK Manager. I also added targetSdkVersion to "19" in manifest file. But my project was showing error as 'android-support-v7-appcompat jar mismatch. Fix your dependaecies.' Then I added the jar from /extras/android/support/.... to the project as an external jar using build path menu > add external jar. Now there is no error in the project and android-support-v7-appcompat.jar & android-support0v4.jar file is showing twice under 'Referenced Libraries' folder and also once under 'libs' folder. The project is not showing error and running, but crashing in different activities.
Previously I imported the android-support-v7-appcombat library as an external project in the workplace. I can see error in that project. Please suggest what should I do now. Also, android-support-v7-appcompat.jar umder Android Dependencies in Java Build Path showing error.
The error I see is:
Found 2 versions of android-support-v7-appcompat.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:\<project hierarchy>\libs\android-support-v7-appcompat.jar
Path: C:\Users\....\sdk\extras\android\support\v7\appcompat\libs\android-support-v7-appcompat.jar
Jar mismatch! Fix your dependencies
After getting idea from different forum, I removed all the android-support-v7-appcompat libraries from different places, and imported android-v7 support library again in the project. Still it's showing error. Should I also delete android-support-v4 libraries from buildpath and libs/private librariry/referenced library folders?
This error occurs when there are multiple and different instances of the same library are found in the same project, or libraries used by it. A very simple way to resolve this is use the common lib at both the places. To do so:
Just copy your C:\Users....\AppData\Local\Android\android-studio\sdk\extras\android\support\v7\appcompat\libs\android-support-v7-appcompat.jar
and paste it in your libs folder, replace the old one with this. Clean the project, and it shall compile now..
Edit 1:
Basically the idea is if you are using the same libraries, it shall be the common jar, or the same jar.
In your case if you are using the appv7 as an external project, please go to libs folder of your project copy android-support-v4.jar, and paste into the libs of android-support-v7-appcompat project.
Also, make sure if there are other external jars or support libraries used by you, they shall be the similar jars in all the projects you are using.
I hope it helps!
I had exactly the same problem after installing all the updates mentioned in the question. I am sure there are different ways to solve this problem. Here is the way I used:
Previously, when an activity was created, the following project was automatically generated by the wizard:
androi-support-v7-appcompat and this project was added to the build path.
After all the updates, the following equivalent is generated when an activity is created:
appcompat_v7 with the jars of the same names.
I deleted androi-support-v7-appcompat and made sure the projects use appcompat_v7 to replace androi-support-v7-appcompat in their build paths. This made hundreds of errors generated by the duplicates go away.
I am glad that i finally found the answer. I was encountering the same problem again and again and i was like fed up.
Here is the answer to your question.
whenever you get such an error just don't touch anything other than libs folder. Just go directly into the libs folder and right away delete the android-support-v4.jar. and clean build your project. You will be relieved to get rid of errors.
Hope its useful to you.
Keep coding..
I have actually figured out the solution by trying different options suggested from different forum. I had manually change the android-support-v7-appcompat project's(which was added as an external project) project.properties file and had to set 'target=android-19'.
I have used both activiti and tuscany sca tools to make a java project by eclipse IDE, then I got a big problem.
Activiti uses xmlschema-core.jar and Tuscany sca use xmlschema.jar. However those two libs using same package (and all classes in package) org.apache.ws.commons.schema.XmlSchema.
When I build project, I only use methods just of the first libs, but I need all libs actived.
Would you guys give me some solutions? - Change the name of that package this the last solution I thought about :( , because those tools I mentioned before run a whole way, using that package everywhere.
If both jar have same packages I guess they are different versions of the same lib, so you can try to keep only the updated one in the classpath, removing the other one.
I installed a bunch of updates via Android SDK Manager this morning including Android SDK Tools 22.0.1. This has seemed to be disastrous so far. One disaster is handling libraries. Here is the scenario:
I have a project projFoo that uses a library project libFoo. libFoo uses a dozen or so libraries or projects. In other words, libFoo has the following in its Java Build Path:
projA, projB, projC,...
lib1.jar, lib2.jar, lib3.jar ...
I used to need only adding libFoo to the build path of projFoo, and everything was working fine until I installed the updates.
After the updates, I have been adding projA, projB, lib1.jar one by one to projFoo's build path even though projFoo does not use them directly. Without doing this, java.lang.NoClassDefFoundError would occur when I run the app.
I have cleaned all projects and restarted Eclipse many times. I also checked those referenced projects and libraries in Order and Export of libFoo, but adding those references still seems to be necessary. Is this the right way to handle this?
In the order and export tab of Java Build Path make sure Android private Libraries and Android Dependencies are checked.
Any libraries in .jar format should just go in the libs folder of your project. There's no need to add them to the build path.
Any libraries that are a project can just be added to the Java Build Path Projects tab, or if it is an android project, you can add it to the Library section under the Android pane.
I am trying to reference a pure java-Project in my Android-Project -> The Java-Project has a whole bunch of classes I need to use. Oh, and as the first response pointed out: I am using eclipse, yes :)
Only Problem is: I Always get Could not find class 'XXX', referenced from method com.example.helloworld.MainActivity.onCreate. I seem to have missed SOME step or error...?
What I already did:
The Project is added as Project into the Java Build Path (logically nessecary)
It is marked in "Order and Export" in the Java Build Path and pushed to the top (this solved the problem for someone else here when dealing with Jar-files)
Ir is marked in "Project References" on Project settings.
I added the folder where the relevant class is under "Libraries" in build Path... I am not sure if that should be nessecary.
The Java-Project I reference has a whole load of Jars, but if that is the reason, should I not get a different errormessage?
I had the same issue and after some hours of frustration and search I have finally found the answer here:
Android, class not found from imported jar file
Basically, the issue was that the referenced pure-java project or the generated jar was built with Java 1.7, and Android projects are set to use 1.6.
Two ways to do this.
Jar that java project and copy the jar to the libs folder of your Android project.
Add the project as a dependent project to your Android project
Both work wonderfully.
But mind you, this pure-java project must add android.jar and not things like rt.jar :). Else you will get Dalvik exceptions.
Edit :
Dont forget to refresh and Project - Clean your android project.
Two things to check (you mentioned you are using Eclipse):
If your android project needs to use the pure-java project's JARs, check that those JARs are being exported in the build path options of the pure-java project. This is in the build path of the pure-java project you are trying to include, not the build path of the android project that is trying to include it. Under "Order and Export" tab for the pure-java project, note the comment "Exported entries are contributed to dependent projects". In this case, your android project is the dependent project and your pure-java project needs to do the contributing.
Make sure the pure-java project is actually opened in the IDE in addition to your android project. Probably trivial but sometimes overlooked.
If answer does not suffice, you may wish to mention if the missing classes are in .java source files, or if they are only found in JARs in the build path of the pure-java project
Edit: To further track down the issue, please confirm the following to make sure I understood your question:
The pure-java project does successfully build in the IDE
The 'class not found' error is one you are getting when you try and -build- your android project and not when you try and -run- it.
CLASSPATH (aka build path) can be nasty to untangle. If including the project is not working (assuming it does build), you could try building a JAR of your pure-java project and copying (and including) that and all the other JARs into your android project.
The android SDK does certainly complicate the build environment. One way to find out whether the problem is (A) your android project setup) OR (B) the way the pure-java project is packaged) is to create a different pure java project and try including the first one, preferably using the -exact- same line of code that gives you the build error in the android project, if possible.
I am trying to create 2 versions of an Android app (free/paid). I have an Android Library that contains files common to both. I created a new Android project and am trying to use the Library but get the error below:
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: /Users/Zaheer/Developer/App Free/libs/android-support-v4.jar
Length: 349252
SHA-1: 612846c9857077a039b533718f72db3bc041d389
Path: /Users/Zaheer/Developer/App Library/libs/android-support-v4.jar
Length: 337562
SHA-1: 27c24d26e4c5d57976e6926367985548678e913c
Any ideas on how to resolve this? I've been playing with the build path to no success.
Any ideas on how to resolve this?
Delete one.
I've been playing with the build path to no success.
Step #1: Undo all that. If you are messing with the build path, on R16 or higher version of the ADT plugin for Eclipse, you're doing it wrong.
Step #2: Pick one of those two versions of the JAR, or pick the one from the "extras" area of your SDK installation.
Step #3: Put the right JAR in App Library.
Step #4: Delete the one from App Free, since it will pick up that JAR from App Library.
You are welcome to instead have the same actual JAR file in both spots (App Free and App Library), though that just takes up extra space for no reason.
Delete android-support-v4.jar from App Free
Add the same file from App Library to App Free
Above solutions mostly solve the problem. after using these solutions and problem persists. Then
GO to project folder -> libs-> and delete "android-support-v4.jar"
Hoping it would solve your problem as it solved my problem.
There are some scenarios where you have multiple library projects having the the android-support-v4.jar in their libs and build paths and your project has a dependency towards both of them. Say for example in my case I have the following library projects in my workspace,
libfacebook
libsherlockactionbar
Both these projects are independent and my project.properties looks like the following,
# Project target.
target=android-17
android.library.reference.1=../libfacebook
android.library.reference.2=../libsherlockactionbar
When I build my project, I get a jar mismatch problem having duplicate references to two copies of the same file. What I did to solve this issue is a bit of trickery. I created a new library project named libcommons as a parent to all the other library projects in my workspace, including libfacebook and libsherlockactionbar. Then I removed the support library from all other projects and kept only one copy inside libcommons's libs folder. Then I have added libcommons as a reference to all my other library projects. Once cleaned my workspace, everything works like a charm.
This is a more elegant fix than deleting and adding files!
You just need to :
Right Click the project App Free
Go To "Android Tools" > "Add Support Library"
Approve the permissions and let it update the library
Repeat this process for the project App Library
The Android Support Library will then be in sync (:
VERY SIMPLE SOLUTION
A very simple solution worked for my case, just copy the same (android-support-v4.jar) jar file to all the projects. There will be no more conflict.
1 Copy the jar file android-support-v4.jar from libs folder of any one project.
2 Delete the jar file android-support-v4.jar from second project's libs folder which is already existing.
3 Paste the newly copied jar file of first project to libs folder of second project.
The jar mismatch issue will be resolved by now.
Just copy the library from one of the projects to the other one. Maybe the timestamp needs to be the same on both.
Resolution:
Right click on 'free' project > Android Tools > Add Support Library.
Do the same thing on 'paid' project.
Clean all projects
Check if there are irrelevant projects open for you, because that was the case for me, it seemed one of the JAR files was related to a different project, which I wasn't working with, so I just closed that project, did a clean build of the project I'm working on and didn't have the problem anymore! Hope this helps someone!
Use same jar while adding external jars in both library and project
well.. it works for me:
Go to
Project folder > libs
then, delete "android-support-v4.jar"
Then
project > Clean
It will work!
I just had this issue, but instead of deleting the conflicting android-support-v4.jar I just renamed it to android-support-v4_PROJECT.jar, which removed the conflict.
If you are wondering how to rename a file in Eclipse, you just need to highlight the file and press F2.
You just need to have exactly the same android-support-v4.jar checksum on each of your projects.
For this, you can copy/past one of them in all of your conflicting projects / library.
Nothing else to do, clean and enjoy :)
May be you open 2 project same time (both using android-support-v4.jar) . I close 1 project and every thing ok