Android - Adding JAR File to eclipse (hotpotato API) - android

I'm having this problem, and tried googling and doing tutorials in eclipse. But, it wasnt really helpful for me to use this .jar file in my project.
Source: https://github.com/brunodecarvalho/hotpotato
To be specific, I downloaded this jar file , added it to my project successfully by copying the jar file into my source folder , then added it by doing(Properties->Add Jars->And added it). Also i did a Project -> Clean.
Then once I start coding as they have shown in the examples, it gives me errors, which proves that the Adding of Jar file was not successful.
I tried in different eclipse workspaces but still no luck.
If I explain what I'm trying to do here, I'm working on a Android Download Manager Project. What I need to do is to create a pipeling connection to the request URL so that I can download the packets parallel.
Please help me find my mistake. Thanks for your time!

You can try the following:
Remove the jar from the buildpath - and make a folder called libs underneath the root of the project, at the same level as src / bin / etc.
Then put your lib in there, build path issues may then arise if you are in Eclipse but i believe everything should auto resolve from there.
In the past I have put the jar in the libs folder and additionally added it to the build path from there.
Does it error in the IDE, or at runtime?

Not all Java libraries are compatible with Android. Do what RenegadeAndy wrote here, and if that doesn't work, the lib might really be incompatible with Android.
Remember, Android is not a real Java implementation.

Related

archive for required library could not be read or is not a valid ZIP file

Before coming to the problem let me explain what I did that has landed me in the problem.
I created an account on github and made a repository named Android.
Then I installed github client in my windows 7.
Then I opened this client, provided my authentication and cloned the repository to a local directory C:\Users\Aniket\Documents\GitHub\Android(This folder has the .git folder in it).
Then I went to my Eclipse ADT and installed EGit plugin as described here. Also I
Then in Eclipse I right click on my project TicTacToe go to Team->Share Project and provide my repository path i.e C:\Users\Aniket\Documents\GitHub\Android.
My Project was added to the local repository and in my github client it shows me all option to commit file in the actual repository on the github site.
But my project is suddenly showing error with a red '!' sign on it.
Description --> Archive for required library: 'C:/Users/Aniket/AndroidWorkspace/TicTacToe
/libs/android-support-v4.jar' in project 'TicTacToe' cannot be read or is not a valid ZIP file
Resource --> TicTacToe
Path Location --> Build path
Type --> Build Path Problem
Note : the Error was a single line displayed in error console on Eclipse. I just split it up for readability.
Even after detaching repository it shows that error.
Has anyone encountered this scenario before. What is the solution or workaround? I googled and first few links suggest it is an Eclipse bug. Please suggest what can be done to bring my project back to executable state?
It is an Eclipse bug. I have faced the similar problem several times. closing and reopening the project works sometime. if it doesn't work try restarting Eclipse.
I've seen the same issue. I removed that jar file, and then rightclick on the project, select maven, and do "update project...". The jar was downloaded again, and the problem was gone.
There is other case to display error Archive for required library
Right click on project and open --> project project properties --> java build path --> Android private libs
if there are two jar files with same name then remove one from libs.
jar file may the hidden some times then
open you libs folder in window and check if any hidden files are exist
Organize --> folders and search options --> view --> check show hidden files
and Delete the hidden jar file , The same cass delete if hidden java fies exist in src and packages if any
Looks like everyone has different story to tell! For me, I had to delete the error from eclipse Markers tab, and then cleaned the project again. Before that, I closed and re-opened the project/eclipse several times as suggested by #rachit, which did not work for me.
In my case, i'd downloaded project from internet, after unzipping project some files had been blocked, just unblock files and try again, then problem was solved.
In my case I tried all the tips suggested but the error remained. I solved changing version with a more recent one and writing that in the pom.xml. After this everything is now ok.
In my case restarting Eclipse did not solve the problem. I restarted the computer and did a Project -> Clean in eclipse
A solution that worked for me:
go to *.classpath and delete the line :
<classpathentry kind="lib" path="the_problematic_class.java"/>
Could be due to corrupted jar files as well. Better to check that first as that was the reason in my case:
jar tf myjar.jar
should list the content inside.
i was facing same problem in Eclipse Mars. I downloaded the jars from [https://oss.jfrog.org/webapp/#/artifacts/browse/tree/General/repo/org/ethereum/ethereumj-core/1.0.0-SNAPSHOT][1]
and replaced it in the directory.
I got error while adding ethereum.jar using pom.xml at C:\Users{machineName}.m2\repository\org\ethereum\ethereumj-core\1.0.0-SNAPSHOT\ethereum-core-1.0.0-SNAPSHOT.jar , i added the downloaded jar(ethereum-core-1.0.0-SNAPSHOT.jar) here and the problem was solved.
I will say that it can be that some answers work for some cases, but for me it was necessary to go an extra mile. So I will try to make a summary of what can be done:
Verify that the jars are intact:
jar tf myjar.jar
Restart eclipse and update projects setting over right click on project -> Maven -> Update project
The option which has work for me was to navigate in the workspace folder and then delete the files:
.metadata/.plugins/org.eclipse.jdt.core/invalidArchivesCache
.metadata/.plugins/org.eclipse.jdt.core/nonChainingJarsCache
After that restart eclipse and rebuild project.
I found no duplicates anywhere and tried restarting eclipse, rebuild project. I was getting error for only one libary. So I just tried to rename the jar file from ksoap2-android-assembly-2.5.8-jar-with-dependencies.jar to ksoap2-2.5.8.jar
So if none of the problems solves from above you can also try this one
In my case, the java installation was not proper. So, I uninstalled Java and reinstalled a new version. Now, it works.
For us, the problem seemed to be the size of the .jar file. I would recommend doing the following test to see whether this is the case or at least rule it out. First have a look at other jars in your Eclipse project and compare them to the problemetic jar. Is it a lot bigger than the others? If so, try the following workaround. Else, this answer probably won't help you. Before starting, configure Windows to treat .jar files as .zip files with the following command line command:
assoc .jar=CompressedFolder (see https://superuser.com/questions/121540/can-you-configure-windows-to-open-jar-files-like-zip-files-without-a-3rd-party-t)
Optional: A simple Test
Before trying the workaround, here is a test to see if it is indeed the jar file size that's tripping you up.
Create a large .jar full of random .class files that aren't in your problematic jar. You can do this by making a folder full of files, zipping it, and renaming the .zip extension to a .jar. Windows might warn you about changing the extension. Ignore this. Make sure you have enough files in the folder so that it's a bit larger than the problematic jar.
Try to import this artificially created jar. If it fails with the same error, then size is probably the issue.
The Workaround
If it is indeed size that's the problem, which you might have identified by doing the optional simple test above, you can try the following workaround.
Decompress your .jar file. You should be able to do this easily in Windows
Split the folder you get from step 1 into smaller sub-folders. It could be just two folders, or more, depending on how big the original is. You want the folders to be smaller than some of your existing "good" jars so that size won't be an issue. Make sure to keep the package structure intact when you're doing this.
Zip up all the folders you created in step 2, and rename the .zip to .jar.
Import all of the .jars from step 3 individually.
The steps might be a bit unclear, so here's an example. Imagine your jar file was called mylib.jar. You unzip this to a folder called mylib. Inside, let's say there are three sub-folders called package1, package2 and package3. Create 3 folders called mylib1, mylib2 and mylib3, and put in package1, package2 and package3 respectively. Then zip these up and rename extension to .jar. You'll then be importing mylib1.jar, mylib2.jar and mylib3.jar.
For Java web application, web.xml added as jar in the project. In project explorer, try to find web.xml as in jar icon and remove from the project. Error will go away!!
I was stacked on this problem for days despite searching for a solution on the net. I first moved my project to Netbeans and all worked fine. I then returned to eclipse->properties->java compile-> Building and changed "Incompartible build path" option from error to warning and then did maven update and it worked.
I realize this is an old question, but I have yet another solution if none of these work for other people coming across this thread.
I had this same problem, and spent alot of time trying to figure it out, only to find that my Eclipse classpath/buildpath has a .json file in it, it doesn't like that, so it wouldn't compile.
So, check to make sure no text files or json files, etc are in your build path.
I had accidentally put the web.xml into the build path :x

Include cwac-loaderex library in Android Eclipse project

I'm trying to use the cwac-loaderex library in my Android application. I cloned the repository and have imported the included project into my Eclipse project.
At this point I don't have any compilation errors in Eclipse, but when I try to run the application in the emulator I get:
03-23 20:34:16.895: E/dalvikvm(652): Could not find class 'com.commonsware.cwac.loaderex.SQLiteCursorLoader', referenced from method com.alwaysorderdessert.AlwaysOrderDessertActivity.onCreateLoader
How do I make sure that these external dependencies are loaded along with my application in the emulator and are also (by extension?) included in my distributed .apk?
Thanks!
Update
I have added the .jar file to my project and included in the build path, so now my project explorer window looks like the following:
However, I'm still getting the same error in the emulator. Any ideas?
Thanks again.
Update 2
After a bit of Googling and thanks to this SO answer I found that I just needed to check off the .jar file in the Java Build Path > Order and Exports tab.
Update 3
As was pointed out by the comment in the answer below, I should have copied the .jar file to the libs/ directory rather than lib/. This makes the other changes unnecessary (i.e., adding the .jar to the build path, selecting it for export). What a difference a letter makes!
Put the JAR in your libs/ directory, and that should be sufficient.
I noticed that my README was out of date, telling you to add it to your Eclipse build path. That was correct a year-and-change ago but is no longer needed and may contribute to your problems. Hence, if you manually adjusted your build path, undo that. I apologize for the stale instructions.

Runtime error "Couldn't find class com.google.ads.adView"

I'm trying to include ad mob ads to my activity. I did search about this on this site so I did:
input code from https://developers.google.com/mobile-ads-sdk/docs/admob/fundamentals?hl=uk#android
imported the newest .jar into /lib
included the same .jar in Java Build path as an External Jar
I cleaned the project, I Ctrl+Shift+O'ed it.
Compiling was ok, but runtime I get this error, "Couldn't find class .....adView".
Sorry if I don't see an obvious answer. Please help! Thnx
Have you made sure you imported it into the build path? Right click on your project, select properties, and then set the build path. Then select the libraries tab. (This is from memory so it might be a bit different) If you recently updated your admob SDK you need to update it to point at the right jar file.
If that doesn't work a project clean (Project/Clean) never hurts.
Have you created the Activity Admob requires in your manifest?
Perhaps you could try to only copy the jar in the lib repository of your project and not adding it to the External JARs. I've had many problems with external JARs because of this...

IMarketBillingService.java is never created in gen folder of the application?

I have been working on an android application in which I have to integrate In-app billing. I am following the procedure given on the following link but it is not paying off.
http://developer.android.com/guide/google/play/billing/billing_integrate.html#billing-permission
On this link there is a section named Adding AIDL file to your project, When I follow the steps given in the section, I do not find any " IMarketBillingService.java" file in the "gen" folder of the project. What can be the issue? Has anybody faced this issue..?
Any help is regarding the issue is appreciated.
Move .aidl file from project's src folder into some temporary folder.
Clean & build the project (build can fail, its just important that you start it).
Move .aidl file back to its place.
Clean and build again. This time everything should be ok.
Well nothing worked for me like Cleaning and rebuilding project time and again....However creating a new project from the existing project solved the issue. In the new project I was able to add aidl file and then a corresponding java file was created in the gen folder. It might not be the best solution butt only this is the only thing that worked for me after 2 to 3 days of searching and mindstorming, so if someone has a better solution please do share...:-)
right click on project-->select property-->select java compiler-->set compiler compliance level to 1.6 or more than that

Eclipse - ACRA jar file not recognised

I'm trying to add ACRA to my project and I've followed these steps ACRA Basic Setup but Eclipse is not recognising the #ReportCrashes that it has you create with the class:
I made sure I created a "lib" folder and I added the jar file to it (by drag & drop from a windows explorer), I then right-clicked it and choose Add to Build Path. I even tried to remove the jar file and re-add it and do a Project --> Clean but still nothing.
Any ideas as to what I'm doing wrong?
Here's some screenshots of the Annotations from Eclipse:
I've had the same problem, and I think I've discovered the root of it: I was importing the jar inside SRC folder, instead of importing the one in BUILD folder. Just deleted the first one, reconfigured BUILDPATH to remove the wrong entry, did a clean, copied the right (BUILD FOLDER) jar into the libs folder in my project and then everything went OK
Maybe it helps?
OK I figured out the problem. I had the same issue as you and the problem for me was that I added the source jar and not the build jar from the ACRA archive. It now recognizes the classes from the jar. Rookie mistake :)
Robert,
I updated to R20 of the Android SDK Tools today (Aug 15, 2012) and also upgraded to Eclipse Juno and had similar problems with ACRA and my other jar files.
The way I understand it R17 change the build process that any jar in the '/libs' folder is automatically added to the build path. Which means if you had a jar in the '/libs' folder you need to remove it from you java build path or you get the dreaded "Dalvik 1" build error.
Next, I noticed there is no way to add source or javadoc to jars in the lib folder. So I moved all my jars to a second folder, in my case '/external/jar'. When I moved ACRA-4.2.3.jar to '/external/jar' my project would crash with the same error as yours. So I moved it back to '/libs' and it worked, although I could not add javadoc or source to the ACRA jar.
The conclusion is to place the ACRA jar file in the '/libs' folder. Other jar files may be placed in '/libs' or elsewhere. Also, update Android SDK and Eclipse.
Hope this helps you are somebody,
Fish

Categories

Resources