Android Studio: create Java project with no Android dependencies

前端 未结 10 1665
遇见更好的自我
遇见更好的自我 2020-12-12 16:20

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?

相关标签:
10条回答
  • 2020-12-12 16:54

    Easiest method is to temporarily disable the Android Support Plugin. Un-check Configuration > Plugin > Android Support Plugin After restarting close any current project and you will get the new project wizard with all of your non-android options. Once your new project is created you can re-enable the Android plugin.

    0 讨论(0)
  • 2020-12-12 16:55

    I think this is possible to create a new module from following path (Using Androdi Stdio 1.1.0):

    File> New Module> Choose from more module> java library

    Hope it will work's for you.

    0 讨论(0)
  • 2020-12-12 16:56

    No you cannot create a java project with Android Studio because AS's building system won't let you build your project once you are done writing your application. Android Studio's gradle building system only builds .apk file.

    Android Studio won't support most things requiring an external database or application server.

    0 讨论(0)
  • 2020-12-12 16:56

    One thing that you might want to add here to help REALLY new folks out (it kept tripping me up) is that after creating the folder hierarchy for your Java code (src/main/java) you must right click the java folder and select Mark Directory As > Sources Root. Otherwise, you won't have the option of creating a new java class within the foo directory.

    0 讨论(0)
  • 2020-12-12 16:57

    The answer by Aleksander worked for me. Thanks Aleksander. I further needed to create a package and add a new java class to it before Step 5. Then in Step 6, I used that java class as the MainClass.

    0 讨论(0)
  • 2020-12-12 17:00

    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'
    }
    
    0 讨论(0)
提交回复
热议问题