Reputation: 4830
I have some code that uses the android packages for HTML parsing. Is there a simple way to run the code in Eclipse using a main method without fussing with an emulator?
Upvotes: 0
Views: 1011
Reputation: 264
If you really do want to run a main over your code (let's say, you got a routine to run): Create another Eclipse project referencing the Android code and put you main there. You'll be able to call any class that do not depend on an emulator.
Upvotes: 6
Reputation: 24820
You can do it. I think its more complicated than the normal apk method. But you could still try it. You need dx tool. dx tool is present in android-sdk/platform-tools/
class Foo {
public static void main(String[] args) {
System.out.println("Hello, world");
}
}
javac Foo.java
dx --dex --output=foo.jar Foo.class
adb push foo.jar /sdcard
adb shell dalvikvm -cp /sdcard/foo.jar Foo
you can get more information here
Upvotes: 1
Reputation: 1447
Your question isn't very clear. When programming for Android, you can't use a "Main" method. Android applications begin in the onCreate
method of your class that extends Activity.
EX: public class LeGame extends Activity
However, I assume you want to run your Android code without using the computer's emulator. You can run it on your Android phone. On your phone, go to Settings > Applications > Development > USB Debugging (Check it).
Now, when you connect your phone to your computer, you can simply click "Run" in eclipse, and your application will run on your phone.
(Assuming you have downloaded and installed all the required Android SDK packages, etc)
Upvotes: 0