我已经导入了一个项目到Android工作室的几个子项目。
我想运行一个子项目。
我成功地完成了这个子项目的构建。Gradle作为一个模块。
为了运行它,我去运行>编辑配置> + > Android应用程序。
问题:当我尝试选择一个模块时,下拉列表中没有显示。
为什么会这样?
编辑:它在Groovy下显示为一个模块,但在Android应用程序下不显示。我如何让它显示在Android应用程序?
我已经导入了一个项目到Android工作室的几个子项目。
我想运行一个子项目。
我成功地完成了这个子项目的构建。Gradle作为一个模块。
为了运行它,我去运行>编辑配置> + > Android应用程序。
问题:当我尝试选择一个模块时,下拉列表中没有显示。
为什么会这样?
编辑:它在Groovy下显示为一个模块,但在Android应用程序下不显示。我如何让它显示在Android应用程序?
当前回答
我终于弄清楚了为什么当我为com.android.library模块添加AndroidTests配置时,该模块没有显示。
如果在应用程序的构建中包含库模块。这样Gradle:
compile project(':yourlibrary')
因为对于库模块,它默认是用发布模式编译的,你不能为它运行Android测试,这就是为什么它不会显示在模块列表中。 我做了如下修改:
将以下配置添加到构建中。你的库模块的Gradle:
publishNonDefault true
通过进行以下更改,您可以通过编辑构建来调试编译库。Gradle你的应用模块如下:
- compile project(':yourlibrary')
+ debugCompile project(path: ':yourlibrary', configuration: 'debug')
+ releaseCompile project(path: ':yourlibrary', configuration: 'release')
然后同步它,你会发现它显示在列表中。
其他回答
我终于弄清楚了为什么当我为com.android.library模块添加AndroidTests配置时,该模块没有显示。
如果在应用程序的构建中包含库模块。这样Gradle:
compile project(':yourlibrary')
因为对于库模块,它默认是用发布模式编译的,你不能为它运行Android测试,这就是为什么它不会显示在模块列表中。 我做了如下修改:
将以下配置添加到构建中。你的库模块的Gradle:
publishNonDefault true
通过进行以下更改,您可以通过编辑构建来调试编译库。Gradle你的应用模块如下:
- compile project(':yourlibrary')
+ debugCompile project(path: ':yourlibrary', configuration: 'debug')
+ releaseCompile project(path: ':yourlibrary', configuration: 'release')
然后同步它,你会发现它显示在列表中。
这主要发生在复制一个库项目并试图构建它的时候。解决办法是
apply plugin: 'com.android.application'
在构建中。Gradle文件,而不是
apply plugin: 'com.android.library'
然后进行gradle同步
我通过以下方法在Android Studio 1.3.1中修复了这个问题:
Make a new module from File -> New -> New Module Name it something different, e.g. 'My Libary' Copy an .iml file from an existing library module and change the name of the file and rename references in the .iml file Add the module name to settings.gradle Add the module dependency in your app's build.gradle file 'compile project(':mylibrary')' Close and reopen Android Studio Verify that Android Studio recognises the module as a library (should be bold) Rename module's directory and module name by right clicking on the newly created module. Enjoy :)
通过点击“文件->同步项目与Gradle文件”解决了这个问题
我通过在模块设置中添加facet来解决这个问题。他们失踪了。 右键单击项目>打开模块设置> facet >添加facet(顶部的“+”符号)> Android。 添加facet后,您将拥有模块。 更新: 对于最新版本的gradle, facet已经被删除,你现在可以直接添加模块。 右键单击项目>打开模块设置>添加模块(“+”符号在顶部)>手机和平板电脑应用程序(现在你可以创建一个新的模块和配置它)。