是否可以在Android Studio中编译简单的Java代码? [英] Is it possible to compile a simple Java code in Android Studio?

查看:287
本文介绍了是否可以在Android Studio中编译简单的Java代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经拥有Android Studio,但不是Eclipse。

I already have Android Studio, but not Eclipse.

我是否必须安装Eclipse才能测试一些简单的Java代码?或者是否可以使用Android Studio?

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

两者之间有什么区别?

推荐答案

关于Android Studio的一个很酷的事情是它将构建过程委托给Gradle。使用Gradle,构建一个普通的Java应用程序需要在build.gradle文件中添加必要的插件。

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"

您无需通过新项目向导。只需创建一个项目目录,使用上面的脚本在其中创建build.gradle文件。把你的java源代码放在'src / main / java'中。

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'.

在Android Studio中单击导入项目(Eclipse,Gradle等),打开项目目录并选择build.gradle文件。选择确定以配置Gradle包装器。导入完成后按RUN键让插件完成其余操作。

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.

注意,'application'插件也隐式应用了Java插件。

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

有关这些插件的更多信息,请访问:
https ://docs.gradle.org/current/userguide/application_plugin.html 和此处:
https://docs.gradle.org/current/userguide/java_plugin.html

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

这篇关于是否可以在Android Studio中编译简单的Java代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆