It is possible to add a specific Java module to an existing Android project.
But is it possible to create a pure Java project without Android dependencies?
How can I solve this problem?
Solution 1:
Yes, it’s possible. You need to create all the necessary files manually.
Here are the steps of a project based on Gradle:
- Remove the ‘:app’ include from settings.gradle.
- Deleting the Application Folder
- Replace build.gradle with the example at the end of this post (IntelliJ creates a similar post).
- Create a directory hierarchy for your Java code (src/main/java)
. - Select Change Configuration from the drop-down menu where you would normally start a project.
- Click the Add New Configuration button and select application
. - Register your major in the major league.
Android Studio is more or less similar to IntelliJ Community Edition.
Application plugin: java
sourceCompatibility = 1.8 version
= ‘1.0’.
Deposits {
mavenCentral()
}
Dependencies {
testCompile group: junit, name: junit, version : ‘4.11’
}
Solution 2:
Not through the New Project Wizard.
An alternative is to create a Java maven/gradle project outside Android Studio and then import it into AS via File->Open.
Gradle has an init plugin for installing Java projects:
gradle init — java library type
https://docs.gradle.org/current/userguide/build_init_plugin.html
Solution 3:
I think it is possible to create a new module with the following path (using Androdi Stdio 1.1.0) :
File> New Module> Select from Add-ons> Java Library
I hope it’s good for you.
Solution 4:
No, you cannot build a Java project with Android Studio because the AS building system does not allow you to build the project after you finish writing your application. The Android Studio review system only collects .apk files.
Android Studio does not support most things that require an external database or application server.
Solution no. 5:
The easiest way is to temporarily disable the Android support plugin. Uncheck Configuration > Plugin > Android Support Plugin
After restarting a running project, you will get a new project wizard with all non-Android options. After creating a new project, you can reactivate the Android plug-in.
Solution no. 6:
One thing you might want to add here to REALLY help new people (it gave me ideas) is that after creating a directory hierarchy for your java code (src/main/java), you need to right click on the java directory and select Mark Directory As > Sources Root. Otherwise, you cannot create a new Java class in the foo directory.
Solution no. 7:
Another way of looking at it from my point of view:
- Create a new Android project
- Add a Java module to your project
- Exit the android studio project and go to the project directory, take the java module folder and paste it into a new directory.
- In Android Studio open this module, ideally a completion file will be generated for you.
Solution no. 8:
Alexander’s answer worked for me. Thank you, Alexander. Then I had to create a package and add a new Java class to it for step 5. Then, in step 6, I used this Java class as the MainClass.
Solution no. 9:
The easiest way to start from zero
- Create an empty folder in which you want to place the project.
- On the Welcome to Android Studio screen, select Open Existing…
here. - Navigate to your folder and click OK.
- Your project is created, now add the Java files
. - Choose the SDK and you’re done! Happy coding
Solution no. 10:
The easiest way to run a clean Java program is to type.
Follow these simple steps:
- Create a new project or open an existing one.
- Right-click on the package name in the java folder > New > Scratch file
- In the dialog box, choose java
Now, a class called Scratch.java opens, whose code can be written here….
- To start the program, right-click on Scratch.java and select Option -> ‘Scratch.main()’.
You can now see the results of the program.
Good luck!
Related Tags:
how to run java program in android studio, how to generate aar file in android studio, android studio add module dependency, android library project example, android module tutorial, how to add module in android studio, android studio java programming, how to import project in android studio from folder