在项目结构中找不到导入模块选项(Android Studio 0.3.4 - 0.5.2)

时间:2022-12-04 20:50:26

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.

我感到非常困惑和沮丧,因为我不明白如何将我的android库项目作为应用程序项目的依赖项导入。

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'

我试着在网上查找,大部分的答案建议去我的应用程序的项目结构,点击'+'然后点击'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.

但Android Studio 0.3.4 - 0.5.2没有显示任何选项,当我点击“+”时,它只显示了一个新模块的windows。

Am I doing something wrong or what ?

我做错什么了吗?

Help!!!

帮助! ! !

5 个解决方案

#1


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

在使用基于级别的项目时,您将遇到这种情况,就像这个项目一样;即使在0.3.2中,这个导入项目命令也在做错误的事情;它似乎可以工作,并且可以使编辑器中的语法着色正常工作,但是当您尝试构建和运行应用程序时,它将失败,当您将项目与Gradle构建文件重新同步时,您的更改将丢失。这就是为什么在它能够被正确地重新实现之前将其删除。跟踪它的bug是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.

与此同时,要将现有库作为依赖项添加,您需要在渐变构建文件中手动添加。为此,移动库,使其目录位于项目根目录之下(此时,不支持项目根之外的模块),编写一个构建。渐变构建文件,将构建模块,并在设置中包含模块。gradle文件。

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.

如果您查看文件>新模块,您可能会发现它更容易……命令创建一个空白模块,根据需要选择普通Java模块或Android模块,并将库文件复制到需要的模块目录中。这将为您处理渐变文件并设置框架目录结构。

#2


12  

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

对于android studio 0.5.7,按照以下步骤成功导入volley作为库项目:

  1. Create a directory named "libraries"(whichever you want) under your project root
  2. 在项目根目录下创建一个名为“libraries”(无论你想要什么)的目录
  3. 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:

    在第1步创建的目录下,命令是“git克隆https://android.googlesource.com/platform/frameworks/volley”。项目结构如下:

    [Project root]
    |- [Your module]
    |- libraries
       |- volley
    
  4. 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.
  5. 导入截击:右击项目根->打开模块设置->在左上角点击“+”(新模块)->导入现有项目->选择截击源目录->在第三步之后,截击被导入,但对库项目截击的依赖尚未建立。
  6. 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
  7. 设置模块依赖项:右键点击项目根->打开模块设置(现在volley应该出现在模块列表中)->选择[您的模块]->切换到tab“依赖项”->点击左下角的“+”(添加)->选择“模块依赖项”->选择“:volley”模块列表对话框
  8. Now everything works fine, you can use volley as you want
  9. 现在一切都很好,你可以随意使用截击

#3


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.

我也有类似的问题。我打开设置。渐变文件和添加库包括':Test', ':libraries:MyLibrary',然后在build中。gradle添加行:编译项目(‘:libraries:MyLibrary’)。如果您这样做:在项目->打开模块设置->您的项目->依赖项,您将在build.gradle中看到相同的依赖项。顺便说一下,在这些操作之后,我重新启动了Android Studio,然后创建了IDE *。安恩科技文件。

#4


2  

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

最后导入模块的功能已经在2014年3月27日发布的Android Studio 0.5.3中。

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

看看这里:http://tools.android.com/recent/androidstudio053release

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.

在Module选项卡中,您现在可以单击“+”按钮,导入现有模块或创建一个新的模块。

#5


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.

在使用0.3.6版本时,我遇到了同样的问题。最后我决定回到0。3.2。现在它的工作原理。我认为是限制连接的能力,比如非齐次的项目。我有一个(Android/Gradle)项目a (Java/Maven)项目1。当我试图将project1作为project0的模块导入时,我失败了,因为我唯一的“选项”是创建一个新的模块。当我尝试为Java/Gradle项目导入相同的模块(project1: Java/Maven)时,根本没有问题。

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.

也许原因是Android/Gradle甚至是一个项目的Android特性,但是我现在还不能确定我的假设是否正确。

#1


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

在使用基于级别的项目时,您将遇到这种情况,就像这个项目一样;即使在0.3.2中,这个导入项目命令也在做错误的事情;它似乎可以工作,并且可以使编辑器中的语法着色正常工作,但是当您尝试构建和运行应用程序时,它将失败,当您将项目与Gradle构建文件重新同步时,您的更改将丢失。这就是为什么在它能够被正确地重新实现之前将其删除。跟踪它的bug是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.

与此同时,要将现有库作为依赖项添加,您需要在渐变构建文件中手动添加。为此,移动库,使其目录位于项目根目录之下(此时,不支持项目根之外的模块),编写一个构建。渐变构建文件,将构建模块,并在设置中包含模块。gradle文件。

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.

如果您查看文件>新模块,您可能会发现它更容易……命令创建一个空白模块,根据需要选择普通Java模块或Android模块,并将库文件复制到需要的模块目录中。这将为您处理渐变文件并设置框架目录结构。

#2


12  

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

对于android studio 0.5.7,按照以下步骤成功导入volley作为库项目:

  1. Create a directory named "libraries"(whichever you want) under your project root
  2. 在项目根目录下创建一个名为“libraries”(无论你想要什么)的目录
  3. 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:

    在第1步创建的目录下,命令是“git克隆https://android.googlesource.com/platform/frameworks/volley”。项目结构如下:

    [Project root]
    |- [Your module]
    |- libraries
       |- volley
    
  4. 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.
  5. 导入截击:右击项目根->打开模块设置->在左上角点击“+”(新模块)->导入现有项目->选择截击源目录->在第三步之后,截击被导入,但对库项目截击的依赖尚未建立。
  6. 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
  7. 设置模块依赖项:右键点击项目根->打开模块设置(现在volley应该出现在模块列表中)->选择[您的模块]->切换到tab“依赖项”->点击左下角的“+”(添加)->选择“模块依赖项”->选择“:volley”模块列表对话框
  8. Now everything works fine, you can use volley as you want
  9. 现在一切都很好,你可以随意使用截击

#3


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.

我也有类似的问题。我打开设置。渐变文件和添加库包括':Test', ':libraries:MyLibrary',然后在build中。gradle添加行:编译项目(‘:libraries:MyLibrary’)。如果您这样做:在项目->打开模块设置->您的项目->依赖项,您将在build.gradle中看到相同的依赖项。顺便说一下,在这些操作之后,我重新启动了Android Studio,然后创建了IDE *。安恩科技文件。

#4


2  

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

最后导入模块的功能已经在2014年3月27日发布的Android Studio 0.5.3中。

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

看看这里:http://tools.android.com/recent/androidstudio053release

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.

在Module选项卡中,您现在可以单击“+”按钮,导入现有模块或创建一个新的模块。

#5


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.

在使用0.3.6版本时,我遇到了同样的问题。最后我决定回到0。3.2。现在它的工作原理。我认为是限制连接的能力,比如非齐次的项目。我有一个(Android/Gradle)项目a (Java/Maven)项目1。当我试图将project1作为project0的模块导入时,我失败了,因为我唯一的“选项”是创建一个新的模块。当我尝试为Java/Gradle项目导入相同的模块(project1: Java/Maven)时,根本没有问题。

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.

也许原因是Android/Gradle甚至是一个项目的Android特性,但是我现在还不能确定我的假设是否正确。