我想更改我的项目和模块的名称。但如果我试图重命名他们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'

当前回答

首先,我强烈建议升级到最新的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版本,它可能没有这个按钮,所以你可以关闭项目并在这种情况下重新打开它),它应该会接收到更改。

其他回答

对我有用的是:

转到

setting.gradle

更改其中的名称。 转到你想要更改并重构的应用根文件夹——>重命名它。 关闭android studio。 浏览到文件夹并更改名称 重新启动android studio。 做gradle同步。

这样就完成了!

首先,我强烈建议升级到最新的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版本,它可能没有这个按钮,所以你可以关闭项目并在这种情况下重新打开它),它应该会接收到更改。

这种方法100%有效

只需要做这些简单的步骤:

退出Android Studio 重命名资源管理器中的主项目文件夹 打开Android Studio,打开你的项目 重建和享受。

->修改项目名称<-


通过关闭Android Studio更改项目名称,进入项目文件夹,重命名它…



删除。idea文件夹和。iml文件。(要显示隐藏的文件夹,按Cmd + Shift +。(点))。



打开设置。使用文本编辑器(如VSCode)编辑gradle文件,并将rootProject.name更改为您的新项目名称。



完成了!项目名称已更改!只要用Android Studio打开你的项目,Gradle就会再次同步。

TL; diana:

你可能只关注最后一部分重命名,可能只有图像在里面…: -)


术语:

Android Studio的“项目名称”是不存在的。但它们是在创建新项目时输入的其他名称:

应用程序名称,最初与Gradle的根项目名称相同, 包名, Android Studio项目根文件夹名称。

一般来说,人们想要改变这3个名称,大多数是从Gradle的根项目名称中派生出来的,就像在新建项目对话窗口中建议的那样。

所以我的答案会涵盖这种情况。


分析:

在创建新项目时,我们可能需要遵循与Android Studio相同的步骤。

如果你选择文件→新建→新建项目…(然后是一个项目模板),在新建项目对话框窗口的第一个字段是“名称”字段提供的名称My Application。

2个next字段使用这个(默认的或已更改的)名称派生其他2个字符串的默认名称,例如,有3个重要的字符串

我的应用程序 com.something.myapplication C:\Users\someuser\ AndroidStudioProjects \ MyApplication

此外,

在创建项目之后,还没有构建会使用这3个字符串。


重命名:

因此,在重命名为其他名称期间,我们必须确保4件事-我将使用My改名项目的名称作为新名称的基础。

让我们从最后一个,可能是最简单的一个开始:

Build ->清洁项目

从现在开始,在完全重命名完成之前,请不要进行新的构建。

现在,开始重命名之前指定的3点:

My Application: In the leftmost position of the title bar of the Android Studio Window, you see the same text as I selected in the settings.gradle file: Change this text to the new name (My Renamed Application). The yellowish bar will appear near the top. Click the “Sync Now” in the right-hand part of it:         You will immediately see the change in the title bar: You probably want to change the application name to the same name, too, so change it in the strings.xml resource file (the change will then reflect in the AndroidManifest.xml file, which is important): Before renaming: After renaming:   com.something.myapplication: Change the applicationID in the build.gradle (module level) file - the new name, derived from “My Renamed Application” will be without spaces, all lowercase, i.e. myrenamedapplication: Before changing: After changing: The yellowish bar will appear again near the top. Click the “Sync Now” in the right-hand part of it:           Now close the Android Studio, and rename the folder MyApplication (probably located in the folder C:\Users\someuser\AndroidStudioProjects\) to MyRenamedApplication (the name, derived from “My Renamed Application”, is without spaces). Although this step is optional, it is highly recommended to keep things tidy.

注意:

使用File→Open Recent打开重命名的项目当然会失败,所以在重命名后,第一次使用File→Open打开它。