Skip to content

Instantly share code, notes, and snippets.

@alwarren
Last active April 29, 2018 16:09
Show Gist options
  • Save alwarren/dc2bd623d85f5a696a9ade4fbba9c67c to your computer and use it in GitHub Desktop.
Save alwarren/dc2bd623d85f5a696a9ade4fbba9c67c to your computer and use it in GitHub Desktop.

Task: Manually add a Java module in Android Studio

Steps

  1. Switch to Project view.
  2. In the project root folder, create a folder with a unique identifiable name for the module. This folder becomes the root folder for the module.
  3. Within the module's root folder, create a src/main/java folder.
  4. Within the module's root folder, create a build.gradle file.
  5. Within the module's build.gradle, insert the following two lines:
    a. apply plugin: "java" // apply the java plugin
    b. sourceCompatibility = 1.8 // Java 8 source compatibility
  6. Add the module to settings.gradle using the folder name from step 2.
    a. include ':app', ':yourModuleFolder'
  7. Add the module to your application's build.gradle.
    a. implementation project('yourModuleFolder')
  8. Synchronize the project and wait for it to rebuild.
  9. Create a package structure in your module's java folder.

At this point, when you switch back to Android Project view, you should see your new module below your app's root folder and your module's build.gradle should show up under Gradle Scripts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment