Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running Java application in Android Studio

I created new libgdx project and i want to run desktop application in Android Studio. Is there something to do with run configurations? In Eclipse i can just choose Run as Java Application.

like image 357
nikoliazekter Avatar asked Jan 04 '15 13:01

nikoliazekter


People also ask

How do I run a Java program in Android Studio?

Easy way to run a java program in Android Studio would be, 1) Create a java Class say "Test.java" in Android Studio. 2) Write your code eg, a Hello World program to test. 3) Right click on the Java class and select the option "Run 'Test.main()'" or press Cntrl+Shift+F10.

How do I run an app on an Android device?

How to Run My App on Android 1 In the toolbar, select your app from the run configurations drop-down menu. 2 From the target device drop-down menu, select the device that you want to run your app on. If you don't have any devices configured, then you need ... 3 Click Run . See More....

Why can’t my Android program run Java class files?

In case you are not used to doing this outside of an IDE, here’s the command: Make sure the program compiled properly: Android cannot run Java class files directly. They have to be converted to Dalvik’s DEX format first (yes, even if you are using ART): NOTE: Android Build Tools v28.0.2 and later contain a dx upgrade, called d8.

Should I stick with Java for my Android app development?

Sticking with Java would have the benefit of avoiding all of the native ABI hassle and also being able to call into the Android runtime. So how do we do that? Let’s start with the Java program we want to run.


2 Answers

Ok, i did it. Here is the solution https://github.com/libgdx/libgdx/wiki/Gradle-and-Intellij-IDEA#running-your-project

Run -> Edit Configurations..., click the plus (+) button and select Application.

Set the Name to Desktop.

Set the field Use classpath of module to desktop, then click on the button of the Main class field and select the DesktopLauncher class.

Set the Working directory to your android/assets/ (or your_project_path/core/assets/) folder!

Click Apply and then OK.

You have now created a run configuration for your desktop project. You can now select the configuration and run it.

like image 50
nikoliazekter Avatar answered Oct 17 '22 01:10

nikoliazekter


Right click on the main method (or anywhere in the main class) and select Run.

like image 36
JBaruch Avatar answered Oct 17 '22 01:10

JBaruch