简体   繁体   English

Android Studio 运行/调试配置错误:未指定模块

[英]Android Studio Run/Debug configuration error: Module not specified

I am getting a 'Module not specified' error in my run config.我的运行配置中出现“未指定模块”错误。 I have no module showing in the drop down yet I can see my module no probs.我在下拉列表中没有显示模块,但我可以看到我的模块没有问题。 The issue came about when I refactored my module name, changed the settings.gradle to new name.当我重构我的模块名称,将 settings.gradle 更改为新名称时,问题就出现了。

Now when I go to project structure and select my module nothing shows in the screen, not even an error.现在,当我转到项目结构并选择我的模块时,屏幕上没有任何显示,甚至没有错误。

I'm not 100% sure, but the icon beside my module looks like a folder with a cup and not a folder with a phone.我不是 100% 确定,但我模块旁边的图标看起来像一个带杯子的文件夹,而不是一个带手机的文件夹。

My exact steps -我的确切步骤 -

  1. Open in Android view在 Android 视图中打开
  2. Refactor directory name重构目录名称
  3. refactor module name重构模块名称
  4. change settings.gradle contents: name to new name更改 settings.gradle 内容:名称到新名称

Resync your project gradle files to add the app module through Gradle 重新同步您的项目gradle文件以通过Gradle添加app模块

  1. In the root folder of your project, open the settings.gradle file for editing. 在项目的根文件夹中,打开settings.gradle文件进行编辑。

  2. Remove include ':app' from the file. 从文件中删除include ':app'

  3. On Android Studio, click on the File Menu, and select Sync Project with Gradle files . 在Android Studio上,点击File菜单,然后选择Sync Project with Gradle files

  4. After synchronisation, add include ':app' back to the settings.gradle file. 同步后,将include ':app'添加回settings.gradle文件。

  5. Re-run Sync Project with Gradle files again. 再次Sync Project with Gradle files重新运行Sync Project with Gradle files

没关系,我在settings.gradle中更改了名称并进行了同步,然后又将其改回并再次进行了同步,这一次它莫名其妙地起作用了。

尝试删除项目目录中的app.iml并重新启动android studio

This issue also may happen when you just installed new Android studio and importing some project, in the new Android studio only the latest sdk is downloaded(for example currently the latest is 30) and if your project target sdk is 29 you will not see your module in run configuring dialog.当您刚刚安装新的 Android Studio并导入某个项目时,也可能发生此问题,在新的 Android Studio 中仅下载最新的 sdk(例如当前最新的是 30),如果您的项目target sdk是 29,您将看不到您的modulerun configuring对话框中。

So download the sdk that your app is targeted, then run Sync project with gradle files .因此,下载您的应用程序所针对的 sdk,然后Sync project with gradle files运行Sync project with gradle files

在此处输入图片说明

I realized following line was missing in settings.gradle file 我意识到settings.gradle文件中缺少以下行

include ':app' 包括':app'

make sure you include ":app" module 确保包括“:app”模块

在Android Studio 3.2.1上更新后,我遇到了相同的问题,必须重新导入项目,然后一切正常

I struggled with this because I'm developing a library, and every now and then want to run it as an application. 我为此苦苦挣扎,因为我正在开发一个库,并且时不时地希望将其作为应用程序运行。

From app/build.gradle, check that you have apply plugin: 'com.android.application' instead of apply plugin: 'com.android.library' . 从app / build.gradle中,检查您是否具有apply plugin: 'com.android.application'而不是apply plugin: 'com.android.library'

You should also have this in app/build.gradle: 您还应该在app / build.gradle中拥有此功能:

defaultConfig { applicationId "com.your_company.your_application" ... }

Finally run Gradle sync. 最后运行Gradle sync。

If you can't find your settings.gradle file in your project directory 如果在项目目录中找不到settings.gradle文件

  1. Add settings.gradle file 添加settings.gradle文件

  2. Add include ':app' inside the settings.gradle file 在settings.gradle文件中添加include':app'

  3. Rebuild or sync your project 重建或同步您的项目

Your app module should appear in your configuration file. 您的应用程序模块应显示在您的配置文件中。

check your build.gradle file and make sure that use apply plugin: 'com.android.application' istead of apply plugin: 'com.android.library' 检查您的build.gradle文件,并确保使用Apply apply plugin: 'com.android.application'不是Apply apply plugin: 'com.android.library'

it worked for me 它对我有用

You have 3 ways: 您有3种方法:

  1. Clean Project in Android Studio menu 在Android Studio菜单中清理项目

    Build -> Clean Project and use Build -> Rebuild 构建->清理项目并使用构建->重建


  1. Remove all modal in settings.gradle 删除settings.gradle中的所有模态

    • Open settings.gradle project 打开settings.gradle项目
    • Remove include ':app' and and other modal 删除包括':app'和其他模式
    • Sync gradle 同步gradle
    • Add include ':app' and and other modal 添加包括':app'和其他模式
    • Sync gradle again 再次同步gradle

  1. Remove all code in gradle.properties 删除gradle.properties中的所有代码

    • Open gradle.properties project 打开gradle.properties项目
    • Remove all code 删除所有代码

      org.gradle.daemon=true org.gradle.daemon = true

      org.gradle.configureondemand=true org.gradle.configureondemand = true

      org.gradle.parallel=true org.gradle.parallel = true

      android.enableBuildCache=true android.enableBuildCache = true

    • Sync gradle 同步gradle

    • Add code again 再次添加代码
    • Sync gradle again 再次同步gradle

I would like to add some more information while I was facing this issue:当我遇到这个问题时,我想添加更多信息:

Ref: Answer from @Eli:参考:@Eli 的回答:

  1. Cut line include ' :app ' from the file.剪切线包括文件中的“ :app ”。
  2. On Android Studio, click on the File Menu, and select Sync Project with Gradle files.在 Android Studio 上,单击文件菜单,然后选择将项目与 Gradle 文件同步。
  3. After synchronisation, paste back line include ':app' to the settings.gradle file.同步后,将行 include ':app' 粘贴回 settings.gradle 文件。
  4. Re-run Sync Project with Gradle files again.再次使用 Gradle 文件重新运行同步项目。

So, let's follow the instruction and try to keep one thing in mind, that what is showing in your build configuration.因此,让我们按照说明进行操作,并尝试记住一件事,即构建配置中显示的内容。 Make sure you are seeing the name of your configuration app like the image below:确保您看到的是配置app的名称,如下图所示:

在此处输入图片说明

If you are seeing anything else, then the steps mentioned by @Eli (the most accepted answer) will not work.如果您看到其他任何内容,则@Eli 提到的步骤(最常接受的答案)将不起作用。

An alternative Solution If you have a different name on the Run/Debug Configurations window and the above process is not working, please change the config name to ' app '另一种解决方案如果您在“运行/调试配置”窗口上有不同的名称并且上述过程不起作用,请将配置名称更改为“ app

then -> hit Apply -> then Ok .然后 -> 点击Apply -> 然后Ok

After that follow this:-之后按照这个: -

File -> Sync project with gradle files (if needed).文件-> 将项目与 gradle 文件同步(如果需要)。

Now check the issue will be resolved hopefully.现在检查问题有望得到解决。 I have faced this issue and I think it might help others as well.我遇到过这个问题,我认为它也可能对其他人有所帮助。

I was trying to open an old GitHub project with the latest android studio that's why got this error.我试图用最新的 android studio 打开一个旧的 GitHub 项目,这就是为什么会出现这个错误。 I tried almost all the way that mentions in this post but none of them is work.我几乎尝试了这篇文章中提到的所有方法,但没有一个是有效的。

In my case, I update my Gradle version with my latest project, and the issue resolved.就我而言,我用我的最新项目更新了我的 Gradle 版本,问题解决了。 Use your latest Gradle version to resolve the issue.使用最新的 Gradle 版本来解决问题。

在此处输入图片说明 在此处输入图片说明

Sometimes the project doesn't load your sdk version.有时项目不会加载您的 sdk 版本。 so manually change the this in your build.gradle file module level to your own sdk version所以手动将 build.gradle 文件模块级别中的 this 更改为您自己的 sdk 版本

  1. compileSdkVersion 28 compileSdkVersion 28
  2. buildToolsVersion "28.0.3"构建工具版本“28.0.3”
  3. targetSdkVersion 28目标SDK版本28

now re-sync the your project.现在重新同步您的项目。

我必须选择“使用模块的类路径:”下拉选项,然后选择我的模块。

Remove from app gradle this code 从应用Gradle中删除此代码

android{
    defaultConfig.applicationId="com.storiebox"
}

We are currently recommending AS 3.3 for exercises. 目前,我们建议您使用AS 3.3进行练习。

These settings will work in the current 3.3 beta version with two small changes to your project: 这些设置将在当前的3.3 beta版本中运行,并且对项目进行了两个小的更改:

In build.gradle (Project), change gradle version to 3.3.0-rc02 在build.gradle(项目)中,将Gradle版本更改为3.3.0-rc02

In menu go to File -> Project Structure. 在菜单中,转到文件->项目结构。 There you can change the gradle version to 4.10.0 在那里,您可以将gradle版本更改为4.10.0

None of the existing answers worked in my case (Android studio 3.5.0). 在我的情况下(Android studio 3.5.0),所有现有答案均无效。 I had to 我不得不

  1. close all android studio projects 关闭所有android studio项目
  2. remove the project from the recent projects in android studio wizard 从android studio向导中的最新项目中删除项目
  3. restart android studio 重新启动Android Studio
  4. use import option (Import project- Gradle, Eclipse ADT, etc) instead of open an existing project AS project 使用导入选项 (导入项目-Gradle,Eclipse ADT等),而不是打开现有的项目AS项目
  5. File -> Sync project with gradle files 文件->使用Gradle文件同步项目

Run the app, it will show ' Edit Configuration ' window.运行应用程序,它将显示“ Edit Configuration ”窗口。 Under Module - select the app (it would be <no module> ).Module - 选择应用程序(它将是<no module> )。

Then select the activity (under Launch Options )然后选择活动(在Launch Options

在此处输入图片说明

in my case, when I added Fragment I git this error.就我而言,当我添加 Fragment 时,我会出现此错误。

When I opened THe app build.gradle I saw id("kotlin-android") this plugin in plugins.当我打开应用程序build.gradle我在插件中看到了id("kotlin-android")这个插件。

just remove it!只需删除它!

If all above solution doesn't work then do try this solution, because in my case none of the above solution were working.如果以上所有解决方案都不起作用,请尝试此解决方案,因为在我的情况下,上述解决方案均无效。 I too was facing this problem and after 5 hour of hard work I am able to tell you a solution.我也遇到了这个问题,经过 5 个小时的努力,我可以告诉你一个解决方案。 If you are cloning project using git the I would recommend you to directly clone project using android studio.如果您使用 git 克隆项目,我建议您直接使用 android studio 克隆项目。 It worked for me.它对我有用。

You can clean your project and and invalidate caches / restart.您可以清理项目并使缓存无效/重新启动。 After that your project might be fixed.之后,您的项目可能会得到修复。

This solution works for me.这个解决方案对我有用。

If no solution works then make sure that you opened the project from the right directory如果没有解决方案,请确保您从正确的目录中打开了项目

For example, when I opened the project from app folder and from the root I got例如,当我从app文件夹和根目录打开项目时,我得到了

Module not specified未指定模块

error, but when I opened it from todoapp the error had gone错误,但是当我从todoapp打开它时,错误消失了

例子

Check your minsdkversion, compilesdkversion and targetsdkversion and ensure that you installed all those from Tools -> SDKManager in Android Studio.检查您的 minsdkversion、compilesdkversion 和 targetsdkversion,并确保您从 Android Studio 中的Tools -> SDKManager安装了所有这些。

eg if your targetsdkversion is 30 and minsdkversion is 28, ensure that you installed 28, 29, 30 sdks.例如,如果你的 targetdkversion 是 30 而 minsdkversion 是 28,请确保你安装了 28、29、30 个 sdks。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM