Twitter APIs and adding Jars to Build path - android

I am trying to manually add a jar file to my project for the 1st time.
I have downloaded Twitter4j in order to use these APIs in my app.
I extracted twitter4j-core-2.2.6-sources.jar and twitter4j-core-2.2.6-javadoc.jar and copied them to my /libs folder. Refreshed the folder in eclipse and added the 2 files to my build path.
In the 'referenced libraries' and 'android dependencies' folder I can see my 2 new jars.
But I now have the following issues:
a)the sources cannot be viewed(I'll understand if they cannot be viewed, I am a C++ programmer, do I have to rely on the documentation to find out about the API names in Java?)
b)In eclipse, the javasources cannot be seen either: When i click on an item i get: Problem opening an editor. Reason Problem opening editor for (Annotations.xml)Unable to open external editor null xxx (org.eclipse.ui.browser.editorsupport)
c)I added one of the example files to my project and it does not compile:
import twitter4j.Status; ==> The import twitter4j.Status cannot be resolved
Any help much appreciated

Don't create lib folder..you should have libs folder and eclipse will automatically add everything inside it to the build path for you. You don't need to do anything else except putting your jars there.

Related

How to import com.android.support:design:23.0.1 in eclipse

I am learning the android tab with swipe functionality using material theme. I have a sample tutorials from here and it is build from Android studio.
I am currently using eclipse for my project.
I am following the tutorial and i can't import the TabLayout from com.android.support:design
Below is the code,
import android.support.design.widget.TabLayout;
Showing the error, The import android.support.design cannot be resolved
I downloaded support:design:23.0.1 from here and imported to eclipse, even then the error appears.
Can any one tell me where to download and import the com.android.support:design:23.0.1 in eclipse.
Thanks
Install Android SDK 23.0.1
Import design library from sdk\extras\android\support\design into eclipse workspace
To mark the design project as Library, open properties -> Select Android ->Check Library
Now import this design Library to your Project from project properties.
This worked for me in Tab material design.
If the design folder is not found in the said location, try to locate it in sdk\extras\android\m2repository\com\android\support\design instead, especially for the later version.
I have also face same problem then find solution like this.
It work for me hope same for You.
First Step:- find .aar file for design-23.0.1.aar
E:\new sdk\sdk\android-sdk-windows\extras\android\m2repository\com\android\support\design\23.0.1
Second Step:- copy that file and rename it like design-23.0.1.jar to be extract this.
After unzip it you find classes.jar, res, AndroidManifest etc.
Third Step:- Create Library project in eclipse Named design and copy
classes.jar in libs folder
all res in res/
replace AndroidManifest.xml
and last add lib appcompat-v7 by right click on lib project -> properties-> Android -> add -> appcompat-v7
Most important do not forgot clean project and can be restart eclipse for refreshing eclipse.
And more deep details follow steps Guided by commonsware's blog
Create an empty directory that will be the home for the Android
library project. For the rest of these steps, I will refer to this as
“the output directory”.
Copy the AndroidManifest.xml, res/, and assets/ directories from the
AAR into the output directory.
Create a libs/ directory in the output directory. Copy into libs/ the
classes.jar from the root of the unZIPped AAR, plus anything in libs/
in the AAR (e.g., mediarouter-v7 has its own JAR of proprietary
bits).
Decide what build SDK you want to try to use. You might just choose
the highest SDK version you have installed. Or, you can use the
android:minSdkVersion and the -vNN resource set qualifiers to get
clues as to what a good build SDK might be. If desired, create a
project.properties file with a target=android-NNN line, where NNN is
your chosen build SDK. Or, you can address this in Eclipse later on.
Import the resulting project into Eclipse, and if needed adjust the
build SDK (Project > Properties > Android). Also, you will need to
attach to this library project any library projects it depends upon
(e.g., mediarouter-v7 depends upon appcompat-v7).
Good Luck!
And Special thanks to commonsware !!
A great fix to that problem is that you copy the sdk\extras\android\support\design\libs\android-support-design.jar file to "libs" folder of your project

Import "MPChartLib" Library to Eclipse

I tried to add "MPAndroidChart" library in Eclipse but when I try to import this lib:(https://github.com/PhilJay/MPAndroidChart/archive/master.zip) .
Amongst the downloaded files , I found a folder called "MPChartLib". This is the actual library folder, I need to add this folder to my project to be able to use the full functionality of the library.
I tried to import the library folder into my workspace, using File-->Import-->Android-->Existing Android but I have this message " Select at least one project eclipse import" !!!!
The lib uses gradle, because of that you can't "import a eclipse project"
You have 2 options, install a gradle plugin for eclipse, or use the lib as a jar
From the lib README:
Download the latest .jar file from the releases section
Copy the mpandroidchartlibrary-.jar file into the libs folder of your Android application project
Start using the library
I hope the same named file is already there or else you can do one thing check the file name to the New Project Name column and check the same file name in your workspace. I must say you that the same named file is definitely there.
So once you will find this, just rename your file name into your workspace and try again importing this.
I hope this will work for you. Any help will be needed, do let me know.
"Select at least one project eclipse import" this message inform you that you have already added Lib in Work Space check for already added "MPChartLib" Lib followed this step:-
Write click on your project and select Properties.
On left select Android.
In Android->Library section click Add
Select for "MPChartLib" (note: name can be change).
Or If you unable to find lib please make new workspace if possible then import MPAndroidChart on workspace.

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.

Eclipse Android gen already exists but is not a source folder

I am getting the following errors when I try to load an Android project in Eclipse that was working just fine last week.
Any ideas?
[2012-03-16 09:29:43 - MyProject] /MyProjectName/gen already exists but is not a source folder. Convert to a source folder or rename it
Note that I have tried to clean the project several times, even restarted but it still gives me this errors.
right click on project and go to project properties, then goto java build path, and then in source tab, click on add folder button and add gen folder.
just src and gen folders should be checked there if you haven't any library projects attached.
MyProject] /MyProjectName/gen already exists but is not a source folder. Convert to a source folder or rename it
This problem happens when eclipse does not able to find each linked contents in a project.
For example:
When we import a project to eclipse from a specific folder(suppose D://NewFolder), eclipse memorized and link each content with its appropriate path (which is D://NewFolder/project_library/src in our example).
But if we replaced(Here D://NewFolder To E://Another_Folder) or delete the library from its specific folder(Here D://NewFolder), eclipse unable to find its(project_library) original path
and give red error.
So when this problem happens, first we have to make sure that the imported project or library is its original folder and no changes has made to this.
Otherwise again replace the project to its specific folder to which eclipse has linked at the time of import i.e parent folder.
This happens because your .classpath file got wiped out somehow. This file contains all the information from the Java Build Path tab under Project Properties. You could add in all information manually but there's an easier way of fixing this problem.
If you have a copy of the .classpath file on your machine, you can just copy and paste it into your project directory.
Follow these steps in Eclipse :
Project -> Properties -> Select Java Build Path ->
Open Source tab -> Click Add Folder and check the gen

How do I attach the Android Support Library source in Eclipse?

Having the source code attached to external libraries is awesome. Where do I find the source code for the v4 support package? Preferably, it would be a zip file which could be easily attached to the android-support-v4.jar in Eclipse.
I just want to add yet another method of attaching sources for the support library. It requires ADT in version 20 or later. Supposedly this method works for all JARs for which setting source/javadoc location is disabled by the container. Here's what you need to do:
The android-support-v4.jar library lies in the libs directory of your project. In that same directory create a regular Java properties file named exactly like the JAR in question, but with appended .properties extension. So, for our support library it'll be: android-support-v4.jar.properties.
Open created properties file and set value of property named src to the location where sources for that library can be found. Your file should have one line like:
src=c:/apps/adt-bundle-windows-64bit/sdk/extras/android/support/v4/src
Save the file.
Close and re-open your android project.
Try browsing to one of the support classes. The source attachment should work now.
Worked perfectly in my case.
One thing to note: if src is not an absolute path, it will be resolved starting in the parent directory of the JAR file. Taking support library as an example - if src=support/src, ADT will assume that the class sources are located in libs/support/src.
Short description of this feature written by its author can be found here.
If anyone is interested in how exactly this .properties file is processed, I recommend reading patch set #4, esp. changes in eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/ internal/project/LibraryClasspathContainerInitializer.java :)
Edit
Please also see a fine comment by WindRider about adding sources properly in a project with multiple referenced libraries.
Here the solution to attache the source of the support library in Eclipse Juno
I suppose that your project already has android-support-v4.jar in your "Build Path", under "Android Dependencies", but you cannot attach the sources directory to it. (the "Source attachment" said "Non modifiable"). Solution:
Goto "Configure Build Path"
Add External JARs > YourProject/libs/android-support-v4.jar
(I know your project had already referenced to it but don't worry, just add it again).
Expand jar and attach Source to the External Jar: android-sdk/extras/android/support/v4/src
Switch to the "Order and Export" tab, pull up the external jar above the "Android Dependencies"
Enjoy navigating the support library with source!
if you have an "Android Test Project" attached to YourProject, so YourProjectTest might not compiled anymore. In this case, you have to return to "Order and Export" and pull down the external jar below the "Android Dependencies" to get things back to normal.
After downloading the support package from the Android SDK Manager, you can find the source code of support package in folder <android-sdks>/extras/android/support/v4/src.
Referencing the accepted answer, it is also possible to attach the source straight from the directory without building a .jar file. From the Java build path / libraries tab, expand android-support-v4.jar, highlight "Source attachment", click "Edit...", "External Folder..." then point to (android-sdk)\extras\android\support\v4.
This was tested using eclipse indigo.
From the comments:
The problem of being unable to add source to the support library seems to occur if your support library is located in the "Android Dependencies" folder of your project. The workaround is from the same "Java build path / libraries" tab click "Add External JARs..." and find the .jar file in your (android-sdk)\extras\android\support\v4 path. It will then appear in your project setup under a new "Referenced Libraries" folder.
For those who like the standard to have the jar file of the source code, which makes it more convenient for source control and sharing the project.
For example:
../android-support-v4.jar
../android-support-v4-src.jar
It is simple to create the source jar file and attach it:
cd to path_to_android_sdk/extras/android/compatibility/v4/
Use your favorite zip program such as 7-zip to create a zip file and name it android-support-v4-src.jar. The first folder in the jar should be /scr.
Copy the file to your project, in this example it is in the same folder as the code jar.
In Eclipse attach the source jar in project properties.
I just remove the auto generated one , then manual add it as a Referencde Libraries.
First open a class, the IDE will ask you to Change Attached Source.
The process of attaching the src and doc from build path works for some and it doesn't for some (like me). some key things to keep in mind
Make sure you are in Package Explorer, not Project Navigator.
If you have put your android-support-v4.jar in libs folder under your project. great.
Right click the jar, Build path.. Add to Path. (if Add to Path does not show up then its already added. you will see configure path..)
As the result of step 3, a new folder called Referenced Libraries will appear in package explorer tree. Open that tree, find the android-support-v4.jar there. Right click on this jar in the Referenced Libraries, properties. Then set the Java Source Attachment and Javadoc Location there.
You are done.
The path for my Java Source Attachment.(its external location)
C:/Users/thupten/adt-bundle-windows-x86_64-20130514/sdk/extras/android/support/v4/src
I used the android website doc for java doc location
http://developer.android.com/reference/android/support/v4/app/package-summary.html
I found this for me:
For main lib: android.jar:
src: sdk/sources/android-19
doc: sdk/docs/reference/
For support lib: android-support-v4.jar: (before this we should add android-support-v4.jar like external jar (Project Properties -> Java Build Path -> Libraries, then in Tab ‘Order and Export’ pull up this library before Android Private Libraries)):
src: sdk/extras/android/support/v4/src/java
doc: http://developer.android.com/reference/android/support/v4/app/package-summary.html (not sure)
After you have updated the SDK and downloaded Documentations in it:
Import support library project to package explorer.
Create a folder in the library and name it something like ext-jars.
Move android-support-v4.jar to ext-jars folder.
Right click on the project and click on Properties.
Click on Java Build Path in the left menu then select Libraries tab.
Click on Add JARs... then expand the project and select the jar file you already moved to folder ext-jars.
Expand the added jar and select Source attachment then click on Edit.
Select External location then click on External Folder...
Choose the source folder for the Support v4 which is located in
[sdk-path]/extras/android/support/v4/src
Select Javadoc location click on Edit then select Javadoc URL then click on Browse... and choose the javadoc location for support v4 which is located in [sdk-path]/docs/reference/
- Select Order and Export tab and check the android-support-v4.jar you just added.
I suggest you also clean the project and reopen the Eclipse.

Categories

Resources