我想更改我的项目和模块的名称。但如果我试图重命名他们Android工作室通知我一些错误… 例:我想把名字从“MyApplication”改为“AndroidApp”,如下图所示。 在第一个矩形中,我想改变它:

AndroidApp (“G:...\Android\AndroidApp”).

在第二个矩形中,我想改变它:

AndroidApp [AndroidApp-AndroidApp]

编辑:这是日志:

Gradle:项目“AndroidApp”在根项目“MyApplicationProject”中找不到。

build.gradle:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.5.+'
    }
}
apply plugin: 'android'

repositories {
    mavenCentral()
}

android {
    compileSdkVersion 18
    buildToolsVersion "18.0.1"

    defaultConfig {
        minSdkVersion 7
        targetSdkVersion 16
    }
}

dependencies {
    compile 'com.android.support:support-v4:18.0.0'
}

settings.gradle:

include ':MyApplication'

当前回答

它为我工作的方式,以取代我的项目的旧名称为一个新名称(在我的代码库中无处不在)如下:

Close Android Studio. Rename the root folder of your project. Open Android Studio. It will not find the old project, so you must import it again. This step will generate the configuration again (no need to touch your .idea files manually), including a new .iml file with the new project name. Afterwards you can delete the old .iml file if you want. Once the renamed project is imported in Android Studio you need to rename your source packages to use the new project name in case you used the old project name as part of the package path.

注意:这适用于Android Studio 2.1.2

其他回答

更新:这是2013年的过时响应,仅适用于v2.2.2及以下版本。


右键单击根项目目录 选择“重构->重命名” 选择重命名项目并在那里更改名称。 选择重命名模块,并在那里更改它。如果你得到一个消息说模块名称已经改变,那很好。 现在再次右键单击项目根文件夹并选择Open Module Settings。 在Modules部分下,删除与旧项目名称相关联的任何文件夹。 应用设置并点击OK。 重新启动Android Studio。

对我有用的是,

去Build.gradle 更改ApplicationId并同步项目。

右键单击您的项目>重命名>重命名包。

运行你的应用。

希望这对我有用

在2020年11月,解决这个问题的一个非常快速的方法是以下步骤

hit the shift key twice, a pop up will show search for a file named "settings.gradle" when it opens change the rootProject.name = "Old-name" to rootProject.name = "new name" then sync. hit the shift key twice, a pop up will show search for a file named "string.xml", when it opens change <string "app_name">old-name to <string "app_name">new-name close android studio locate androidStudioProject directory on your machine, open it and find the project by its old name, rename it to the new name. open Android Studio goto File > Open > "new name". open it from there.

目前正在Android Studio 4.1.1上运行

您可以轻松地使用refactor重命名。

写,单击项目根文件夹,然后单击重构。 然后点击重命名,会弹出一个窗口,你可以在那里给出新的名字。

首先,我强烈建议升级到最新的Android Studio(目前为0.3.7);有大量的错误修复。

您遇到了bug https://code.google.com/p/android/issues/detail?id=57692,即如果您试图使用UI重命名模块或项目,它不会更新构建文件。对不起,它现在真的坏了。我建议直接在文件系统中更改目录名,并更新您的设置。Gradle文件来反映这些变化。你在磁盘上的项目应该看起来像这样(比这里显示的文件更多):

projectFolder
|--settings.gradle
|--applicationModuleFolder
|  |--build.gradle
|  |--src

它使用projectFolder的名称作为项目名称,并使用applicationModuleFolder作为您的Android应用程序所在的模块名称(分别是屏幕截图中的上方和下方轮廓框)。我认为你现在的项目设置方式,它们都有相同的名称;如果你喜欢,你可以将它们重命名为相同的新名称,或者你可以给它们不同的名称;没关系。

重命名后,编辑您的设置。gradle文件;它看起来像这样:

include ':applicationModuleFolder'

在那里把名字也改成你的新名字。一旦完成这些更改,点击工具栏中的“用Gradle文件同步项目”按钮(如果你运行的是一个非常旧的Android Studio版本,它可能没有这个按钮,所以你可以关闭项目并在这种情况下重新打开它),它应该会接收到更改。