我想更改我的项目和模块的名称。但如果我试图重命名他们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 2.3中使用了以下指示(第一次)。它们包括在Android Studio中创建一个新应用,然后关闭它,在文件资源管理器和文本编辑器中完成所有工作。

重构和重命名一个Android Studio项目或应用程序

注意:需要一个文本编辑器,它可以在目录结构中执行全局搜索和替换。说明书上推荐了Sublime Text,我很容易安装和运行。

它生成了一个新的应用程序,安装和运行在现有的应用程序旁边。它仍然有相同的屏幕名,这是通过在清单中编辑Android:label="MyNewApp"来修复的。

其他回答

用Alt+1进入[工具窗口\项目],改变这个窗口左上角的级别为项目(另外两个是Packages和Android),然后你可以用Shift+F6重命名项目名称。输入新名称并按OK。

如果你只是想改变系统中出现的应用程序名称,你可以修改manifest.xml中的android:title。

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

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

只需在build.gradle中更改应用程序id

applicationId "yourpackageName"

更改应用程序标签,在manifest中

<application 
android:label="@string/app_name" 
... />

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打开它。

以下是我在Android Studio Beta(0.8.14)中所做的事情

Changed the package name manually in the manifest file Navigated to build -> source -> r -> release and drilled down until I found R.java Selected the file and pressed F6 to rename Then from the Build menu selected Make Project Clicked the first error and pressed Shift+F6 on the package name and renamed which updated all my source files Selected my project name in Android Studio, right clicked -> Refactor -> Rename and changed the name there too. Next went to app -> build.gradle and updated my applicationId Navigate to .idea -> .name file and rename your Android Studio project in there too Just to clean up I deleted the old package folder inside build -> source -> r -> release

和vola,我的包名称现在已经更改并成功构建。