Development issue/problem:

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:

  1. Remove the ‘:app’ include from settings.gradle.
  2. Deleting the Application Folder
  3. Replace build.gradle with the example at the end of this post (IntelliJ creates a similar post).
  4. Create a directory hierarchy for your Java code (src/main/java)
    Enter a description of the image here .
  5. Select Change Configuration from the drop-down menu where you would normally start a project.
  6. Click the Add New Configuration button and select application
    , enter the description of the image here .
  7. 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:

  1. Create a new Android project
  2. Add a Java module to your project
  3. Exit the android studio project and go to the project directory, take the java module folder and paste it into a new directory.
  4. 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

  1. Create an empty folder in which you want to place the project.
  2. On the Welcome to Android Studio screen, select Open Existing…
    Provide a description of figure here.
  3. Navigate to your folder and click OK.
  4. Your project is created, now add the Java files
    , fill in the description of the image .
  5. 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:

  1. Create a new project or open an existing one.
  2. Right-click on the package name in the java folder > New > Scratch file
  3. In the dialog box, choose java

Now, a class called Scratch.java opens, whose code can be written here….

  1. 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!

how to run java program in android studiohow to generate aar file in android studioandroid studio add module dependencyandroid library project exampleandroid module tutorialhow to add module in android studioandroid studio java programminghow to import project in android studio from folder

You May Also Like

10 Best Motherboards with PCIe 4 – Buying Guide (2021)

This article contains affiliate links for which we may receive a commission…

PowerToys Stable Version 0.29.0 is Now Available

Microsoft has released a supporting version of PowerToys. Version 0.29 contains some…

How to restore missing SNMP in Windows 10 [ULTIMATE GUIDE]

Read the following instructions. Table of contents : Using third-party tools Installing…

9 Things That Can Damage Your Laptop

The laptop is becoming the standard piece of technology in today’s society,…