Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to compile a simple Java code in Android Studio? [duplicate]

I already have Android Studio, but not Eclipse.

Do I have to install Eclipse in order to test some simple Java code? Or is it possible using Android Studio?

What is the difference between both?

like image 717
Seung Joo Noh Avatar asked Jan 26 '26 17:01

Seung Joo Noh


1 Answers

The cool thing about Android Studio is that it delegates the build process to Gradle. And with Gradle, building a plain Java application is a matter of adding the necessary plugin to the build.gradle file.

apply plugin: 'application'

mainClassName = "com.your.package.MainClassName"

And you don't need to go through the new project wizard. Just make a project directory, create a build.gradle file in it with the script above. Put your java source code is in 'src/main/java'.

In Android Studio click 'Import Project (Eclipse, Gradle, etc.)', open the project directory and select the build.gradle file. Choose OK to configure Gradle wrapper. When the import is finished press RUN and let the plugin do the rest.

Note, that the 'application' plugin also implicitly applies the Java plugin.

More about these plugins here: https://docs.gradle.org/current/userguide/application_plugin.html and here: https://docs.gradle.org/current/userguide/java_plugin.html

like image 84
dev.bmax Avatar answered Jan 28 '26 06:01

dev.bmax



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!