Change attached source in eclipse (android) - 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

Related

Errors when creating a new Android project

Im trying to create an Android project on Eclipse but as soon as i create it, errors appear on the project name.
I dont know whats wrong since I havent written anything myself yet. When when im on the final step of the project creation window (the activity section), I click finish and it takes like 5 seconds and the project name appears on the left, in the project explorer but the window doesnt close.
Heres what it looks like:
Here's the result of the Problems tab:
When you have errors like R cannot be resolved to a variable most of the times you have to solve problems in your Resources, for example you can see the folder \res has a red cross, solve that problems first.
Do the below changes and I guess it should work.
Update ADT & SDK.
Remove gen folder , and create it again .
Do a clean-project.
Right click the project and choose android-tools -> fix-project-properties .
Right click the project and choose properties -> java-build-path -> order-and-export. make sure the order is :
Android private libraries
Android dependencies
Your library project's if needed
yourAppProject/gen
yourAppProject/src
Make sure all files in the res folder's subfolders have names that are ok : only lowercase letters, digits and underscore ("_") .
Always make sure the targetSdk is pointed to the latest API (currently 18) , and set it in the project.properties file
If above doesn't work then try next method 2 given below:
The step to solve the issues is easy. You just mouse point to your project folder (Example: SampleAndroid), then right click and now choose “Build Project”. Your all project will rebuild.
Once rebuild complete, you can see that the error icon was disappear on the MainActivity.java code. Now you can run your application in Emulator.
Maybe try "Project->clean" in order to rebuild.
First of all check the Problems tab that will you show you what may cause this. Also clean your project as it might solve some issues.
I also faced the same problem and solved it by deleting appcompatv4 file from libs folder. Try it, it might help to you.
I have this problem, finally,I solved this by opening my SDK manager → download Android support in Extras,you can try.
check your Android support is installed, and then you can build a new project without errors.

Cannot create new project - There must not already be a project at this location

I am trying to start using the just released Android Studio, I have already established the location for the Android SDK, and the Studio opens correctly.
Now, I want to create a new application project, but I cannot figure out what to select as project location.
Steps followed:
Launch Android Studio
Select New Project
Enter Application Name, Module Name, Package Name.
Click on the '...' button to select a project location
Select the appropriate folder I created for the project, which is empty. See Screenshot here of the dialog at this point.
Clicked Ok on the dialog, and now I am prompted with a second dialog, that is now labeled 'Select Path', where previous dialog was labeled 'Please choose a Project Location'. No matter what folder I select, the option for 'Ok' is grayed out and cannot be selected. Image here.
I read a similar question, and I am making sure, as you can tell by the steps I followed, that I am entering the path at the very end, and it still won't work for me.
I really think there must be a silly thing I am missing here, not sure what it may be though.
Any ideas?
So, apparently what caused the main problem is that the first time I launched Android Studio I didn't create a new project, I imported one, and that seemed to screw the whole workflow of it.
As per someone's answer, who was apparently removed, here are the steps.
Go to C:\Users\Username\ and erase the folder named: .AndroidStudioPreview.
Launch Android Studio again, it will ask if you want to import any settings, select the option that doesn't import anything.
Optionally Configure, Project Defaults, Project Structure, Platform Settings, and make sure that both the JDK and Android SDK are configured, for instance, I had to point Android Studio to a folder where the SDK had already been downloaded.
Create new project, and leave the default workspace that will now show, it should be C:\Users\Username\AndroidStudioProjects
That's it, just go through the setup wizard, and you're done.
This is a really simple issue. Android Studio likes to create the folder for the project on its own. That means you can't just select a pre-made folder. For example if you select C:/Android Projects with Android Projects being a folder, you must append a folder name to the location for Android Studio to create, for example C:/Android Projects/NEW PROJECT
No work-arounds needed.
I have found a workaround.Here's what I did :
Click on check out from version control.
Select git(I have a bitbucket account,but might work with github).
Put in repo-url
Select the parent directory(this directory will also become the parent directory of your android projects)
Then click clone
Select YES when asked if you want to create Android studio project from existing sources.
Select Create Project from existing sources
Don't change anything,select Next and then Finish.
Now it will create a new project at your selected location
Close android studio,go back to your parent directory and delete the project folder.
And now start your new project wizard,you should be able to see your parent directory listed in project location.Start typing details about your project and the directory will be updated accordingly.
I had the same issue this morning when trying to create a new project and found a simple way to get around it.
Choosing the path to the project folder was impossible as I kept getting the same error message 'There must not already be a project at this location'. What I then did was type out the path manually, but not all at once. To begin with I thought I'd just try to set a folder at the root of my drive eg. C:\AndroidStudioProjects. It seemed to be ok with this, which led me to try to add the rest of the path manually as well. So the final path would be something like C:\Development\Android\AndroidStudioProjects
This worked, no errors showed up and it let me go through the rest of the set up.
Hope this works for others out there who are facing the same issue.

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 Properties Window

If I right click on my project and select properties. Then select android properties on the left side of the screen I am given a window where I can change project build target or add a library. The problem is none of my changes appear to be "sticking" in this screen when I hit apply or ok.
For example I go into the screen to add a library project:
Then I hit apply, then ok. When I go back into the screen none of my changes have been applied:
This is a problem because I want to reference a library project in my main project. Whenever I try to reference one of the classes in my library project from my main project I get a class not found exception. Also whenever I run my project it says the libray-project.apk is not found in the console window?
Any suggestions or is this possibly a bug in eclipse or the android tools?
This bug has been reported here: http://code.google.com/p/android/issues/detail?id=17673&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars
Check that default.properties file is not read-only. This file is located in root folder of your Android project.
UPDATE: I actually tried making this file read-only and can see exactly the same behavior, but on Ubuntu. Don't have access to Windows machine now. This should probably be reported as bug.

How to attach Android Source to Eclipse

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 .

Categories

Resources