Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio: create Java project with no Android dependencies

It's possible to add pure Java module to existing Android project.

But is it possible to create pure Java project with no Android dependencies?

like image 655
Alexey Dmitriev Avatar asked Mar 10 '15 06:03

Alexey Dmitriev


People also ask

Can we create Java project in Android Studio?

In an open Android Studio project, click File > New Module. Click More Modules > Java Library > Next, then fill in whatever you prefer for the names. A new module will appear as a folder on the same level as your "app" folder in the Project Structure. Open it and open the new Java class file.

What is the difference between AAR and jar?

The main difference is aar is splitted inside android to jar. If your app will be used only in user app only in android studio then aar is preferred. If you are planning for app to communicate with c/c++ compiled lib.so file jar is preferred.

Why dependencies are used in Android Studio?

In Android Studio, dependencies allows us to include external library or local jar files or other library modules in our Android project.

Where is the libs folder in Android Studio?

How to find the libs folder in Android Studio? If you are unable to find the libs folder in Android studio then open your android project in “Project” mode If the project is already opened in the “Android” mode. Then go to Your Project Name > app > libs and right-click on it and paste the downloaded JAR files.


1 Answers

Yes, it is possible. You have to manually create all necessary files.

Here are steps for Gradle based project:

  1. Remove include ':app' form settings.gradle
  2. Remove app directory
  3. Replace build.gradle with example from end of this post (IntelliJ creates similar)
  4. Create folder hierarchy for your Java code (src/main/java) enter image description here
  5. Select Edit Configuration from drop down menu where normally you start project

  6. Click Add new Configuration and select Application enter image description here

  7. In Main class point your Main class.

Android studio is more or less like IntelliJ Community Edition.

apply plugin: 'java'  sourceCompatibility = 1.8 version = '1.0'  repositories {     mavenCentral() }  dependencies {     testCompile group: 'junit', name: 'junit', version: '4.11' } 
like image 157
Aleksander Mielczarek Avatar answered Oct 09 '22 11:10

Aleksander Mielczarek