Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't find import module option in project structure (Android Studio 0.3.4 - 0.5.2)

I'm getting really confused and frustrated because I just can't understand how to import my android library project as dependency for my application project.

I tried to find online and most of the answers suggested to go to project structure of my application and click on '+' and then click on 'import module'

But Android Studio 0.3.4 - 0.5.2 doesn't show any options and when I click on '+', it just shows the windows for a new module.

Am I doing something wrong or what ?

Help!!!

like image 628
Jigar Avatar asked Nov 11 '13 03:11

Jigar


People also ask

How can I import module in Android Studio?

Import a moduleClick File > New > Import Module. In the Source directory box, type or select the directory of the module(s) that you want to import: If you are importing one module, indicate its root directory.

How do I import a module into gradle?

In Android Studio, Right-clicking on the folder to add as library. Editing the dependencies in the build. gradle file, adding: compile fileTree(dir: 'libs', include: '*. jar')}

Can we import module from source in Android Studio?

Select the source directory of the Module you want to import and click Finish. Open Project Structure Dialog (You can open the PSD by selecting File > Project Structure) and from the left panel click on Dependencies. Select the module from the Module(Middle) section In which you want to add module dependency.


2 Answers

You'll run into this when working with Gradle-based projects, as this one is; even in 0.3.2, this Import project command was doing the wrong thing; it would seem to work, and would make syntax coloring in the editor work properly, but it would fail when you would try to build and run your app, and your changes would be lost when you re-synced the project with the Gradle build files. This is why this has been removed until it can be properly reimplemented. The bug to track it is at https://code.google.com/p/android/issues/detail?id=62122

In the meantime, to add an existing library as a dependency, you'll need to do it by hand in your Gradle build files. To do so, move the library so its directory is under the project root (at the moment, including modules outside the project root isn't supported), write a build.gradle build file that will build the module, and include the module in your settings.gradle file.

You might find it easier if you go through the File > New Module... command to create a blank module, choosing either a plain Java module or an Android module as appropriate, and copying the library files into the module directory where they need to go. That will take care of the Gradle files for you and set up the skeleton directory structure.

like image 105
Scott Barta Avatar answered Oct 07 '22 19:10

Scott Barta


For android studio 0.5.7, volley was successfully imported as a library project following these steps:

  1. Create a directory named "libraries"(whichever you want) under your project root
  2. Clone volley using git under the directory created in step 1, command is "git clone https://android.googlesource.com/platform/frameworks/volley". Now the project structure looks like:

    [Project root] |- [Your module] |- libraries    |- volley 
  3. Import volley through : Right click project root -> Open Module Settings -> Click "+"(New Module) in the up left corner -> Import existing project -> Select volley source directory -> Next After step 3, volley is imported, but dependency on library project volley is not setup yet.
  4. Setup module dependency : Right click project root -> Open Module Settings(Now volley should appear in the module list) -> Choose [Your module] -> Switch to tab "Dependencies" -> Click "+"(Add) in the left bottom corner -> Choose "Module dependency" -> Select ":volley" in the module list dialog
  5. Now everything works fine, you can use volley as you want
like image 44
cmoaciopm Avatar answered Oct 07 '22 19:10

cmoaciopm