1

I have a small github project which i opened in Android Studio from below link.

https://github.com/adakoda/android-screen-monitor

It has no compilation errors , But i see no Run Configuration to run that main method from AndroidScreenMonitor.java. And also i dont find a way to create a jar file from this .java .

I tried to help myself with creating RunConfigurations by following the links below:

Run single java file with standard main(String [] args) method - Android Studio

Running Java application in Android Studio

In Run -> EditConfigurations -> MainClass drop down -> Click 3 dots -> Choose Main Class window ,it doesnt let me select the AndroidScreenMonitor.java file or any file as the main file which means the OK button is never enabled.

Is there a way to fix this issue. So that i can run this project from Android Studio.

Community
  • 1
  • 1
krrishna
  • 2,050
  • 4
  • 47
  • 101
  • why to use Android Studio to run a java project with a main? You could use intelliJ IDEA and not mess with android libraries. I guess there could be a way somehow but I have never tried what you are trying to do. All java modules I have made in Android Studio did not include a main and were created to be used as libraries in Android Projects – Klitos G. Mar 18 '17 at 20:24
  • @KlitosG.I tried IntelliJ IDE but and i had the same issue. – krrishna Mar 18 '17 at 20:45

1 Answers1

1

Your project is an Eclipse project that uses swing. You should not use Android Studio for this, you should use IntelliJ.

I cloned your repository and I am able to build it in IntelliJ, follow this steps to build your project:

  • In the first screen of IntelliJ select Import Project
  • In import screen, navigate to your project dir and open it.

  • Select Eclipse as the external model

  • IntelliJ will convert your project to the gradle build system.

  • Now your project should build without problem.

  • To run in, go Run->Edit Configuration.

  • In the top left corner select the plus (+) icon and select application

  • In the main class, select the three dots and select your main class.

  • Give the configuration a name, suggestion: App and press OK.

  • Now in the top right corner, in the dropdown will have the App and a play button, click in the play and your project will run.

jonathanrz
  • 4,206
  • 6
  • 35
  • 58
  • 1
    To add to this answer, it also searches for jdk1.5. you will have to choose a java sdk that you have installed on your computer eg jdk1.8 – Klitos G. Mar 18 '17 at 21:10
  • Android Studio runs Java apps just as well as Intellij – OneCricketeer Mar 18 '17 at 21:10
  • @cricket_007 are you sure? Android Studio doesn't have the import screen to select the dependencies. I know that it can import Eclipse projects that use ADT, pure Eclipse project I never tried. – jonathanrz Mar 18 '17 at 21:11
  • 1
    Android Studio only builds over IntelliJ with Android specific features. Nothing is removed from IntelliJ base featureset – OneCricketeer Mar 18 '17 at 21:47
  • 1
    Thank you so much everyone for your inputs.Thank you @jonathanrz. It worked now and i am able to run it in IntelliJ. – krrishna Mar 19 '17 at 00:20