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

5

67

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!!!

Restrainer answered 11/11, 2013 at 3:42 Comment(11)
Not yet. As suggested by @JerothKP, I might just reinstall 0.3.2 versionRestrainer
Has anyone heard when the import module option is coming back to Android Studio?Breeding
@toobsco42 well you can just track the issue at code.google.com/p/android/issues/detail?id=62122Restrainer
0.4 and is not back, yetRogovy
What is the standard way of importing an existing new module into my project?Boomerang
@Injhb According to that code.google/issues page, AS 0.5 will have that feature (if I'm not wrong). The problem is that we don't know when it will be ready. Have you managed to solved your problem manually? I'm facing the same problem. My own library project with many projects which depends on it (and I prefer a project-reference style rather than a copy/paste).Rogovy
Android Studio 0.5 has been released. Does it fix this issue or not?Rogovy
@Rogovy No. Android Studio 0.5 doesn't have the fix as Google team promised.Restrainer
this answer will help. [stackoverflow answer][1] [1]: https://mcmap.net/q/204451/-using-facebook-sdk-in-android-studioNightie
@Nightie No. that solution is not feasible because if two different apps are using one library then both apps will have to contain entire library in their structure.Restrainer
This feature has finally arrived in Android Studio 0.5.3 (released on March 27th, 2014)Restrainer
R
2

Finally the import module feature has arrived in Android Studio 0.5.3 which was release on March 27th, 2014.

Take a look here: http://tools.android.com/recent/androidstudio053released

I have also tested and it's there in project structure window.

In Module tab, you can now press the '+' button and either import an existing module or create a new one.

Restrainer answered 28/3, 2014 at 23:42 Comment(14)
I updated to the 0.5.3 somehow the import module is not there. I tried File->Import Module, but it opened another project window.Goosander
@TanJitRen What are you trying to achieve ? Import module lets you import another project into the current one so that you can have dependencies.Restrainer
I wanted to import existing module but my 0.5.3 doesn't include the feature. Look over here, he's facing the same issue too. #22744211Goosander
@TanJitRen I don't think that issue is related to import project settings. It looks like related to incorrectly build gradle project. As I mentioned there, you can try using this manager-plugin by Jake Wharton. github.com/JakeWharton/sdk-manager-pluginRestrainer
I tried with the manager-plugin by Jake Wharton or create a new project and the import module still not available. I'm using classpath 'com.android.tools.build:gradle:0.9.+' classpath 'com.jakewharton.sdkmanager:gradle-plugin:0.9.+'Goosander
@JabbarJigariyo You mention something about the gradle project being build or setup incorrectly, but I don't see what could be wrong with how it is. I'm having the same issue as the link that Tan-jit-ren mentioned. Essentially Import Module performs like the old version of Import Project (opens a new Window) and the Project Structure window doesn't have an Import option, only a New option. Do you have any idea on what the gradle issue might be? I also just tried with a new project, sadly that produced the same result.Portugal
It seems like there might have been a bug in 0.5.3. I just installed 0.5.4 a minute ago and while Project Structure doesn't allow import, one can perform the import via File -> Import Module now and that works! Woo hoo!Portugal
I spoke too soon. You can indeed import a module now, but it seems to make a copy of the entire module rather than linking to a module outside of the project structure. Any changes you make are local to new copy. So, this is only slightly useful really. It is more useful than not having the ability at all, but still pretty useless if you want to have a Library that is in a sep. repo than your App, etc.Portugal
I found an answer to my problem via #17479576 - That might help OP and other users that would like to actually link to a module that is outside of the project structure (different repo, etc).Portugal
@Portugal So it wasn't a problem with 0.5.3 but how the project has been structured. That's what I was trying to say about incorrect setup. I'm glad you found the solution :)Restrainer
@JabbarJigariyo Right, but nothing changed for me between 0.5.3 and 0.5.4 where the Import functionality actually performed an import (though not the way I thought it would). At least I was able to edit the gradle file to do the import as I thought it should happen.Portugal
@Portugal Yeah. It happened to me too. As they said they fixed many bugs in 0.5.4. This might be one of them. Most probably related to how Gradle sync work.Restrainer
@Portugal I've found a way to re-use a module in multiple projects. I created (NTFS Junction) folder links using an application called winbolic link for Windows. When I have a module that I depend on in multiple projects, I create a folder link to the to-be-reused project inside the directory of each project in which to use it. After this I add the module dependency (in Andr. Studio). Now I can use/edit the module in each project while keeping is in sync. Not sure if it is the right way to go, but for now it seems to work quite well! This works better than a local maven repo.Kurt
@peterman A little late on the reply here, but I was away for a bit. The most recent versions of Android Studio allow module importing to work rather well and I've been able to create a lib module and add that into my application module.Portugal
A
17

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.

Andino answered 18/11, 2013 at 18:15 Comment(1)
Thank you but doing this will mess up my structure. I don't have just one app which depends on this library and moving library to individual app project root seems inappropriate. I'll wait for a proper solution and keep continuing use of my current IDE. Meanwhile I starred the bug to get the updates about it.Restrainer
A
12

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
Argentite answered 1/5, 2014 at 4:46 Comment(1)
This works with the facebook and parse SDKs in AS 0.6.0. In fact, you can ignore steps 1 and 2... this should work for any module.Wheaten
L
10

I had similar problem. I opened settings.gradle file and add the library include ':Test', ':libraries:MyLibrary', then in build.gradle add the line: compile project(':libraries:MyLibrary'). If you do: Right Click at the project -> Open Module Settings -> your project -> Dependencies, you will see the same dependencies in build.gradle. By the way, after this actions I restarted Android Studio, then IDE created *.iml file.

Licentiate answered 11/11, 2013 at 8:4 Comment(6)
For doing this, you need to have MyLibrary module in your library already. Without that, how can Android Studio supposed to find where your MyLibrary is ?Restrainer
settings.gardle must have include ':libraries:MyLibrary' (<project_directory>/libraries/MyLibrary)Licentiate
This doesn't work for me. The Test can't find the package in the imported library. I guess Injhb is right, we have to create the new module first.Disbar
The *.iml file is not generated after I did as you suggest and restart the IDE.Disbar
I finally solved the problem by creating a new module and add the source code to the module.Disbar
@Disbar you added this as well compile project(':libraries:MyLibrary')??Ammadas
R
2

Finally the import module feature has arrived in Android Studio 0.5.3 which was release on March 27th, 2014.

Take a look here: http://tools.android.com/recent/androidstudio053released

I have also tested and it's there in project structure window.

In Module tab, you can now press the '+' button and either import an existing module or create a new one.

Restrainer answered 28/3, 2014 at 23:42 Comment(14)
I updated to the 0.5.3 somehow the import module is not there. I tried File->Import Module, but it opened another project window.Goosander
@TanJitRen What are you trying to achieve ? Import module lets you import another project into the current one so that you can have dependencies.Restrainer
I wanted to import existing module but my 0.5.3 doesn't include the feature. Look over here, he's facing the same issue too. #22744211Goosander
@TanJitRen I don't think that issue is related to import project settings. It looks like related to incorrectly build gradle project. As I mentioned there, you can try using this manager-plugin by Jake Wharton. github.com/JakeWharton/sdk-manager-pluginRestrainer
I tried with the manager-plugin by Jake Wharton or create a new project and the import module still not available. I'm using classpath 'com.android.tools.build:gradle:0.9.+' classpath 'com.jakewharton.sdkmanager:gradle-plugin:0.9.+'Goosander
@JabbarJigariyo You mention something about the gradle project being build or setup incorrectly, but I don't see what could be wrong with how it is. I'm having the same issue as the link that Tan-jit-ren mentioned. Essentially Import Module performs like the old version of Import Project (opens a new Window) and the Project Structure window doesn't have an Import option, only a New option. Do you have any idea on what the gradle issue might be? I also just tried with a new project, sadly that produced the same result.Portugal
It seems like there might have been a bug in 0.5.3. I just installed 0.5.4 a minute ago and while Project Structure doesn't allow import, one can perform the import via File -> Import Module now and that works! Woo hoo!Portugal
I spoke too soon. You can indeed import a module now, but it seems to make a copy of the entire module rather than linking to a module outside of the project structure. Any changes you make are local to new copy. So, this is only slightly useful really. It is more useful than not having the ability at all, but still pretty useless if you want to have a Library that is in a sep. repo than your App, etc.Portugal
I found an answer to my problem via #17479576 - That might help OP and other users that would like to actually link to a module that is outside of the project structure (different repo, etc).Portugal
@Portugal So it wasn't a problem with 0.5.3 but how the project has been structured. That's what I was trying to say about incorrect setup. I'm glad you found the solution :)Restrainer
@JabbarJigariyo Right, but nothing changed for me between 0.5.3 and 0.5.4 where the Import functionality actually performed an import (though not the way I thought it would). At least I was able to edit the gradle file to do the import as I thought it should happen.Portugal
@Portugal Yeah. It happened to me too. As they said they fixed many bugs in 0.5.4. This might be one of them. Most probably related to how Gradle sync work.Restrainer
@Portugal I've found a way to re-use a module in multiple projects. I created (NTFS Junction) folder links using an application called winbolic link for Windows. When I have a module that I depend on in multiple projects, I create a folder link to the to-be-reused project inside the directory of each project in which to use it. After this I add the module dependency (in Andr. Studio). Now I can use/edit the module in each project while keeping is in sync. Not sure if it is the right way to go, but for now it seems to work quite well! This works better than a local maven repo.Kurt
@peterman A little late on the reply here, but I was away for a bit. The most recent versions of Android Studio allow module importing to work rather well and I've been able to create a lib module and add that into my application module.Portugal
F
0

I had the same problem when using version 0.3.6. Finally I decided to go back to 0.3.2. and now it works. I suppose AS restricts the ability to connect so to say inhomogeneous projects. I have an (Android/Gradle) project0 an a (Java/Maven) project1. When trying to import project1 as a module of project0 I failed, because the only "option" I had was to create a new module. When I tried to import the same module (project1: Java/Maven) for a Java/Gradle project, there was no problem at all.

Maybe the reason is the Android/Gradle or even just Android nature of a project, but I can't for sure verify my assumption right now.

Frankfurter answered 18/11, 2013 at 15:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.