I keep getting the error java.lang.NoClassDefFoundError: com.facebook.android.Facebook when running my application.
This occurs when calling:
facebook = new Facebook(APP_ID);
Addtional error message:
Could not find class 'com.facebook.android.Facebook', referenced from method com.example.example1.ShareOnFacebook.onCreate
I have add the facebook .jar file via Referenced libraries in Eclipse.
Has anyone encountered/solve this problem?
Just go to Project / Properties / Java Build Path / Order and Export and click on jar's checkbox. This will set jar as "exported". You can verify this in .classparh file:
classpathentry exported="true" kind="lib" path="/my-jars/facebook-android-sdk-1.2.1.jar"
Don't forget to clean your project after that (Project / Clean...)
I heard that with the latest ADT you need to name your library folder "libs" and not "lib". But that didn't work for me.
So instead I had to resort to moving my jar file into the "assets" folder. That fixed my problem.
Completely retarded if you ask me.
I keep getting this issue too, the "Library Projects" (which should contain the com_facebook_android.jar) is not reflected in the "Package explorer" at all. But It is easily solved.
Right click on project>Properties>Android> Library -> remove the facebook library project added -> apply.
Then add the facebook library project again and click apply. This time "Library Projects" will come up in your Package Explorer on the right side.
Have you recently updated your ADT or Android SDK? Try deleting the reference to the facebook library or facebook jar and re-adding it.
They changed the way they handle external libraries references in the latest ADT updates, and it's thrown off a ton of my projects. Deleting the references and re-adding them seems to do the trick.
A solution that worked for me:
the android-support-v4.jar file inside my project had a different version from the one inside facebook's project. So I copied facebook's support lib to my project libs folder and it worked like a charm.
Related
I have a rather big Android App project that is referencing several library projects. Everything was fine until i upgraded the eclipse ADT plugin to the newest version (v22). I also upgraded the SDK of course. I do not see any compile errors in eclipse, but when i run the project on the phone i get a NoClassDefFoundError.
java.lang.NoClassDefFoundError: org.acra.ACRA
....
The arca library is included in one of the referenced library project (in the libs folder) and i can see it in the "Android Private Libraries" in the package explorer, also as i said, no compile errors. The project runs fine on everyone else's computer that did not upgrade ADT.
I have already tried a whole bunch of stuff including but not limited to:
re-install the android SDK
download a fresh ADT bundle
delete all my code an get it again from git
copy the library in question to the app project
comment out the code that uses this library - i just get the same error for the next library
all without any success, so i'm getting really desperate here.
I would be really happy if anyone could give me a hint on how to solve that problem.
Quoting Streets of Boston from his adt-dev post:
When upgrading, the 'Order and Export' of the new 'Android Private
Libraries' is not always checked. And the android-support-v4.jar is now in
this 'Android Private Libraries' section.
To fix this, go to 'Order and Export' and check 'Android Private
Libraries'. Then refresh/clean/rebuild.
After you done this 'fix' for a library project, you may need to just close
and re-open any depending project, because they may not see this 'fix'
immediately.
Give this a shot and with luck it will solve your problem.
Simply checking Android Private Libraries was not enough, I also had to install Android SDK Build-tools in Android SDK Manager.
I had also the same problem and my adt was 22.0.1. And none of the solution above worked. Further when adding a external library project to a working project.I always check the gen folder of working project and if R of external library project is there (along with package name),then only external library project is exported. And on my gen folder no packagename of external library was shown.
So I checked on project.properties file and there wasn't any external library link present android.library.reference.1= present. So I manually added the external library reference there ,even though I had added from project->properties->Java Build Path->Projects->Add. So manually editing the project.properties did all the work for me.
I have encountered a similar problem, spent about 3 hours, but none of the proposed here decisions did not help... Finally I found a source of the problem: my project files & project.properties were read-only. Eclipse is simply silently ignoring any changes in library dependencies when I doing it in the GUI!
I had the same problem. It was because of the eclipse project.
To solve it I created a new project in eclipse, copy my existing project classes and resources into it and then launched eclipse again and added my custom includes.
I had the similar issue and my answer is slightly different from CommonsWare's. Here is my screenshot:
After checking the libs back in my build started to work again.
I had also the same problem,
i) add gson lib as referecend librairies
ii) check it in java Build Path
I have a rather big Android App project that is referencing several library projects. Everything was fine until i upgraded the eclipse ADT plugin to the newest version (v22). I also upgraded the SDK of course. I do not see any compile errors in eclipse, but when i run the project on the phone i get a NoClassDefFoundError.
java.lang.NoClassDefFoundError: org.acra.ACRA
....
The arca library is included in one of the referenced library project (in the libs folder) and i can see it in the "Android Private Libraries" in the package explorer, also as i said, no compile errors. The project runs fine on everyone else's computer that did not upgrade ADT.
I have already tried a whole bunch of stuff including but not limited to:
re-install the android SDK
download a fresh ADT bundle
delete all my code an get it again from git
copy the library in question to the app project
comment out the code that uses this library - i just get the same error for the next library
all without any success, so i'm getting really desperate here.
I would be really happy if anyone could give me a hint on how to solve that problem.
Quoting Streets of Boston from his adt-dev post:
When upgrading, the 'Order and Export' of the new 'Android Private
Libraries' is not always checked. And the android-support-v4.jar is now in
this 'Android Private Libraries' section.
To fix this, go to 'Order and Export' and check 'Android Private
Libraries'. Then refresh/clean/rebuild.
After you done this 'fix' for a library project, you may need to just close
and re-open any depending project, because they may not see this 'fix'
immediately.
Give this a shot and with luck it will solve your problem.
Simply checking Android Private Libraries was not enough, I also had to install Android SDK Build-tools in Android SDK Manager.
I had also the same problem and my adt was 22.0.1. And none of the solution above worked. Further when adding a external library project to a working project.I always check the gen folder of working project and if R of external library project is there (along with package name),then only external library project is exported. And on my gen folder no packagename of external library was shown.
So I checked on project.properties file and there wasn't any external library link present android.library.reference.1= present. So I manually added the external library reference there ,even though I had added from project->properties->Java Build Path->Projects->Add. So manually editing the project.properties did all the work for me.
I have encountered a similar problem, spent about 3 hours, but none of the proposed here decisions did not help... Finally I found a source of the problem: my project files & project.properties were read-only. Eclipse is simply silently ignoring any changes in library dependencies when I doing it in the GUI!
I had the same problem. It was because of the eclipse project.
To solve it I created a new project in eclipse, copy my existing project classes and resources into it and then launched eclipse again and added my custom includes.
I had the similar issue and my answer is slightly different from CommonsWare's. Here is my screenshot:
After checking the libs back in my build started to work again.
I had also the same problem,
i) add gson lib as referecend librairies
ii) check it in java Build Path
I am working with Android API 17 on eclipse Indigo. I have cloned the faccebook sdk from github and done the facebook library project set up using the source project provided in the fb sdk.
Now I'm trying to include this library project in my android demo project. I have added it under Project properties->Android->Library section. Im seeing green color tick mark infront of the added library.
Also, i have added the same in the Project properties->Java build path->Projects.
build is successful. but when i try to install on my AVD, im getting the error, E/AndroidRuntime(748): java.lang.NoClassDefFoundError: com.facebook.android.Facebook
Can anybody plz help me how to fix this issue.
---- EDIT ------
One more thing I have observed is, when i opened Project properties->Android window, the green tick mark is not displaying under Library section, instead I'm seeing red cross mark.
Any ideas?
Thanks,
Venkat Papana
Same thing happen for me also.. try below .. it will work..
A Best way to add External Jars to your Android Project or any Java project is:
Create a folder called libs into you project root folder
Copy your Jar files to the libs folder
Now right click on the Jar file and then select Build Path > Add to Build Path, this will create a folder called Refrenced Library into you project, and your are done
By do doing like this, whenever you transfer you project to other Computer, you will not miss your libraries which are being referenced to some space on your Hard drive.
(The facebooksdk.jar can be found at the facebook-sdk directory: <facebook-sdk>\facebook\bin)
i know this question is old But I thought that may be it can help someone.
Move the library project and the application on the same drive. Usually this is a bug in Eclipse.
I solved my problem by moving them in same drive on my computer.
You can Give it a try.
You need to make both project in same dictionary then include it using Project Properties -> Android-> Library.
This works fine.
You do not have to add this to the library project as this is not the library.
https://github.com/facebook/facebook-android-sdk is the help of the project ad the sample code for the including the project in our code. Just you need to create the app ID for the facebook by registering your api with it.
Hope this will help you in your project.
Resolved by copying the com.facebook.android source code to my project source.
In order to implement different versions of our UI we broke our program up into UI specific code and a common library project that has everything else. Up until yesterday when I updated to ADT 14 everything was working fine. Now I can't build. I keep getting the error "The container 'Library Projects' references non existing library 'path to the bin folder of my common project and the name of the project.jar'
I've been all over the web and tried everything I can think of to fix this to no avail. Can someone help me out? I'm basically stuck at this point.
Maybe you have the same issues I had when switching to the new ADT:
In my previous setup I had some resources split between the library and the main project. The library project would not compile error free on its own but only in combination with the main project which added the missing resources.
It doesn't work like this any more.
The library project must compile completely error free now. When it does the build process will create a <lib_project_name>.jar in the bin folder of the library project.
If the jar file is not created ( thus the build process of the library project failed for some reason - eg. because the changes in the R.java file (see http://tools.android.com/recent/buildchangesinrevision14 )) you will get the error message you described.
Also, I had to manually remove the <lib_project>_src from the project.
I've had a problem with a few different projects where I did the fixes suggested in the other answer, but they were only fixed temporarily.
Every time I reopened Eclipse or did a Clean on a project, the "Library Projects" directory would disappear, and I would have to open the project properties, remove the library, and add it again.
I solved this the hard way by creating a new project and copying everything into it.
Then I found an easy way to solve it. Right click the project, Refactor-->Rename. You can rename it back afterwards. This fixed it.
Check out the article "Changes to Library Projects in Android SDK Tools, r14" ( http://android-developers.blogspot.com/2011/10/changes-to-library-projects-in-android.html ) on the Android Developers blog.
E.g. #P.Melch: "I had to manually remove the _src from the project" should be done as follows:
To fix the project, you must remove the extraneous source folders with the following steps:
Right click source folder and choose Build Path > Remove from Build
path.
A dialog will pop up. In it, make sure to check “Also unlink the folder from the project” to completely remove the folder.
You have to update the Android SDK in Android SDK Manager
Android SDK Tools Intalled
Android SDK Plataforms Installed
Android SDK Builds Installed
I have just downloaded the facebook SDK from http://github.com/facebook/facebook-android-sdk
I unpack it from git and opened Eclipse. I then created a new project using existing source and selected the facebook directory. So the sdk project came up correctly (i think). Then I created a new project again using existing source and selected the "Simple" example.
Its came up with errors. I went in the properties and selected Build Path section and added the facebook SDK project and applyed. All the errors disappear.
I then tried to run the Example but im getting an exception on the first call to facebook SDK function ! Exception is NoClassDefFoundError. Its seems that at runtime it cannot find the class of the SDK. How come ? Any suggestions ? Someone did sucessfully run this example ? Any help would be greatly appreciated.
Right click on the Project. Choose Properties -> Android. Under Library click on the Add... button and select the path to the Facebook SDK Project.
I had your same problem, and there was a suggestion in another question thread to export the Android Facebook SDK as a jar file and add that file to your project.
Although some people said that the previous solution worked with them, it didn't work with me!
The only thing worked with me is: coping the Android Facebook SDK six classes into my project and that solved my problem.
Steps:
1- I simply copied the following 6 classes from the Android SDK into my project
AsyncFacebookRunner.java
DialogError.java
Facebook.java
FacebookError.java
FbDialog.java
Util.java
2- I've also copied the facebook_icon.png file from the drawable folders to my drawable folders.
3- I imported my R.java class in the the copied FbDialog.java class.
My advice is to try the jar solution first (as it is the neat way to be a developer), if it didn't work with you, then try my solution (as it is a way to solve the problem).
Thanks and hopefully it will solve your problem.
Mohamed.
I managed to overcome this error by doing a clean build for both my project and facebook library (referenced) project.
The steps:
On Eclipse:
1) Select Project -> Clean
2) Select both your project and facebook sdk project
3) select OK
I too faced the same problem. I was able to overcome this issue by placing the Facebook SDK library as well as my project(to which I want to link the Facebook SDK) within the same workspace. Now go to your project->right click->properties->android->scoll down->add->select the path to facebook SDK->press ok.
This way you can link the Facebook SDK to your project. Only adding the Facebook jar will result in an exception as this does not contain all the classes.
I also had this exception and tried almost everything i found. But then i copied the facebook sdk project to my workspace folder and then referenced it from there in my project and it worked.
Don't know why this happened, this made no sense to me as i was providing it the path while adding reference but anyways, It solved the problem.
I had this same problem. I solved it just by following these steps:
Remove all the sample projects and the Facebook SDK from Eclipse
Import the SDK and sample projects again, but this time, using the "Copy projects into workspace" option checked.
Rebuild the SDK and the sample projects
Working!
Try to mark the check-boxes in Properties -> Java Build Path -> Order and Export.
I had the same problem with the UiLifecycleHelper, and checkig both the Android Dependencies and the android-support-v4.jar worked perfectly. Better to run a clean after that.
I had similar problems. I am building one my lib project (with activities) and my main project using this lib. I had these problems. I had added the lib under the Project properties/Android section and at the bottom, as suggested correctly before, but this wasn't enough (note that both projects were compiling good). I had to change the lib project and use the full path to the layout as:
setContentView(com.example.mylib.R.layout.activity_main1);
Note that using just R.layout wasn't enough, although I have defined the:
import com.example.mylib.R;
Valid alternative is however:
import com.example.mylib.R.layout;
setContentView(layout.activity_main1);
Using Eclipse.
hth to someone
download bolts-android1.1.2 and put into \libs folder. then open the project properties-> java Build Path-> Project tab , Add Facebook SDK. (Facebook SDK libs must be attached with project)
The new facebook SDK already had android.support.V4.jar.
And when you create a new android application, even that contains one.
Hence when you check the console, you get error message called JAR mismatch.
In that case select properties of android project -> Java Build path ->
Select Library tab -> Remove android.support.V4.jar
Select Order and Export and uncheck -> Reference libraries (android.support.V4.jar)
This will fix the issue.