Import an external module to Android Project in Android Studio

Today I want to talk about an importing external module to Android project in Android Studio.

As example you have folder Projects with two subfolders FirstApplication and simpledateformatter. In this case simpledateformatter it’s just a module which you want to use in the FirstApplication.

Example of project folder

Import library via IDE (Android Studio)

First and simplest way it’s import your additional module via IDE. (File / New / Import module OR File / Project Structure / + ) Unfortunately it’s not a better way because you can find copy of your additional module into main project folder.

Imported module via IDE

Of course it’s working correctly and you can use and modify your library, but in this case you will update just module into subfolder of you main project. It’s not a better ways for your module, because probably you want to use you additional module not just for one project. In this case better way it’s configure gradle files for using additional folder without copy whole module to you project.

Configure gradle from import project

You can configure gradle files in your project(s) and your applications can use one folder with you additional project without creating subfolders into project folder. It’s better way for support you additional module, because if you add some changes to your additional library all your project will use this module with all changes.

For it need to open settings.grade file in “Main project” and need to add some lines:

include ':simpledateformatter'
project(':simpledateformatter').projectDir = new File(settingsDir, '../simpledateformatter')

After it need to add dependency to build.gradle file in your project, for it need to add to this files next line:

compile project(':simpledateformatter')

After these changes you will use additional module from default folder of additional module.
Imported module in Android Studio

Of course you must adapt path to your additional module to your situation. As example in situation where you have your Main project and additional module in the same folder all works correctly.

Example of project folder

Full source code of settings.gradle file:

include ':app'
include ':simpledateformatter'
project(':simpledateformatter').projectDir = new File(settingsDir, '../simpledateformatter')

Full source code of build.gradle file:

apply plugin: ''

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.alexzh.tutorial.firstapplication"
        minSdkVersion 14
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), ''

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile ''
    compile project(':simpledateformatter')

Note: Of course you have some other ways for use last version of you library

  • repositories (maven , jcentral, ..)
  • aar, jar files

I hope it was helpful for you. If you want get more article about mobile development join to Facebook community or follow me.
Thank you for your time and have a nice day.


14 thoughts on “Import an external module to Android Project in Android Studio

  1. I got it, but i have a issues:
    Error:A problem occurred configuring project ‘:app’.
    > Cannot evaluate module XXX: Configuration with name ‘default’ not found.

    1. Thankyou! I got it, but i have a issues:
      Error:A problem occurred configuring project ‘:app’.
      > Cannot evaluate module XXX: Configuration with name ‘default’ not found.
      Can you help me?

        1. thank you!

          this is content settings.gradle of main project:

          include ‘:app’
          include ‘:Library3Test’
          project(‘:Library3Test’).projectDir = new File(settingsDir, ‘../Library3Test’)

          this is content build.gradle of main project:

          dependencies {
          compile fileTree(include: [‘*.jar’], dir: ‘libs’)
          testCompile ‘junit:junit:4.12’
          compile ‘’
          compile project(‘:Library3Test’)

          project Library3Test and main project in one folder(same path).

          Im sorry for bad english!

          1. As I understand correctly, you have something like this,

            Project1 / app / …

            Is it true?

  2. First and foremost, thanks for helping beginners, i as one, truly appreciate your tutorials.
    I would like it if you make a video tutorial showing us step by step because I only understand android programming by watching android tutorials.
    Thanks for reading, hope I’m not asking for too much

  3. Thanks for this example! There is really not much gradle examples out there and this one is so helpful for beginners in gradle like me!

Leave a Reply

Your email address will not be published. Required fields are marked *