问题
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!!!
回答1:
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.
回答2:
For android studio 0.5.7, volley was successfully imported as a library project following these steps:
- Create a directory named "libraries"(whichever you want) under your project root
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
- 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.
- 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
- Now everything works fine, you can use volley as you want
回答3:
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.
回答4:
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.
回答5:
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.
来源:https://stackoverflow.com/questions/19898456/cant-find-import-module-option-in-project-structure-android-studio-0-3-4-0-5