Facebook Android SDK and IntelliJ IDEA - android

Has anyone figured out how to use the Facebook SDK with an IntelliJ project successfully? I have tried to create a module, mess with project structure etc, but it does not seem to work on compilation.
Does anyone have an answer to this? All other sources seem to be outdated.

This is what actually worked for me.
However, instead of selecting "Library Module" just hit "Empty Module." This was a pain to figure out, but Intellij will change a bunch of files including the AndroidManifest.xml & Strings.xml if you hit "Library Module." Also, be sure to add the dependencies to the libs folder in the recursed directory to your Facebook module so you include android-support-v4 & bolts support. Should work then.

I am currently using the Facebook Android SDK with IntelliJ.
What you need to do is add the SDK as a library for your project.
First, build Facebook Android SDK using Gradle
Open project settings, under Libraries, select Java
Navigate to the Facebook Android SDK directory, select the facebook sub-directory and click OK
The next screen will show a check-list of items, mostly directories - each of them will be classified as source, class etc.
Uncheck everything, and then check the following items:
facebook-android-sdk/facebook/build/classes/release
facebook-android-sdk/facebook/gen
facebook-android-sdk/facebook/src
Then, click Next/OK/Finish
This might be sufficient, but in my case I had to go the Module settings, Dependencies tab and move the facebook item above the project sources item to get the module to compile.

Related

Android Exclamatory red mark

I'm very new to Android. Whenever I create a new project using a new workspace, I get an exclamatory red mark in Eclipse in my project and an error at Appcompat. I searched here for an answer, but no answer was what I was looking for, so I just asked this. When I create a workspace at DDMS it displays this:
Sending Tracking request failed!
At Android, after I create a new project
WARNING: unable to write jarlist cache file here, src file, layout file not available.
I've searched a lot and found no solution.
OK, first thing first. Eclipse is no longer supported by Google. The only official IDE for Android Development is Android Studio Download Page.
Here is the announcement of Eclipse support ending
Over the past few years, our team has focused on improving the development experience for building Android apps with Android Studio. Since the launch of Android Studio, we have been impressed with the excitement and positive feedback. As the official Android IDE, Android Studio gives you access to a powerful and comprehensive suite of tools to evolve your app across Android platforms, whether it's on the phone, wrist, car or TV.
To that end and to focus all of our efforts on making Android Studio better and faster, we are ending development and official support for the Android Developer Tools (ADT) in Eclipse at the end of the year. This specifically includes the Eclipse ADT plugin and Android Ant build system.
Please note that the number of people using Eclipse to develop Android apps are going down. You will get less and less support even on Stackoverflow as time goes by. Overall, it is better to just make the switch while you are just starting.
Check on the first link, you will see some amazing documentation in the Android Studio IDE
If you 100% required to use Eclipse...
OK, so you have a job that requires Eclipse or there is some other reason, then check out this documentation by Eclipse.
Also, here is a list of all the different icons that can be displayed by Eclipse (credit for the icon list).
Build path problems are sometimes easy to miss among other problems in a project. The Package Explorer and Project Explorer views now show a new decorator on Java projects and working sets that contain build path errors:
The concrete errors can be seen in the Problems view, and if you open the view menu and select Group By > Java Problem Type, they all show up in the Build Path category:
Please refer this link too here
If you go to appcompat_v7/bin folder, you'll see that file "jarlist.cache" doesn´t appear or is unsynchronized. You need to
refresh the appcompat_v7 folder, only press F5 over that folder.
The appcompat_v7 folder is added because you use an action bar
component.
Aah. To avoid a new appcompat_v7_XX folder when you are creating a new
project, choose a LEVEL API 14 as Minimun Required SDK. After you must
modifier the AndroidManifest.xml and put the level that you need.
change it
android:targetSdkVersion="19" />
Delete all appcompat_v7_XX. It is a bug.
With appcompat_v7, You will see that Eclipse creates two XML files:
Activity_main.xml and fragment_main.xml. If you want to have an option
to create a project in the old way only with activity_main.xml, do
that:
Make a copy of the folder "BlanckActivity" located in this path:
\sdk\tools\templates\activities of an ADT previous version.
Rename the folder as “BlankActivityNoFragment”, then edit the field
name of the file "template.xml" with a notepad as
name=”BlankActivityNoFragment”
Copy the new folder in the same path of the new Eclipse
IDE:sdk/tools/templates/activities
Now you´ll see the new template when you go to create a new project.
Remember to choose as Minimum Required SDK an API 14
If you don't want the support of appcompat library then just remove it from your project by following steps :
Right click on project
Select properties
In dialog select android on left side
In dialog check library section
Remove appcompat library by selecting it and press remove
Extends your MainActivity.java with Activity
You can run your project successfully.
If you want the support of appcompat then follow this steps :
download the latest appcompat using Sdk Manager
import appcompat project in your eclipse
add it as a library project
extend your MainActivity with AppCompatActivity.
If you're getting any problem with app_compact library... This is the solution
Hopefully it will work....
According to the documentation
Decorates Java projects and working sets that contain build path
errors
There can be several reasons. Most of the times it may be some of the below reasons ,
You have deleted some of the .jar files from your /lib folder
You have added new .jar files
you have added new .jar files which may be conflict with others
So what to do is we have to resolve those missing / updating / newly_added jar files.
right click on the project and go to properties
Select Java Build Path
go to the Libraries tab
Remove the references of the jar files which you have removed already. There will be a red mark near them so you can identify them easily.
Add the references to the newly added .jar files by using Add JARs Refresh the project
This will solve the problem if it's because one of the above reasons.
Still Facing problem ??Try this:
Go to Windows -> Preferences -> Android -> Build and uncheck "Skip packaging and dexing until export or launch" then restart Eclipse.

Android Eclipse NoClassDefFoundError for external .jar files

I have come across a strange error. I have an Android project that uses external libraries, in particular:
android-support-v4.jar (for Fragment support in Android 1.6)
GoogleAdMobAdsSdk-4.3.1.jar (for ads)
The project ran fine until I updated some aspects of the plugin (can't recall the specifics as I did not pay too much attention to it) and after that, whenever I try to use any class from the above .jar files (or any of its subclasses, even ones defined by me), I would get a java.lang.NoClassDefFoundError. I could not find the answer after much searching, so I am really stumped.
I believe this problem is related to how my IDE is set up and it has little to do with actual code, so I will not post any unless if it's absolutely necessary.
You need to read this - Dealing with dependencies in Android projects.
This link is also useful - ClassDefNotFoundError with ADT 17
Basically, create a folder called libs and place all of your jar files inside. The recent update will automatically take care of the rest for you. You don't need to edit your path anymore.
Android does not support Java1.7 up to now. Jars built with compliance level 1.7 cannot be used in Android Applications. Rebuild your Java project with compliance level 5.0 or 6.0 before exporting the jar file.
I found this post via google and answers above didn't solve my problem. Hope what I say will be helpful to others.
If you see NoClassDefFoundError after upgrading to ADT 22, try this in Eclipse:
Go to Project Properties → Java Build Path → Order and Export tab.
Check the Android Private Libraries option.
Also a warning to others who have updated to r17 with many dependencies. I had a another referenced project on my build path and it still did not work after following ALL the directions on this r17 issue on the internet.
Found out after an hour that my referenced project used an older version of an external Jar than my main project did. When trying to compile the main project, Eclipse would give up due to this jar version difference and I never noticed the warning message in Console.
Solution was to copy the newer version external jar file to the referenced project's libs directory.
Wow - such a productivity killer.....
I ran into this error today too, because of updating to the Android SDK, r17. What the links that #aneal pointed out do not discuss is how to handle external runtime libraries (such as those imported under their own heading - not an imported user library).
The easiest way to solve this problem is to change the build order in the build path. Simply right click on your project and select Properties. From here, select Java Build Path. At the top of the display, choose the tab order and export and move GoogleAdMobAdsSdk-4.3.1.jar above Android X (replacing x with the version you are using). Next, clean your project and run it. You should be good to go!
The way I solved it was by : Right clicking on the project and selecting build path. Select configure build path in the selections that appear. After that see if your libraries are there in the libraries folder and then select the order and export tab and over there select all your jar files. Then select ok and run your project.
If you're using Eclipse with Maven IDE (m2e) go to "Java Build Path" then "Order and Export" and finally check the item "Maven Dependencies" and pull it down to the BOTTOM of the list. You should do the same with project references in the same workspace.
Every time I setup the project in a new computer that happens.

Android facebook SDK as JAR

Are there any cons of build the facebook SDK library project into a JAR file(as ADT 16 does with library projects) and adding it to your project? I am not changing anything in the facebook SDK so don't need to have it added as a library project. So far it has been working fine for me and I am wondering whether this is a common practice used by developers using the facebook SDK? It speeds up the build process quite a bit because Eclipse doesn't have to resolve all of the resources in the library projects.
Yes! I just figured it out myself.
You need two jar files:
facebooksdk.jar
android-support-v4.jar
Option 1
The first can be found in the bin folder, the latter in the Android Dependencies folder. (Of the FacebookSDK project)
After adding them both as libraries to my project (Project --> properties --> Java Build Path --> Libraries) it actually worked.
Option 2
Another way is to copy paste the facebooksdk.jar and get the android-support-v4.jar via Right-click on project --> Android Tools --> Add Support Library.
Good luck =)
Kasgoku,
The code is provided as a project for easy viewing of the classes. Adding it as an included jar or just moving the source into your project also works. When I created an FB connected android app, I moved the files I needed into a package in my app.
It looks like maven has them cached.
http://search.maven.org/remotecontent?filepath=com/facebook/android/facebook-android-sdk/4.4.0/facebook-android-sdk-4.4.0-sources.jar
You can create a jar file :
Download Facebook Android SDK from github.
Extract it. (at any location).
In Eclipse create new project using create project from existing source option
Enter the project name as "com_facebook_android".
Set Location to "facebook" folder in extracted location.
Click Finish.
Select the "com_facebook_android" project in project explorer and right click
select export option.
In the export wizard select JAR file in Java folder.
Click next then browse the location for jar file and give the name as yor wish like "facebook-android.jar"
Click finish........ JAR file will be created in that location
Well guys you dont need to manually make a .jar file out of facebook-android-sdk. You can use easyfacebook.jar. It currently supports:
Oauth 2.0 authentication support
Use the access token
Pictures upload support
Supports all the features of Graph API
It can run any query FQL
Contains BEAN of all facebook objects
It's free. LGPL GNU license
Progress dialog
Logout function
Server/Request Error Management
Key hash/Geo Tagging
Login without facebook app

Unable to Debug Library Projects with ADT v14 - Source Not Found

Ever since upgrading my current projects to use the new R14 Tools in Eclipse, I'm now unable to debug any code that exists in my library projects.
When I hit a break point in my library project code, instead of Eclipse opening the original source file, it opens up the read-only copy of the source file contained within the JAR with the message "Source not found".
I've searched around for a solution to this, but have yet to come across anything. Does anybody else have any suggestions? It's quite a pain not being able to debug.
EDIT
The issue has came back and I'm no longer able to debug. I haven't changed any project settings around or anything. Very frustrating.
Tried all of the above and it did not work for me, however the workaround detailed here did.
http://code.google.com/p/android/issues/detail?id=20731
Start debugging, and run until you hit a breakpoint (and precisely get a .class file instead of the .java you would like to have)
Right click in the Debug view of the Debug perspective (for example on the call stack), and choose "Edit Source Lookup Path"
Add all your projects above "Default", via "Add..." > "Java project" > "Select All"
(I'm using ADT 15.0.2 preview from http://tools.android.com/download)
After having this issue as well and doing a little research, I came across this thread and another one that tipped me off. I was pulling my hair out already.
It turns out that the problem is with the build order of your projects (mine was anyway). Since ADT/SDK v14 changed the way library projects are referenced, the build order needs to be correct. Make sure all of the libraries your app uses are built first. I just moved the "src" and "gen" folders for each of my projects to the bottom and now it builds the library first and I am able to debug it and view the source of my library files through the main project.
In case someone doesn't know where to do this, in Eclipse, right click on your project and "Build Path" and then click "Configure Build Path". Then, on the "Order and Export" tab, move the two folders for your project to the bottom of the list below your libraries. I did this for all of my projects and the library projects.
You can also do it globally in Eclipse from Windows->Preferences->General->Workspace->Build Order and moving your library projects to the top. I think the build order defined in each project will override this though, so you may want to do it in both places to solve the issue now and for future projects.
I had the same problem in a project today. The project consists of an app which has two library dependencies. I could not see code during debugging and when using auto-completion when overriding methods Eclipse was unable to deduce proper argument names.
First of all, the problem manifested itself by showing the the 'gen' folder was used as the one that contained the source. To check whether this is the same issue go to your app project, open the Android dependencies and have a look at the properties of the your library dependencies. Location path said /libraryprojectname/gen.
If this is also your problem then go to the 'Order and Export' tab of each library project and move the 'gen' item below the 'src' item. As soon as you click OK Eclipse will work a bit and when you check the Android dependency properties the location path should say: /libraryprojectname/src. Open click the dependency and open any class inside the jar. It should show the source.
I am using ADT plugin 20.0.3 with Android SDK Tools 20.0.3 and Android SDK Platform Tools 14.
The following worked for me on Eclipse Juno:
In Project Properties/Java Build Path:
In the Projects tab, added my library projects.
In the Order and Export tab, moved my library projects to the top, and checked them
Not sure if it's relevant, but Android SDK tools is rev 20.0.3 and Android SDK platform tools is 14.
I assume you are opeining library project and there you put brakepoint.
Try this: On main project open Library Projects->[yourlibrary.jar]->[yourfile.class] from Package Explorer, and then in .class file put brakepoints.
This works for me at least :)
Sometimes this happens to me. Not sure about the reason but the way I solve is:
Remove the main project from eclipse. -- Closs Eclipse -- Delete the jar file in the library project -- Open Eclipse -- Wait for the library project to compile -- Import the main project
This problem also occurs with release 21 of ADT inside Juno. As a workaround, in the "debug" view of the debug perspective (where you see threads and method invocation traces), right click and edit source lookup path.

Android facebook SDK doing error java.lang.NoClassDefFoundError‎

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.

Categories

Resources