How to attach source to android.jar - android

I am new to Android. I am working in the Windows OS with the Eclipse IDE. My simple application has a spinner that populates a list from database column. When I click on the spinner Class, the file Editor says that source not found and the android.jar has no source attachment.
I downloaded the source code and placed it in this location:
android-sdk-windows\platforms\android-8
Then, I attached this source by these steps:
right click the project => build path=> configure build path=> libraries => source attachment => give the path of the source code downloaded.
But, I didn't get any solution for my debug. Again, when clicking on the spinner it opens the debug that android.jar has no source attachment.

This is now really easy!
Go to Window->Android SDK Manager and install "Sources for Android SDK".
Now try to control-click some Android identify, you will get the usual "no source attached" page. Click "Attach Source" and get the option to select an external folder.
Now browse to /home/me/android-sdks/sources/android-16 (or wherever your SDK is installed; this is the default), and hit ok.
It should think for a moment and then display the source! Yeay!

Unless you need older API sources, you are probably better served by Timmmm's answer. If you do need sources older than 14, read on...
In Eclipse simply go to
Help -> Install New Software
then add update site
http://adt-addons.googlecode.com/svn/trunk/source/com.android.ide.eclipse.source.update/
and go through the motions to install it.
This will happily provide sources for all installed API versions and works very well for me.
Some more documentation is here
http://code.google.com/p/adt-addons/
look for the heading Android Sources

If adding folder android-sdks/sources/android-17 as external source doesn't work (as in my case) you can try to create folder android-sdks/platforms/android-17/sources/android-17 copy sources to it and restart eclipse (I have eclipse Juno Service Release 1). Only this way works for me.
Steps to do this for android-17:
Go to the adroid-sdk install folder, for me it's d:\ws\android-sdks\
Copy android-17 sources folder from android-sdks\sources\android-17\ to the android-sdks\platforms\android-17\sources\ (your have to create folder sources here manually) folder so the final path to the sources must be the: android-sdks\platforms\android-17\sources\android-17\
restart the eclipse, it must automatically attach sources for android-17
UPD: the same solution with symlinks:
Windows Vista+ (thanks #saleemrashid1 for mentioning mklink in comments):
1. cd platforms\android-17
2. mklink /D "sources\android-17" "..\..\..\sources\android-17"
For Unix-base OSes (#Joe comment):
it works fine to create the directory and symlink "sources/android-XX"
to "../../../sources/android-XX":
mkdir platforms/android-19/sources &&
ln -s ../../../sources/android-19 platforms/android-19/sources/android-19.

To attach source code for android.jar, you may follow the tutorial at the link below:
http://android.opensourceror.org/2010/01/18/android-source/
Make sure to choose the correct platform version.
If you meet difficutly with spinner, try to get the sample code and see how it works:
http://developer.android.com/resources/samples/get.html
Good luck. :)
Update
This answer is quite out of date, please consider other answers.

What worked for me follows the answer found in Murach's Android Programming. I got stuck trying to debug and tried to work it out for about 3 hours before turning to the next page (literally) where it said "Sometimes Eclipse will display a source not found message because...." (-headdesk-)
My solution was to turn on Step Filtering and add the packages that I wanted to skip when debugging. Evidently, Eclipse sometimes steps through all the source code libraries, when all you want is for it to step through your code. You can bypass this by adding the packages you want to skip to the filter. According to Murach, you kinda just do it by trial and error, starting with selecting all packages and adding them. As you continue with debugging you might find you need to add more packages to the filter.
Specific steps:
1. Turn on step filtering; click the button in the toolbar on the top that looks like this: http://i57.tinypic.com/x3iccp.png
2. Go to Window-->Preferences, then in the Preferences dialog, select Java-->Debug-->Step Filtering
3. Select all packages.
4. To add additional filters, click "Add Filter", type the name of the package with a .* at the end, and click OK. Murach recommends adding these common packages to begin:
--android.*
--com.android.*
--com.google.*
--dalvik.*
--libcore.*
--org.apache.*
So to add one of these packages, click "Add Filter", type "android.*", and click OK. I ended up having all of the following packages on my Step Filter Preferences.
android., android.app., com.android., com.google., com.ibm., com.sun., dalvik., java., javax., jrockit., libcore., org.apache., org.omg., sun., sunw.*, ((and this last one is a class, not a package)) java.lang.ClassLoader
I had "Use Step Filters" checked at the top of the dialog box, and "Step through filters" checked at the bottom. Click "Apply", then "OK" to close the dialog. It should work.
Good luck!

I added appengine sdk and some other sources, and that destroyed my ADT :-(
I saw that for android-16 and android-17, the platform libraries downloaded by SDK Manager started going to ./sdk/sources whereas prior to my adding appenginge sdk, SDK Manager sent platforms to ./sdk/platforms.
It looks like the change is as a result of the appengine sdk, but for ADT, platform APIs should def be going to ./sdk/platforms
The path ./sdk/sources seems like a more generic java location and is probably the 'correct' path. Thus Android, as usual, is the problem. I was pretty sure from this point forward, I would need both ./sdk/sources and ./sdk/platforms, depending on what I was compiling.
So, I moved everything from ./sdk/sources to ./sdk/platform, deleted ./sdk/sources and then created a link 'cd sdk && ln -s platform sources'
Everything works now ;-)

For me the only solution which worked was the answer of fsbmain. Kudos to him. I can't comment on his solution because of my low reputation counter. But I want to share my knowledge ;)
I'm working on windows and don't wanted to copy the whole source tree to another location. And copy again on updates etc. So I used the possibility to insert a symbolic link which works since Windows Vista like a charm (or like Linux). For Linux you have to look at the Joe's comment under fsbmain's answer.
Assuming you have the platform in D:\sdk\platforms\android-19. Now you have to make a subdirectory sources and after that create a relative link to the real sources folder.
D:\sdk\platforms\android-19>mkdir sources
D:\sdk\platforms\android-19>cd sources
D:\sdk\platforms\android-19\sources>mklink /D android-19 ..\..\..\sources\android-19
Now restart Eclipse ... Done!

Related

Running OpenCV Android SDK Samples

I have downloaded OpenCV-2.4.8-android-sdk and android-ndk-r9c. I followed a tutorial by Stanford university, which tells me to import all sample projects from the OpenCV SDK directory and then everything will work magically.
Obviously, that is not the case. Below is a screenshot of one of the sample projects (and its build path) that I imported to Eclipse:
Do you know of a valid and recent tutorial to make the OpenCV samples running?
I checked the tutorial on OpenCV website but it does not describe how to get the samples running. In particular, I am confused about these:
2) I can see that I am missing all android.* and org.opencv.android.* imports. Do I need to manually include these to the build paths of the projects?
3) Where does the Android NDK go in this process?
4) There is no ./jni/Andorid.mk file in any of the projects. Do I have to manually add these?
Right click each sample project folder > Properties > Select Android from the left list of options:
1) Check if you have something for "Project Build target" (example: "Android 4.4.2").
2) Check if you have something in the "library" box and if it does not have a red X next to its path. If it has a red X, edit to select the correct path to where you placed the opencv library.
Also do step (1) for the Opencv Library project, if you imported it to your workspace like it is described in the installation tutorial.
The steps explained in the Android Development with OpenCV article helped me solve the problem:
Do take caution in using outdated tutorials on the web. In my case, the Stanford university tutorial was outdated and was therefore misleading.
Look for documents dated 2012-2013 when you are dealing with OpenCV.
You should follow these steps:
Right click on the example marked with errors ->
Select android from the list ->
on Project Build Target hit the checkbox ->
then apply.
After that the error for the specific example should be gone.
Try project->clean->clean all.

Error: Program "/NDK-build" not found in PATH

I need help. I'm trying to install and configure OpenCV 2.4.7 library in my computer (Ubuntu 12.04). After run OpenCV samples appears those errors in my Console:
Cannot run program "/NDK-build": Unknown reason
Error: Program "/NDK-build" not found in PATH=[/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games]
I've seen numerous tutorials and nothing worked. I ask you to be very specific since I am "new" programming and also because my mother tongue is not English (I have some difficulties). Thank you!
Easiest Method which worked for me is.
Goto the Project Properties
Click on C/C++ Build (An other list will open)
Click on the Environment from the list
Now click on Add
Here you have to Put 2 values
Put Name as NDKROOT
In Value put PATH TO THE NDK FOLDER
You are done :)
Same case happened with me (when my NDK location was already set), so changing to original Android Builder removed my problem for doing so simply go to project properties, C/C++ Build | Tool Chain Editor and select Android Builder as current builder.
Do you have android-ndk installed? If yes, add path to ndk-build to your path.
e.g:
export PATH=$PATH:~/android-ndk/bin
Add the ndk-build to your path
Follow this guide
http://my.safaribooksonline.com/book/programming/android/9781849691529/setting-up-your-environment/ch01lvl1sec18
this is a frequent issue with openCV for Android. It stems from having the incorrect build target, which creates an error within the library for the Video.java file. After getting that patched up, you can import sample projects. Although, after fixing that, you may not be able to see the C/C++ Build node under project preferences. There's a fix for that on the second link. However, if under project preferences you can see C/C++ Build, make sure the path reads: "${NDKROOT}/ndk-build" Finally, it will be looking for NDKROOT,which is undeclared. The third link will direct you on how to do this, it's very simple. ALSO, make sure if your on MAC or LINUX to remove the .cmd from the end of NDK-BUILD. Good Luck!
Video.java issue:
http://answers.opencv.org/question/8266/opencv-library-244-on-eclipse-gives-error/
C++ Build/General Missing from Project Preferences:
http://stackoverflow.com/questions/16953548/eclipse-missing-c-c-build-and-general-from-project-properties
Now, make sure you add NDK root to the build varialbles so you can find it:
http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.cdt.doc.user%2Ftasks%2Fcdt_t_add_build_var.htm`

Project 'HelloFacebookSample' is missing required Java project 'facebook'

I have been following the instructions for integrating the facebook SDK into my apps. I have succeeded in getting all the given sample apps to compile and run except for "helloFacebookSample". For this I get a compilation error:
Project 'HelloFacebookSample' is missing required Java project 'facebook'
My understanding of projects/libraries/build paths etc is a little hazy, but I can not work out why this should fail where all the others succeeded.
Here's a screen grab of my properties window for HelloFacebookSample:
I can confirm that the directory:
c:\android stuff\facebook\facebook-android-sdk-3.0\facebook\bin
contains a file facebooksdk.jar
Any ideas?
EDIT: Thrashing around some more, I just clicked on the "projects" tab that you see in the screen grab above, and saw that it says "facebook (missing)". I'm a bit confused because I thought that projects may need to rely on libraries rather than other projects... but still I have no idea how to resolve the problem. I don't seem to have a project called simply "facebook"...
Edit: thrashing around some more, I just experimentally deleted the "facebook (missing)" from the java build path and then did an "add" of "FacebookSDK"... I thought this was cluttching at straws, but to my surprise it worked!!! HelloFacebookSample compiled and ran!!! - I have no idea what's going on though and would still like an explanation.
The previous version of the Android Facebook SDK referred to the project as 'facebook'. It looks like this sample was not updated to delete the old reference, and add the new one to 'FacebookSDK'. You took the corrective steps to resolve this yourself already by modifying the Java Build Path of the project.
The problem will easily be removed by simply going to the properties of your project and right clicking it, then go to project tab, select the project which prompts missing and remove it.
Now click on project->build project->clean
Now run your project and it will surely do fine

How do I force eclipse to update the apk on my hardware device with each build?

If I change some code, save, and Run, it runs the last version of the program, not what I just saved. The only way I can make it update is if I Clean the project, Build the project, and then Run the project. Is there some way to avoid this tedium?
I spent some time create two dummy projects (one Android and one Java) and have a play with it, and finally come up with a workaround which is not used very often but able to solve your requirements.
First, I will explain your question a bit more (based on my understanding and what I have tried) so that other people can have a more clear understand about what is happened here.
According to the conversation in comments:
could you tell me what you have in following setting: project->properties->Builder ? – Sudar Nimalan
#SudarNimalan: I am not sure this is what you are asking, but: there's text that says "Configure the builders for this project", and under it is a single option, "Java builder", which is selected (checked). – shino
for android project, there should be, "Android Resource Manager", "Android Pre Compiler", "Java Builder", "Android Package Builder" in this order, chould you add those and try? – Sudar Nimalan
#SudarNimalan: I owe you an apology; I do have those four components. My "project" is split into 4 projects - "core", "core-android", "core-desktop", and "core-html". It's a little weird because I set it up with the libGDX project setup UI, and I was looking at the 'core' project when I answered your question. My 'core-android' project has all four (in that order), and it is the one that has the problem in my question. – shino
Scenario:
You have 4 project:
core: a regular java project (common pure java code here)
core-android: an Android application project.
core-desktop: not related to question so ignored.
core-html: not related to question so ignored.
The core-android project has dependency on core project, by adding core to core-android's build path (Properties -> Java Build Path -> Projects -> Add ...) and export list (Properties -> Java Build Path -> Order and Export).
Problem (Not Really):
Change some code in core and save it, run core-android, eclipse install last compiled apk, not the new one with change.
Reason:
The is the expected behavior, the way you used to reference core project in core-android only create a weak link (or something sort of) between core and core-android, the core-andorid's auto-build script doesn't aware any changes made in core. You have to clean the project (only need clean core-android project) so that Eclipse can delete the existing apk (under bin directory) and re-generate the apk (with the latest code changes from core).
See Xav's comments below, Android SDK tools should aware changes from plain Java project under project build path, and it does not behaviour this feature normally at the moment.
Note that if core is an Android Library project, then there is no problem and your core-android project will aware any changes in core project (java code, android resource and etc), if core is only used in core-android, this could also be a workaround: turn Java project core into Android library project.
Workaround (Eclipse Link Source):
There is another way (not commonly used) for adding soft link between projects:
First, you need remove core project from core-android's build path, this will also remove it from Export and Order list.
Right click core-android, choose Build Path -> Link Source ... Add ../core/src as Linked Folder Location and src-lib1 as Folder Name,see screen screen in the end.
This create a symbolic link src-lib1 under core-android in Package Explorer windows point to core's src foder, in the file system, you still have two separate project folder. Now if you change some code in core and run core-android, Eclipse will build and install latest apk. No need to clean core-android project.
Link Source Window:
Final look in Package Explorer:
You should always consider the normal approach as first option, after all, manual clean project is not a big deal compare to the unusual approach I described above.
Please follow this steps..
1. Project--> Build Automatically been checked??
2. Please following setting: project->properties->Builder like that?
Check below image.
And Also Check Below Settings.
Also Check Below Image
IF problem continues then please Update your ADT & SDK.
Hope it works for you .
Navigate to Windows->Preferences->Android->Build. Make sure that the checkbox "Skip packaging and dexing..." is NOT checked.
The Problem is the In your Eclipse, go to Project Properties - Builder, There is one CheckBox with AndroidPackageBuilder that is required to be Checked True. Now everytime you will do any changes in you project that will be reflected in your build and the Compiler will never say that
"Application Already Deployed, No need to Reinstall"
This will work evenif you dont have selected Build Automatically, Because everytime you run by clicking Run icon or Ctrl+F11 that will first Build the Project and Then Run it. So The requirement is just to Enable the Android Package Builder
You won't believe how easy and silly is the solution
On Eclipse,
go to Window-Prefences->run/debug ->launching
And then, on Save required dirty editors before launching :
choose the Prompt option,
Apply and OK

Eclipse opens wrong source file on exception

I have several Android projects in an Eclipse workspace:
a stand-alone application project with a class my.package.Foo
a library project with a different class my.package.Foo
two application projects that depend on the library project and contain no source code
The problem comes when working with one of the applications built on top of the library project. When it crashes (sadly, a frequent occurrence), I double-click on a line of the stack trace in the logcat to go to the relevant source. The problem is, if the line is for Foo.java, Eclipse always opens the source from the stand-alone project. The only way I can direct Eclipse to the right source is to close the stand-alone project, which is somewhat inconvenient.
Is there any way to get Eclipse to pay attention to which application actually crashed when it looks for the relevant source file? I assume that this is some sort of classpath problem (similar to that described in this post). However, I don't see anything in the Android run configuration properties for modifying the class path. Eclipse always seems to run through the workspace projects in alphabetical order by name and opens the first my/package/Foo.java it finds.
I'm using the latest Android ADT and SDK versions.
Per the link provided in the comment by #blessenm, this is an issue with logcat in Eclipse. We should see a fix in Release 20 of the SDK tools. As can be seen here, the patch that fixes it has been completed and is in line for final approval.
Meanwhile, the best thing to do is to change the logcat preferences (Window -> Preferences -> Android -> LogCat) so that the double-click action is "Go to Problem (method declaration)" instead of the default "Go to Problem (error line)". This isn't foolproof: it will at least open the file but if there are multiple methods with the same name, it will go to the first method, regardless of signature. (When the fix is incorporated, there will be no need for options for double-click action and it should disappear from the preferences.)

Categories

Resources