How to attach Android Source to Eclipse - android

I've previously had success attaching the Android Source to Eclipse by following Finn Johnsen's instructions here.
However this approach seems to have stopped working:
samuel-josephs-computer-4:android-sources samueljoseph$ git checkout origin/froyo-release
Previous HEAD position was 1de4a2c... am 62619392: Merge "Fix leak when keylock is recreated."
HEAD is now at adba66b... This class no longer exists.
There was a more recent blog here which had some pre-organized source for Eclair, but nothing since.
There are also some StackOverflow posts from 2008 (older than both the above), e.g.
https://stackoverflow.com/questions/3182904/attaching-java-source-to-android-projects-in-eclipse.
What is the current guidance for accomplishing this?

There is a updated guide. So, you don't need to install an eclipse plugin for this.
Here is the link
Snip from above Link:
follow below steps if you already have downloaded Android sources
Head into eclipse, and press F3 over some android source you're missing, like Activity. And get this pesky window, which we all hate:
Click Attach Source, choose External Folder, and choose the core/java in the base folder.

There is an Eclipse plugin called Android Sources that installs the sources up through Gingerbread. I haven't tried it recently.

For Android 4+ here's a tutorial for attaching sources to eclipse.
EDIT:
First download the source and javadoc from sdk manager.
Goto Your_Project>>Android XXX, Right-Click on android.jar and select Properties.
Point the sources path as Java Source Attachment>>Location Path by clicking on External Folder
Point the reference path as Javadoc Location>>Javadoc Location Path by clicking on Browse
Now you can browse sources like this:

Here's a tutorial:
Make sure you have installed/downloaded the Android source for the appropriate Android SDK API version.
1.1 Check the API version you have specified in Eclipse for Android/Project Build target:
Open project Properties/Java Build Path and click the "Link Source..." button on the Source tab:
Point to where you have installed the Android SDK, expand the "sources" folder, select the appropriate source API version (and click "OK"):
Next...:
Important step is to exclude the whole linked source from building. Otherwise we could have some duplicate source errors plus who wants to build the whole Android source when we have jars already! So, click "Add...", type in *, click "OK" (and then "Finish"):
Verify everything is configured correctly:
Desired result -- linked platform source w/o side effects:
I hope this helped :)

The best way is as below.
Update Android SDK Manager, including source of the version you need.
click on Any class like activity, if source is properly attached, it will open the Activity class.
If it is not opening up, then click on the attach source and can give source path as above.
Source path will be like android-sdk-windows\sources\android-17
This will help you to add source for android SDK

You can do it this way .... hover or copy paste any class_name which is provided from android , just press F3 you will find a Attach_a_source tag there , click in it & here browse your android-sdk folder
and from it just pick source folder because inside it , every android files resides .

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.

Using ADT and SDK manager, attach android source code to eclipse

After installing ADT, I used SDK Manager to download the source codes for the latest android API. Now when I run the Eclipse version that was provided with the ADT, I still can't see the android source codes.
Is there a simple way to fix this?
Open SDK Manager-->install source under api(i.e Android 4.0)
if You got No sources attached then click the button, then choose the Directory
e.g: D:\Android\android___sdk\sources\android-17\ ---> this my android sdk location
Depend upon your android installation directory choose accordingly.
After downloading the Sourcecode by useing the "Android SDK Manager", you have to change the settings in your eclipse-porject.
At first, just have a look where the Sourcecode has been downloaded. In my case (useing Windows 8) its here:
"C:\adt-bundle-windows-x86_64-20130219\sdk\sources\android-17"
Now go into Eclipse.
Open the "Properties" of the project (right click on the project-folder and click on "Properties").
On the left side click on "Java Build Path" and then click on the tab-page "Libraries".
Next you click on the right side on the button "Add External Class Folder...".
Select the folder where you find the sourcecode. In my case its the folder "android-17" of the path "C:\adt-bundle-windows-x86_64-20130219\sdk\sources\android-17".
Commit / close all windows with ok. (Maybe you should restart eclipse.)
And now you can see/read the Android-Sourcecode. (But only in the project which you have choosen before.)
First, you need to download them. Use Android SDK Manager -> Android X.Y.Z (API A) -> Sources for Android SDK.
Then, you need to attach the folder with the sources the next time you browse there: /sources/android-A
Previous answers are great but here you have a complete resource by Lars Vogel who address this question. I hope it may be useful as well as it was for me.
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)

How to configure Javadocs for Android in Eclipse Juno

I found here already a few posts for this problem but also with this help I dont get it running on my machine.
I want to attach the android source code to the android.jar. I tried a few ways but somehow it does not show any android source code. Here is my folder structure where my android sdk is
Image here http://pasteboard.s3.amazonaws.com/images/111OkUca.png
Even if I attach the folder of the requested android-16 plattform it wont show the source.
image here http://pasteboard.s3.amazonaws.com/images/1125INcC.png
What is my mistake?
Thanks
You can download the Java 7 javadoc from
http://www.oracle.com/technetwork/java/javase/documentation/java-se-7-doc-download-435117.html
if you have the "Documentation for Android" package and the javadoc info still isn't showing up, make sure the Android library settings point to the right folder:
Project -> Settings -> Java Build Path, Libraries tab
Android X.X -> Android.jar -> Javadoc Location:
Should be something like "sdk_root/docs/reference/".
And to view the docs for a class in editor for example:
you should choose show attached java doc in web browser from to popup that appear when hover the cursor on some declaration.

Change attached source in eclipse (android)

I am working on an Android project that depends on library written in Java. I develop the library too so I have sources of both - main project and library. I work with eclipse in standard way - both library and the main project are Android projects (no external jar in buildpath or something like that), both are open in the same workspace.
I have problem with debugging the library code. I can put a breakpoint there, the program really breaks but I do not see the source code (which is open in the next child window :-( ... ), I only see the class file editor of the correct file and Java pseudoassembler code. There is a button "Change attached source..." which looks potential but problem is that this button sometimes does not work. When I press it, I can choose "workspace..." or "external folder...", select src directory of the library and press ok, but this has no effect. There will be just a short progress dialog and no change.
Please note that sometimes "Change attached source..." works, but in general if it fails, the second (3rd, 4th, ...) will always fail to so trying it more times does not help. When "Change attached source..." takes effect, it works well for several eclipse sessions but then it fails again and repairing it by "Change attached source..." is a big lottery. Sometimes it works, sometimes not.
The problems are only with library code. The main project works always well even without explicit attached source settings.
Any idea?
"Change attached source..." button does never work. But there is (on the same place and in the same situation) sometimes other very similar button I think "Edit attached source..." (I am sure it starts with "Edit") and this button always works. It looks very wired but it really works so. It must be some bug in Eclipse or Android plugin.
Finally I find the solution (tested on Eclipse Version: Juno Release, Build id: 20120614-1722 and Android SDK 20.0.3). When debugger stops on breakpoint in the "unknown" source of our library, right click on the stack line and it is possible to select an extra source folder in the context menu there. I always specify workspace folder and library src dir. This works in the latest Eclipse and Android SDK/ADT.
If you work on the android project, you shall know the SDK. There is a folder named "sources" and there are source code in it. So maybe you can press the "external folder" and then choose that folder.
I use the Eclipse bundled with the android sdk.
I followed the instructions on the following link:
http://www.mkyong.com/android/attach-android-source-code-to-eclipse-ide/ worked for me.
The instructions are precise and accurate and worked for me.
Hope this works for you.
1- Click change the attach source
2- select external location(radio button)
3-select external folder
4-and select source folder in android sdk folder
5-Click ok.
Choose External Source
Click on select Folder
and select your Android SDK Source Folder
something like this:
C:\Android\sdk\sources
This will work for classes that are Android SDK Classes

How to find easily the source of an android class

I know I can access android source code from https://android.googlesource.com, but it's hard to select the right git repo if I only know the package and the name of an android class.
Isn't there a way to locate a file in https://android.googlesource.com?
Most things you'll want to see can be found under the frameworks/base repo.
This includes pretty much all the public and private API classes that make up the Android Java framework.
If you want to be able to browse the source from within Eclipse, you can follow this guide: http://blog.michael-forster.de/2008/12/view-android-source-code-in-eclipse.html
Finally, the Android SDK Reference Search extension for Chrome lets you browse the public API by typing ad into the URL bar, and it adds a convenient "view source" link to each Javadoc page.
In my opinion today the best way to look into android sources is the github repository :
https://github.com/android/
Public java classes can be found here https://github.com/android/platform_frameworks_base/tree/master/core/java/android
Internal package is here https://github.com/android/platform_frameworks_base/tree/master/core/java/com/android/internal
Resources are here https://github.com/android/platform_frameworks_base/tree/master/core/res/res
Support library https://github.com/android/platform_frameworks_support
Since 2011 the source code can be downloaded with the SDK Manager (Window > Android SDK Manager)
Install package "Sources for Android SDK"
Open Properties of android.jar, which you can find in the package explorer below the Android library
In "Java Source Attachment", select android/sdk/sources as external folder
Edit: Eclipse seems to regularly scan the external folder for updates. If this annoys you, you can zip the folder into a .jar and then tell Eclipse to look in that jar for the sources. Eclipse will then no longer scan for changes.
There is an issue raised against Android project for a single .jar file containing the Java sources.
The issue has been declined but the comments are a good source of methods to access the source in Eclipse.
also, this is a very good tutorial on how to get the source in eclipse, without having to mess with any of the repos or anything, it includes zip files of the the source (which might be out of date)
You can search for any Android class through https://cs.android.com easily.

Categories

Resources