Difference between revisions of "CISC181 S2017 PlainJavaInAndroidStudio"
From class_wiki
(Created page with "This is adapted from idunnololz's comment titled "Tested on Android Studio 0.8.6 - 1.0.2" [http://stackoverflow.com/questions/16626810/can-android-studio-be-used-to-run-standa...") |
|||
Line 6: | Line 6: | ||
# Click '''File > New Module'''. Under "More modules", select '''Java Library''' and click '''Next'''. | # Click '''File > New Module'''. Under "More modules", select '''Java Library''' and click '''Next'''. | ||
# Set the library name to be "java" (this is arbitrary) | # Set the library name to be "java" (this is arbitrary) | ||
− | # Click Edit and fill in the package name (which you just created [http://nameless.cis.udel.edu/class_wiki/index.php/ | + | # Click Edit and fill in the package name (which you just created [http://nameless.cis.udel.edu/class_wiki/index.php/CISC181_S2017_NewAndroidStudioProject here] -- should be cisc181.mylab_n) |
# Fill in a class name -- "MyClass" or whatever the assignment specifies -- and click '''Finish'''. You should now see a module called "java" inside your Android project. | # Fill in a class name -- "MyClass" or whatever the assignment specifies -- and click '''Finish'''. You should now see a module called "java" inside your Android project. | ||
# Open the "java" module folder, double-click on "MyClass" (or whatever your class name is) and start coding! For example, paste this into MyClass (between the curly braces) and save with Control-S: | # Open the "java" module folder, double-click on "MyClass" (or whatever your class name is) and start coding! For example, paste this into MyClass (between the curly braces) and save with Control-S: |
Revision as of 16:34, 3 February 2017
This is adapted from idunnololz's comment titled "Tested on Android Studio 0.8.6 - 1.0.2" here.
Using this method you can have Java modules and Android modules in the same project and also have the ability to compile and run Java modules as stand alone Java projects.
- Open your Android project in Android Studio. If you do not have one, create one.
- Click File > New Module. Under "More modules", select Java Library and click Next.
- Set the library name to be "java" (this is arbitrary)
- Click Edit and fill in the package name (which you just created here -- should be cisc181.mylab_n)
- Fill in a class name -- "MyClass" or whatever the assignment specifies -- and click Finish. You should now see a module called "java" inside your Android project.
- Open the "java" module folder, double-click on "MyClass" (or whatever your class name is) and start coding! For example, paste this into MyClass (between the curly braces) and save with Control-S:
public static void main(String[] args) { System.out.println("Hello World!"); }
- Before you forget, make sure to ADD YOUR NAME to the code as a comment.
- Click on the drop down menu to the left of the run button (the green triangle next to the bug icon). Click Edit Configurations...
- In the new window, click on the green plus sign at the top left of the window and select Application
- A new application configuration should appear. Enter in the details such as name ("MyJavaProgram"), your full main class ("cisc181.mylab_n.MyClass"), and classpath of your module ("java"), and click OK
Now if you click run, this should compile and run your Java module.