Make eclipse debug my android PROJECT
I am writing an Android application using Eclipse. When I click on the project in the left tree view and then click debug, the IDE builds an APK and inst开发者_Python百科alls in the emulator / device as expected.
However, if I'm editing a file and forget to first click on the project before attempting to debug, the IDE thinks I want to debug that specific Java file. This is NOT what I want to do, I would like it to build and emulate / install on device as usual.
Is there any way to change this behavior in Eclipse?
In eclipse, you can set in workspace preferences / run-debug / launching to always launch the previously launched application (until you explicitly choose an other application: then it will be the last that will be launched).
This way, no matter where you press (ctrl)F11 or click the debug/run button, the launch configuration you used the last time will be called again.
You will still be able to launch different applications of course, by explicitly calling their launchers (the way you debug now).
The procedure you are using (clicking on the project and selecting Debug as
=> Android Application
is OK, for the first debug session (resp. Run as
, non debug).
If you want to debug the app again (regardless of what is selected in the left hand side navigator), you should just click on the Green Run
circular icon (or rather on the small >
sign on its right side if you want to select a different run configuration) or the little bug on its left (for debug).
If you click on one of the >
you will select on of the 8 last run/debugged app. If you are sure that the last one is the one you want to run again, then just press one of these two icons (bug for debug, green arrow for run) instead of the arrows.
When you click on the project and select Debug as
what you actually do is configure a default run configuration for this app or class that can be later tweaked through the Run/debug Configurations...
to better suit your customisation needs. If you click again, eclipse will detect that it has already generated a default configuration (and will not create a new identical one). Alternately you can directly create your new Run/Debug config directly through the Run/debug Configurations...
sub menu.
Since the ADT plugin shipped by Google does not include a Run as... Android Application
submenu when you click a java class under an android project, the default launch configuration is the java application or the server application (static main method absent).
Update
To clarify things a bit. What you ask (running your android app whilst having the java class selected in the package explorer is possible). What happens when you press the 'small bug' icon does not depend on what is selected in any navigator.
The "default launch configuration" is poorly phrased.
Let me describe what happens in more detail. When you right-click on a java class say in the package explorer (or the project explorer for Java EE version) eclipse (the navigator) calls all contributions (plugins) having registered a handler for that event and lists possible candidates in a sub menu.
In a standard Java EE eclipse installation you will see at least the run on server
option and if the class has a main static method with string array arguments, you will also have a the runs as ... java application
option. In both cases, eclipse will generate for you a "launch configuration". These launch configurations (both debug and non debug) are all available in the launcher dialog boxes (accessible via the icons described above). They have a lot of different configuration options depending on their nature (for instance whether you debug on a server or a simple java app or an applet). What I termed the "default configuration" is that for each of this launch configuration categories, eclipse will leave these options empty.
So the first time, you will select the Android project and select the run as... Android application
option. This will create a default configuration. In ADT's case, the default configuration will also probably select a default ADV and launch it (if it's not already launched). And on subsequent occasions, it will be enough to press the run or debug icon to redeploy your app back to your ADV and this will happen regardless of what is selected in the navigator.
精彩评论