Trying to add facebooksdk.jar file to my project - android

I have installed facebookSDK and the sample apps. The sample apps all copilr and run fine.
I tried to make my own app. The only thing I did was creat a new android project, test it, runs fine. Then I added the facebooksdk jar file. Now my project no longer runs and I get a error that says
“jar miss match fix your dependencies”
The jar file seed to load in correctly, if I click on android dependences I see
Facebooksdk.jar ../programming/facebooksdk/……
I tried to see what was different from my project ans facebook's sample code.
Under android dependencies it had the same line I had Facebooksdk.jar ../programming/facebooksdk/……
And also had another jar file called android-suppert-v4-.jar that I do not have.
Other then that both the sample code and my test project seem to be the same.

there is a jar that exists both in the facebook sdk project and in yours.

This is caused by having a duplicate jar -- a .jar file of the same name that appears in both projects, but is not the exact same file. In this case, it is probably android.support.v4.jar, since Facebook uses it, and your project likely does too.
Check your dependencies carefully (and check your assets, bin, etc. folders) for the android support library in your own project -- even if you didn't add it yourself, the dependency could have been added by default, especially if you used the wizards provided with ADT for eclipse.

Related

What is the correct way to add an Android Library to an Android Project?

I am trying to add android-support-v7-appcompat to my newly created Android project.
Following the Support Library Setup Documentation (developer.android.com/tools/support-library/setup.html), section Adding libraries with resources, I have created an android-support-v7-appcompat project, before adding it as an Android dependency.
EDIT: Here are more details on the process I followed to add the library project as an Android Dependency to the main project:
In the Project Explorer, right-click your project and select Properties.
In the category panel on the left side of the dialog, select Android.
In the Library pane, click the Add button.
Select the library project and click OK.
However, even if the dependency is correctly recognized, Eclipse still sees the compatibility references, such as ActionBarActivity, as errors, forbidding me to build the project. (See picture here).
To solve this problem, I tried the solutions accepted by similar questions on SE, i.e. adding android-support-v7-appcompat to the Project's Build Path, which successfully silents the errors that prevented me to compile earlier.
However, now when building and deploying the project, I get an error: the app crashes at launch, and the Console displays an error message: Could not find android-support-v7-appcompat.apk! (See picture here).
To resume, with the first configuration I am not able to compile with Eclipse, while with the second configuration I can't launch the application.
Therefore, I have two questions:
First, how should I be adding a library to my project, so I can at the same time build my project and be able to use the library's additions in my code in Eclipse?
Secondly, I feel like I am missing theoretical knowledge on how Eclipse handles dependencies.
What is the difference between adding a library as Android dependency vs Java Dependency / vs adding the project or its jar to the Build path?
First, how should I be adding a library to my project, so I can at the same time build my project and be able to use the library's additions in my code in Eclipse?
Your first approach should be fine, which would indicate that there is some other problem. For example, there may be errors in the appcompat library project that are preventing it from being compiled. However, given the error from the second approach, either you are running the appcompat library (which will not work) or something else is more fundamentally broken in your project setup, where your app thinks that it is supposed to build android-support-v7-appcompat.apk, when there is no such APK.
What is the difference between adding a library as Android dependency vs Java Dependency / vs adding the project or its jar to the Build path?
Never manually modify the build path in Eclipse for an Android project. While that will satisfy the compiler, the contents of the JAR(s) will not be packaged into your APK for use at runtime, resulting in runtime crashes (e.g., VerifyError).
"Java dependency" is for pure Java source code. Not only do you not have the source code to appcompat from the SDK, but an Android library project includes Android resources (and, at least on Android Studio, also assets and an optional manifest file).
For Eclipse, library projects are attached via the approach you describe as the first approach in your question. For Eclipse, plain JARs are just dropped into libs/ in your project root, and those are automatically added to your compile-time and runtime classpaths.

How do I add a new library to android dependencies using eclipse adt?

I am trying to add external library to android dependancies using eclipse adt. I have a couple of libraries like pull to refresh etc in there. But everytime I add a new library jar file it shows outside of the android dependancies library folder. How do I make it such that it is coupled with the other libraries as a part of android dependancies library. Here's what I did so far:
Project> Properties> java build path > libraries> add jars ( also tried adding external jars), but it always showed my new jar file independantly, i want it to be a part of android dependancies). any clue?
Here's a screen shot, I would like to add it as a part of android dependencies:
I still do not get why that is important to you.
However, when you reference a library project: rightclick project->properties->Android->Add then the jar goes into Android Dependencies.
If you add the jar directly to your project under libs or using build path, then it goes under Android Private Libraries.
Both methods works but referencing a library project can have benefits if you want to alter the code of the library during development.
In my case I had the following in my project.properties file
target=android-18
proguard.config=proguard.cfg
android.library=false
android.library.reference.1=..\\com_facebook_android
android.library.reference.2=../actionbarsherlock
After I changed the last line to
android.library.reference.2=..\\actionbarsherlock
actionbarsherlock.jar appeared in the Android Dependancies and I could run my app without the java.lang.noclassdeffounderror exception

Gradle: error: package does not exist

I know that there are different solutions with different libraries posted. But, could anyone help me with this one?
I've busting my head for the past couple of days, and I really don't know what to do. I already tried importing the modules in all the suggested ways from different posts. (Project Structure --> Dependencies --> Add dependencies), etc. My project does not show any errors, but when I run it, it throws me a compilation error that complains about some classes missing. The library only depends on the ViewPagerIndicator's library which I also imported.
here is a picture. Thanks!!!
NOTE:I also have tried it with Eclipse, but the problem is different there. The app crashes when I run it. When I uncheck isLibrary from Properties -> Android and erase those libraries, the app works.
Inspired by this answer, these are the steps I did:
Put the jar file (in my case, 'xxx.jar') into the libs folder of your project
Right click it and select Add as library
Type this in the dependencies part of build.gradle file: compile files('libs/xxx.jar')
Do a clean build. It can be done inside the android studio, but I also ran the gradlew.bat included inside the project folder
Now, the project should be built and run just fine.
You are referencing the library wrong. You need to add the dependency in the build.gradle file. I recommend you to read the documentation first. It's a long read, but totally worth it.
I noticed that a user uploaded the library as .aar file in his maven repo. You might want to use the library from his repo. The setup is very easy (you only need to include the dependency of the better picker library).

Paypal Mobile Express Checkout Library sample app gives me NoClassDefFoundError Exception

I'm testing the sample app for Mobile Express Checkout Library with Android.
I'm getting java.lang.NoClassDefFoundError: com.paypal.android.pizza.ResultDelegate
The error is on this Pizza.java line: PayPal.fetchDeviceReferenceTokenWithAppID(this, appID, server, new ResultDelegate());
I'm confused, i didnt find any info about that error on google, and also on the faq on paypal and x.com, so i don't know how to solve it.
I simply opened the sample code project and executed it.
This is the link to the project and the library: https://www.x.com/sites/default/files/PayPal_MECL_1.0_Android-Developer-Package_0.zip
There are only three reasons you will ever get this error:
The class genuinely doesn't exist. If you are using code from an official example and getting this, make sure you have the latest build of the library
You have not added the jar to your build path. To fix this, right click on the jar in Eclipse, and do Build Path ► Add to Build Path.
Your jar is not in the /libs folder. This happens when you have added the jar to the build path, but newer versions of ADT need it to be in /libs. Put it there and it will automatically be added to the build path. If it isn't, try doing a Clean build via ant clean or Project ► Clean in eclipse.
Mostly, such errors occur because newer versions of the ADT require all external jars to be in the libs folder.
By looking at the project you linked to, I can see the paypal jar in the project root. Instead, try moving it into a /libs folder. This should solve your problem.
I think you have not exported library jar from the configure build path section of eclipse.
create libs directory in project's directory and add move PayPal_MECL.jar to /libs. goto project properties and remove existing PayPal_MECL entry from libraries

Cannot build library dependent project after update to ADT 14

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

Categories

Resources