简体   繁体   English

在 Android Studio 上更改项目名称

[英]Change project name on Android Studio

I want to change the name of my project and module.我想更改我的项目和模块的名称。 But if I try to rename them Android Studio notify me some errors...但是如果我尝试重命名它们 Android Studio 会通知我一些错误......

eg I want to change the name from "MyApplication" to "AndroidApp" as shown in the image below.例如,我想将名称从“MyApplication”更改为“AndroidApp”,如下图所示。
在此处输入图像描述
In the first rectangle I want to change it in:在第一个矩形中,我想将其更改为:

AndroidApp ("G:...\Android\AndroidApp). AndroidApp ("G:...\Android\AndroidApp)。

In the second rectangle I want to change it in:在第二个矩形中,我想将其更改为:

AndroidApp [AndroidApp-AndroidApp] AndroidApp [AndroidApp-AndroidApp]

edit: This is the log:编辑:这是日志:

Gradle: Project 'AndroidApp' not found in root project 'MyApplicationProject'. Gradle:在根项目“MyApplicationProject”中找不到项目“AndroidApp”。

build.gradle: 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:设置。gradle:

include ':MyApplication'

This did the trick for me:这对我有用:

  • Close Android Studio关闭 Android Studio
  • Rename project root directory name重命名项目根目录名称
  • Open Android Studio打开安卓工作室
  • Open the project打开项目
  • Clean project清洁项目

If your settings.gradle contains the below line, either delete it or update it to the new name.如果您的settings.gradle包含以下行,请将其删除或更新为新名称。

rootProject.name = 'Your project name'

Edit:编辑:
Working in all versions!在所有版本中工作! Last test: Android Studio Chimpmunk Jun 2022 .最后一次测试: Android Studio Chimpmunk Jun 2022

您可以更改文件“.idea/.name”中标题栏中显示的名称。

Update: This is an out-dated response from 2013 and only works for v2.2.2 and below.更新:这是 2013 年的过时响应,仅适用于 v2.2.2 及以下版本。


  1. Right-click on your root project directory右键单击您的根项目目录

  2. Select Refactor -> Rename选择重构 -> 重命名

  3. Select rename project and change the name there.选择重命名项目并在那里更改名称。

  4. Also Select rename module and change it there as well.还选择重命名模块并在那里进行更改。 If you get an message saying module name already changed thats fine.如果您收到一条消息说模块名称已更改,那很好。

  5. Now right-click on the project root folder again and select Open Module Settings.现在再次右键单击项目根文件夹并选择打开模块设置。

  6. Under the Modules section remove whatever folders are associated to your old project name.在 Modules 部分下,删除与旧项目名称关联的所有文件夹。

  7. Apply Settings and hit OK.应用设置并点击确定。

  8. Restart Android Studio.重启安卓工作室。

Hope that helps!希望有帮助!

update July/2017: tested and worked 2017 年 7 月更新:测试和工作


  1. Open project folder (you could open it through Android Studio itself see this )打开项目文件夹(您可以通过 Android Studio 本身打开它,请参阅
  2. now close Android Studio现在关闭 Android Studio
  3. change the yourOldProjectName.iml to the a new name将 yourOldProjectName.iml 更改为新名称
  4. rename the parent folder to the same new name.将父文件夹重命名为相同的新名称。
  5. re-open Android Studio --> File --> Open--> path to your renamed.im重新打开 Android Studio --> 文件 --> 打开 --> 重命名.im 的路径

->Change the Project Name<- ->更改项目名称<-


Change the name of your project by closing the Android Studio, go to your project folder, rename it…通过关闭 Android Studio 更改您的项目名称,转到您的项目文件夹,重命名它......


在此处输入图像描述


Delete the .idea folder and .iml file.删除.idea文件夹和.iml文件。 (To show hidden folders, press Cmd + Shift + . (dot) ) . (要显示隐藏文件夹,请按Cmd + Shift + .(点))


在此处输入图像描述


Open the settings.gradle file with a text editor, like VSCode, and change the rootProject.name to your new project name.使用文本编辑器(如 VSCode)打开settings.gradle文件,并将rootProject.name更改为您的新项目名称。


在此处输入图像描述


Done!完毕! The project name has been changed!项目名称已更改! Just open your project with the Android Studio and Gradle will sync again.只需使用Android Studio打开您的项目, Gradle就会再次同步

UPDATE :更新

This answer is better.这个答案更好。

OLD ANSWER : 1. Right click your旧答案:1.右键单击您的

ackage name and Refactor -> Rename... ackage 名称和Refactor -> Rename...

在此处输入图像描述

  1. When asked if you want to Rename directory or Rename package , choose Rename package当询问您是否要Rename directoryRename package时,请选择Rename package

在此处输入图像描述

  1. Now in Finder, manually rename your root folder (the parent folder of your /app folder)现在在 Finder 中,手动重命名根文件夹(/app 文件夹的父文件夹)

在此处输入图像描述

  1. Reopen project in Android Studio with new folder name使用新文件夹名称在 Android Studio 中重新打开项目

  2. Cmd + Shift + f for any instances of your old name in Android Studio, and change all of them to the new name. Cmd + Shift + f用于 Android Studio 中旧名称的任何实例,并将它们全部更改为新名称。

  3. Change the applicationId in your build.gradle更改build.gradle中的applicationId

BONUS ROUND:奖金回合:

  • You might need to update a .gitignore file if it was at the root of your project.如果.gitignore文件位于项目的根目录,您可能需要更新它。 Note that when swapping branches after doing this, you'll potentially see a bunch of files showing up in working changes, but don't worry they should go away after you merge in your renamed branch with updated .gitignore .请注意,在执行此操作后交换分支时,您可能会看到一堆文件显示在工作更改中,但不要担心在您将重命名的分支与更新的.gitignore合并后它们会消失。 Don't manually remove these as it can cause issues in Android Studio.不要手动删除这些,因为它可能会导致 Android Studio 出现问题。
  • Delete your old root folder in Finder在 Finder 中删除旧的根文件夹

Just find the name " android:label="AppName" " from the Android Manifest .只需从 Android Manifest 中找到名称“ android:label="AppName" ”。 Just rename the label name (eg: "AppName" here) all such android:label in the AndroidManifest.xml .只需在 AndroidManifest.xml 中重命名所有此类 android:label 的标签名称(例如:“AppName”)。 Just save it !只要保存它! When you run the app you will see the new Name运行应用程序时,您将看到新名称

Just go to res>values>strings.xml.只需转到 res>values>strings.xml。 One line says Somethig-your name一行写着Somethig-你的名字

<string name="app_name">Somethig-your name</string>

Just replace your original name to只需将您的原始名称替换为

 <string name="app_name">Your Name</string>
  1. Close Android Studio.关闭安卓工作室。

  2. Rename the folder of the root of the project.重命名项目根目录的文件夹。 For example, change "MyApplication" to "Myblablabla".例如,将“MyApplication”更改为“Myblablabla”。

  3. Delete the '.idea' folder.删除“.idea”文件夹。

  4. Open Android Studio, and import the updated project.打开 Android Studio,并导入更新后的项目。

What worked for me is:对我有用的是:

GoTo

setting.gradle
  1. change the name in it.更改其中的名称。
  2. go to the app root folder which you want to change and refactor--> rename it.转到您要更改和重构的应用程序根文件夹 - >重命名它。
  3. close the android studio.关闭安卓工作室。
  4. browse to the folder and change the name浏览到文件夹并更改名称
  5. start android studio again.再次启动android studio。
  6. do the gradle sync.做gradle同步。

And you are done!你完成了!

1.Edit settings.gradle file, change rootProject.name 1.编辑settings.gradle文件,修改rootProject.name

rootProject.name = "FirebaseDemo"
include ':app'

2.Go to the project file folder, rename the file folder 2.进入项目文件夹,重命名文件夹

3.Delete .idea folder in your project and rebuild the project 3.删除项目中的.idea文件夹并重建项目

For one, I'd strongly suggest updating to the latest Android Studio (0.3.7 as of now);一方面,我强烈建议更新到最新的 Android Studio(截至目前为 0.3.7); there are tons of bug fixes.有大量的错误修复。

You're running into bug https://code.google.com/p/android/issues/detail?id=57692 , which is that if you try to use the UI to rename modules or your project, it doesn't update the build files.您遇到了错误https://code.google.com/p/android/issues/detail?id=57692 ,即如果您尝试使用 UI 重命名模块或项目,它不会更新构建文件。 Sorry, it's really broken right now.对不起,现在真的坏了。 I'd suggest changing the directory names directly in the filesystem, and updating your settings.gradle file to reflect the changes.我建议直接在文件系统中更改目录名称,并更新您的settings.gradle文件以反映更改。 Your project on disk should look something like this (with many more files than what's shown here):您在磁盘上的项目应该看起来像这样(文件比这里显示的要多):

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

it uses projectFolder's name as the project name and applicationModuleFolder as the name of the module that your Android App lives in (the upper and lower outlined boxes in your screenshot, respectively).它使用 projectFolder 的名称作为项目名称和 applicationModuleFolder 作为您的 Android 应用程序所在的模块的名称(分别在屏幕截图中的上框和下框)。 I think the way your project is set up now, they both have the same name;我认为您现在的项目设置方式,它们都具有相同的名称; you can rename both to the same new name if you like, or you can give them different names;如果愿意,您可以将两者重命名为相同的新名称,也可以给它们起不同的名称; it doesn't matter.没关系。

Once they're renamed, edit your settings.gradle file;重命名后,编辑您的settings.gradle文件; it will look something like:它看起来像:

include ':applicationModuleFolder'

just change the name to your new name there as well.只需将名称更改为您的新名称。 Once these changes are made, click the Sync Project with Gradle Files button in the toolbar (if you're running a very old version of Android Studio, it may not have that button, so you can close the project and reopen it in that case) and it should pick up the changes.完成这些更改后,单击工具栏中的Sync Project with Gradle Files按钮(如果您运行的是非常旧版本的 Android Studio,它可能没有该按钮,因此您可以关闭项目并在这种情况下重新打开它) 并且它应该接受更改。

A very quick way to solve this as at November 2020 is by the following steps截至 2020 年 11 月,解决此问题的一种非常快速的方法是通过以下步骤

  1. 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.按两次 shift 键,弹出窗口将显示搜索名为“settings.gradle”的文件,打开时将 rootProject.name =“Old-name”更改为 rootProject.name =“new name”,然后同步。

  2. 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按两次 shift 键,弹出窗口将显示搜索名为“string.xml”的文件,当它打开时将 <string "app_name">old-name 更改为 <string "app_name">new-name

  3. close android studio关闭安卓工作室

  4. locate androidStudioProject directory on your machine, open it and find the project by its old name, rename it to the new name.在您的机器上找到 androidStudioProject 目录,打开它并按旧名称找到项目,将其重命名为新名称。

  5. open Android Studio goto File > Open > "new name".打开 Android Studio 转到文件 > 打开 > “新名称”。 open it from there.从那里打开它。

this is currently working on Android Studio 4.1.1这目前适用于 Android Studio 4.1.1

You can try something like this in your settings.gradle file:你可以在你的settings.gradle文件中尝试这样的事情:

rootProject.name = "YOUR_PROJECT_NAME"

After restarting of Android Studio it will also change text in title bar to YOUR_PROJECT_NAME .重新启动 Android Studio 后,它还会将标题栏中的文本更改为YOUR_PROJECT_NAME

Tested on Android Studio 2.2 RC2在 Android Studio 2.2 RC2 上测试

Just change the application id in build.gradle只需更改 build.gradle 中的应用程序 ID

applicationId "yourpackageName"

For changing application label, in manifest用于更改应用程序标签,在清单中

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

Video tutorial: https://youtu.be/7aQjiae2doU视频教程: https ://youtu.be/7aQjiae2doU

  1. Refactor the name to com.example.[NewFileName] in path:将名称重构为路径中的com.example.[NewFileName]

    app>java>com.example.[OldFileName]应用>java>com.example.[OldFileName]


  1. Go to strings.xml and change code to <string name="app_name”>[NewFileName]</string> in path:转到 strings.xml 并将代码更改为<string name="app_name”>[NewFileName]</string>在路径中:

    app>res>values>strings.xml应用>资源>值>strings.xml


  1. Go to build.gradle (Module: app) and change code to applicationId "com.example.[NewFileName]” in path:转到 build.gradle (Module: app) 并将路径中的代码更改为applicationId "com.example.[NewFileName]”

    Gradle Scripts>build.gradle (Module: app) Gradle Scripts>build.gradle(模块:app)


  1. Go to settings.gradle (Project Settings) and change code to rootProject.name='[NewFileName]' in path:转到 settings.gradle(项目设置)并将代码更改为rootProject.name='[NewFileName]'在路径中:

    Gradle Scripts>build.gradle (Project Settings) Gradle Scripts>build.gradle(项目设置)


  1. Press Sync now prompt按立即Sync now提示

  1. Rename your folder to [NewFileName] outside Android Studio将您的文件夹重命名为 Android Studio 外部的[NewFileName]

  1. Reopen your project and rebuild project in path:重新打开您的项目并在路径中重建项目:

    Build>Rebuild Project构建>重建项目


Go to [ Tool Window \ Project ] by Alt + 1 , and change the level on the top-left corner of this window to Project (the other two are Packages and Android), then you can rename the Project name by Shift + F6 . Alt + 1进入[ Tool Window \ Project ],将该窗口左上角的层级更改为Project(另外两个是Packages和Android),然后您可以通过Shift + F6重命名Project名称。 Type in the new name and press OK.输入新名称,然后按 OK。

If you just want to change the app name which appears in the system, you can modify the android:title in the manifest.xml .如果您只是想更改系统中出现的应用名称,您可以修改manifest.xml中的android:title

You can easily rename using refactor.您可以使用重构轻松重命名。

  1. Write click on the project root folder and click refactor.写入单击项目根文件夹,然后单击重构。

  2. Then click on the rename, there will be a popup, you can give new name there.然后点击重命名,会有一个弹出窗口,你可以在那里给新的名字。

What works for me is,对我有用的是,

Go To Build.gradle Change ApplicationId & sync project.转到 Build.gradle 更改 ApplicationId 并同步项目。

Right click on your project > Rename > Rename Package.右键单击您的项目 > 重命名 > 重命名包。

Run your app and boom.运行您的应用程序并繁荣。

Hope this works as did for me希望这对我有用

To change the apps name in Android Studio:要在 Android Studio 中更改应用名称:

  1. Close the project in Android studio and get rid of it from the quick start side of the launcher ( Should be a mini next to the name).在 Android Studio 中关闭项目,然后从启动器的快速启动端将其删除(名称旁边应该是一个 mini)。

  2. Close Android Studio.关闭安卓工作室。

  3. Go into where your app file is located and rename it (Under My Documents Usually).进入您的应用程序文件所在的位置并重命名它(通常在我的文档下)。

  4. Restart Android Studio, select add new project and navigate to the folder that was renamed.重新启动 Android Studio,选择添加新项目并导航到重命名的文件夹。

Changing the label of the launcher of the application / The applications actual name:更改应用程序启动器的标签/应用程序实际名称:

  1. Go into your initial folder (app)进入您的初始文件夹(应用程序)
  2. Go into manifests进入清单
  3. Go into AndroidManifest.xml.进入 AndroidManifest.xml。
  4. Rename android:label= _____ to whatever you want to rename your app to将 android:label= _____ 重命名为您想要将应用重命名为的任何名称

Eg: android:label="Developer Portal".例如:android:label="开发者门户"。

  1. Click Save All.单击全部保存。

For me the following works:对我来说,以下作品:

  1. Close Android Studio.关闭安卓工作室。
  2. Rename the folder of the project from MyApplication to NewProjectName将项目的文件夹从 MyApplication 重命名为 NewProjectName
  3. Rename MyApplication.iml file to NewProjectName.iml将 MyApplication.iml 文件重命名为 NewProjectName.iml
  4. in NewProjectName.iml change every MyApplication text to NewProjectName在 NewProjectName.iml 中将每个 MyApplication 文本更改为 NewProjectName
  5. in .idea/modules.xml change every MyApplication text to NewProjectName在 .idea/modules.xml 中将每个 MyApplication 文本更改为 NewProjectName
  6. in .idea/workspace.xml change every MyApplication text to NewProjectName在 .idea/workspace.xml 将每个 MyApplication 文本更改为 NewProjectName
  7. Start Android Studio.启动 Android Studio。
  8. All the previous settings remain, and "app" module as well!之前的所有设置都保留了,“app”模块也保留了!

Here's what I did in Android Studio Beta (0.8.14)这是我在 Android Studio Beta (0.8.14) 中所做的

  1. Changed the package name manually in the manifest file在清单文件中手动更改包名称
  2. Navigated to build -> source -> r -> release and drilled down until I found R.java导航到 build -> source -> r -> release 并向下钻取,直到找到 R.java
  3. Selected the file and pressed F6 to rename选择文件并按 F6 重命名
  4. Then from the Build menu selected Make Project然后从 Build 菜单中选择 Make Project
  5. Clicked the first error and pressed Shift+F6 on the package name and renamed which updated all my source files单击第一个错误并在包名称上按 Shift+F6 并重命名它更新了我的所有源文件
  6. Selected my project name in Android Studio, right clicked -> Refactor -> Rename and changed the name there too.在 Android Studio 中选择我的项目名称,右键单击 -> 重构 -> 重命名并在那里更改名称。
  7. Next went to app -> build.gradle and updated my applicationId接下来转到 app -> build.gradle 并更新了我的 applicationId
  8. Navigate to .idea -> .name file and rename your Android Studio project in there too导航到 .idea -> .name 文件并在其中重命名您的 Android Studio 项目
  9. Just to clean up I deleted the old package folder inside build -> source -> r -> release只是为了清理我删除了 build -> source -> r -> release 中的旧包文件夹

And vola, my package name has now changed and builds successfully.和 vola,我的包名现在已经更改并成功构建。

changing following thing worked for me.改变以下事情对我有用。 settings.gradle-> rootProject.name='MyEvinApp' change rootProject.name will take android studio as project name settings.gradle-> rootProject.name='MyEvinApp'更改rootProject.name将 android studio 作为项目名称

Try to change android:label in AndroidManifest.xml and reinstall/rerun app:尝试更改AndroidManifest.xml中的android:label并重新安装/重新运行应用程序:

<application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">

Here is how it all changes in seconds... in your "manifest.xml" find "android:label=" in front of it just type your new name inside "" for example: android:label="My new name"以下是它在几秒钟内发生的变化......在你的“manifest.xml”中找到“android:label=”,只需在“”中输入你的新名称,例如:android:label="My new name"

Its done!完成! your welcome ;)别客气 ;)

I just went into the manifest and changed android:label="...." to the name of the application.我刚刚进入清单并将 android:label="...." 更改为应用程序的名称。 Once Id changed this, the title and the actual app name changed to that :)一旦 Id 改变了这个,标题和实际的应用程序名称就改变了 :)

Hello RobertoAV96 ,你好罗伯托AV96

I have provided three solutions here.我在这里提供了三个解决方案。 Choose whichever applies to your problem.选择适用于您的问题的那个。

If you want to just change the name of the project root folder name, you can do it from the explorer:如果您只想更改项目根文件夹名称的名称,可以从资源管理器中进行:

  1. Just close the project in the studio, after copying path to the project.将路径复制到项目,只需在工作室中关闭项目。 Close the project from the main welcome screen .从主欢迎屏幕关闭项目。
  2. go to the file explorer , copy this path on the address bar, and go to the folder.转到文件资源管理器,在地址栏上复制此路径,然后转到文件夹。
  3. Rename the folder that is the root of the project .重命名作为项目根目录的文件夹。
  4. Rename the iml file in this root folder to the name of the folder.将此根文件夹中的iml文件重命名为该文件夹的名称。 That is if the project root folder's name was say demo_project , there will be demo_project.iml file inside it.也就是说,如果项目根文件夹的名称是demo_project ,那么里面会有demo_project.iml文件。 If you changed this folder's name to say my_project , then you have to change the name of the iml file inside it to my_project.iml .如果您将此文件夹的名称更改为my_project ,那么您必须将其中的iml文件的名称更改为my_project.iml

Actually the refactor option from the Studio can do the same.实际上,来自Studiorefactor选项也可以做到这一点。

If you want to change the app folder's name, that is inside the root folder of the project, do the same in the explorer:如果要更改项目root folder内的app文件夹名称,请在资源管理器中执行相同操作:

  1. Rename the app folder to the name you like to have.app文件夹重命名为您喜欢的名称。

[ INFO: The APK file, that is generated for this project, will acquire the same first name followed by the suffix that represents the mode you build the signed APK for, that is either debug or release . [信息:为此项目生成的APK文件将获取相同的名字,后跟代表您构建签名APK的模式的后缀,即debugrelease Signed APK is found in it's respective folder of debug or release .签名的APK位于其各自的debugrelease文件夹中。 The unsigned APK is located in output folder of build directory, all build , debug and release folders are found in the primary app folder, or the folder you have renamed this folder to].未签名的 APK 位于build目录的output文件夹中,所有builddebugrelease文件夹都位于app文件夹中,或者您将此文件夹重命名为的文件夹]。

  1. Suppose the name that you have given to this folder is my_project_app , open the folder and rename the app.iml , to my_project_app.iml after the name of the project.假设您为此文件夹指定的名称是my_project_app ,打开文件夹并将app.iml重命名为项目名称后的my_project_app.iml
  2. Now go to the project's root folder , and find the settings.gradle file.现在转到项目的根文件夹,找到settings.gradle文件。

The content of this file are the names of module folders that you include in the project, currently there is only one module, that is the main one :该文件的内容是您在项目中包含的模块文件夹的名称,目前只有一个模块,即主模块:

include ':app'

This is corresponding to the old name of the app folder.这对应于app文件夹的旧名称。

Hence you have to make the changes:因此,您必须进行更改:

include ':my_project_app'

That's it.而已。 Now you can reload the project in the studio , and check the name of the APK that is generated.现在您可以在studio中重新加载项目,并检查生成的APK的名称。

If you want to rename the package name, say com.first.myproject to com.alpha.myproject :如果要重命名包名称, com.first.myproject改为com.alpha.myproject

  1. Again go to the explorer: Inside the hierarchy of folders in the src-->main-->java , your package is com-->first-->myproject .再次转到资源管理器:在src-->main-->java的文件夹层次结构中,您的包是com-->first-->myproject Make sure your Studio is closed.确保您的Studio已关闭。
  2. Rename the second folder first to alpha . first将第二个文件夹重命名为alpha
  3. Open the Studio now.现在打开Studio Choose Replace in Path in the first package inside the java folder, in the Android mode of the left panel tree .左侧面板树Android模式下,选择java文件夹内第一个包中的Replace in Path This one is the package that you changed from the Explorer , that is: com.alpha.myproject instead of com.first.myproject .这个是您从Explorer更改的包,即: com.alpha.myproject而不是com.first.myproject Change the instances of the string import com.first.myproject;更改字符串import com.first.myproject; in files to import com.alpha.myproject;在文件中import com.alpha.myproject; . . Check for just the string occurrence of com.first.myproject , and safely change it to com.alpha.myproject .只检查com.first.myproject的字符串出现,然后安全地将其更改为com.alpha.myproject
  4. Check for just the string occurrence of com.first.myproject , in build.gradle inside your main app module , and safely change it to com.alpha.myproject .app模块内的com.first.myproject中检查build.gradle的字符串出现,并安全地将其更改为com.alpha.myproject
  5. Do not forget that this package name is also the signature and identity to your application project.不要忘记这个包名也是你的应用程序项目的签名身份 If you have already published your application in the play store, then you have to setup a different project com.alpha.myproject afresh and unpublish com.first.myproject , affecting lots of users:- you have to broadcast to the users using push notification, in the latest version of old existing APK , that the new Application version will be released with different name, and you have to publish this new APK , restarting from version name 1.0 .如果您已经在 Play 商店中发布了您的应用程序,那么您必须重新设置一个不同的项目com.alpha.myproject并取消发布com.first.myproject ,这会影响很多用户:- 您必须使用推送通知向用户广播,在旧的现有APK最新版本中,新的应用程序版本将以不同的名称发布,您必须发布这个新的APK ,从版本名称1.0重新开始。 This destroys objective of having the application slot at play-store for the old APK .这破坏了在旧APK的 play-store 中拥有应用程序插槽的目标。 So you have to consult your client that what should be the name of their application package before starting the project.因此,在开始项目之前,您必须咨询您的客户,他们的应用程序包的名称应该是什么。
  6. Don't forget that the signing and obfuscation of the application is equally important.不要忘记应用程序的签名和混淆同样重要。 You can issue command inside Studio to remove unnecessary resources from your project.可以Studio中发出命令以从项目中删除不必要的资源。 You can manually deal with all the warnings that LINT produces.可以手动处理LINT产生的所有warnings

Happy coding and Happy app publishing.快乐的编码和快乐的应用发布。 :-) :-)

The way it worked for me in order to replace the old name of my project for a new one (everywhere in my codebase) is the following:为了将我的项目的旧名称替换为新名称(在我的代码库中的任何地方),它对我的​​工作方式如下:

  1. Close Android Studio.关闭安卓工作室。
  2. Rename the root folder of your project.重命名项目的根文件夹。
  3. 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.此步骤将再次生成配置(无需手动触摸您的 .idea 文件),包括具有新项目名称的新 .iml 文件。 Afterwards you can delete the old .iml file if you want.之后,您可以根据需要删除旧的 .iml 文件。
  4. 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 后,您需要重命名源包以使用新的项目名称,以防您将旧项目名称用作包路径的一部分。

NOTE: This worked for Android Studio 2.1.2注意:这适用于 Android Studio 2.1.2

关闭 android studio 并在文件资源管理器中重命名 .iml 文件即可

  • Changing the name in res>values>strings.xml will change the app name that is shown in the apps menu after installation更改 res>values>strings.xml 中的名称将更改安装后应用程序菜单中显示的应用程序名称

  • Renaming the android studio project folder (when android studio is closed) will likely satisfy many developers重命名 android studio 项目文件夹(当 android studio 关闭时)可能会让很多开发者满意

These instructions below worked (first time) for me in Android Studio 2.3.下面的这些说明(第一次)在 Android Studio 2.3 中对我有用。 They involve creating a new app in Android Studio, then closing it and doing all the work in a file explorer and a text editor.它们涉及在 Android Studio 中创建一个新应用,然后关闭它并在文件浏览器和文本编辑器中完成所有工作。

Refactor and Rename a Android Studio Project or App 重构和重命名 Android Studio 项目或应用程序

Note: Requires a text editor which can do a global search-and-replace in a directory structure.注意:需要一个可以在目录结构中进行全局搜索和替换的文本编辑器。 The instructions propose Sublime Text , which I easily installed and ran.说明提出了Sublime Text ,我很容易安装并运行它。

It produced a new app which installed and ran beside the existing app.它生成了一个新应用程序,该应用程序在现有应用程序旁边安装并运行。 It still had the same screen name, which was fixed by editing Android:label="MyNewApp" in the manifest.它仍然具有相同的屏幕名称,这是通过在清单中编辑Android:label="MyNewApp"的。

  1. first go to the values folder首先转到值文件夹
  2. then go to the String Folder然后转到字符串文件夹
  3. find the app_name找到 app_name
  4. Change the name of the application in string Tag在字符串标签中更改应用程序的名称
  5. Finished完成的

it will work fine for me它对我来说很好用

Change Following.

Step 1: Make sure ApplicationId And PackageName will Same.第 1 步:确保 ApplicationId 和 PackageName 相同。 example :例子 :

  android {
  defaultConfig {
                     applicationId "com.example.myapplication"
                 }
       }
 and package name the same. package="com.example.myapplication"

Step 2 delete iml file in my case :第 2 步在我的情况下删除 iml 文件:

  Go To Project> >C:\Users\ashif\Documents\MyApplication  .iml file // delete 
if you forget Project Path Then Go To android Studio Right Click on app and go to  Show in Explorer you get your Project and remove .iml file

Step 3 Close Project步骤 3关闭项目

Step 4 Now Copy Your old Project and Paste Any other Root or copy Project Folder and paste Any other Dir.第 4 步现在复制您的旧项目并粘贴任何其他根目录或复制项目文件夹并粘贴任何其他目录。

 Example C:\Users\ashif\Documents/MyApplication 

Step 5第 5 步

Now open Android Studio and open Existing Project 
C:\Users\ashif\Documents/MyApplication 

Try it will work试一试会奏效

This approach 100% working这种方法 100% 有效

Just do these simple step:只需执行以下简单步骤:

  • Exit Android Studio退出 Android Studio
  • Rename the main project folder from your explorer从资源管理器重命名主项目文件夹
  • Open Android Studio and Open your project打开 Android Studio 并打开你的项目
  • Rebuild and Enjoy.重建和享受。

TL;DR: TL;博士:

You may only follow the last part Renaming , maybe only images in it... ;-)您可能只关注最后一部分Renaming ,也许只关注其中的图像...... ;-)


Terminology:术语:

There is no such thing as Android Studio's “Project name” .没有Android Studio 的“项目名称”之类的东西。 But they are other names, entered during creating a new project:但它们是其他名称,在创建新项目时输入:

  • application name , which is initially the same as the Gradle's root project name ,应用程序名称,最初与 Gradle 的根项目名称相同,
  • the package name , package 名称
  • Android Studio project root folder name . Android Studio 项目根文件夹名称

In general, people want to change these 3 names, mostly to be derived from the Gradle's root project name in the same way as it is proposed in the New Project dialog window.通常,人们希望更改这 3 个名称,主要是从 Gradle 的根项目名称派生而来,其方式与“新建项目”对话框 window 中建议的方式相同。

So my answer will cover this case.所以我的回答将涵盖这种情况。


Analysis:分析:

We may to follow the same steps as Android Studio does when creating a new project.我们可以按照与 Android Studio 在创建新项目时相同的步骤进行操作。

If you chose File → New → New Project... (and then a project template), the first field in the New Project dialog window is the “Name” field with offered name My Application .如果您选择File → New → New Project... (然后是项目模板),New Project 对话框 window 中的第一个字段是提供名称My Application“Name”字段。

The 2 next fields uses this (default or changed) name to derive the default for 2 other strings, so there are 3 important strings , for example接下来的 2 个字段使用此(默认或更改的)名称来派生其他 2 个字符串的默认值,因此有3 个重要字符串,例如

  1. My Application我的应用程序
  2. com.something. com.something。 myapplication我的应用程序
  3. C:\Users\someuser\AndroidStudioProjects\ MyApplication C:\Users\someuser\AndroidStudioProjects\ MyApplication

Moreover,而且,

  • just after creating a project, there are yet no builds which would use those 3 strings.在创建项目之后,还没有使用这 3 个字符串的构建

Renaming:重命名:

So, there are 4 things which we have to ensure during renaming to other name – I will use the name My Renamed Project as a base for new names.因此,在重命名为其他名称期间,我们必须确保 4 件事——我将使用名称My Renamed Project作为新名称的基础。

Let's begin with the last, probably the simplest one:让我们从最后一个开始,可能是最简单的一个:

  • Build -> Clean Project构建 -> 清理项目

Please, no new build from this moment until the full renaming finishes.拜托,从这一刻起,直到完全重命名完成之前,没有新版本。

Now, begin renaming by previously specified 3 points:现在,按之前指定的 3 个点开始重命名:

  1. 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:在 Android Studio Window 的标题栏最左边的 position 中,您看到的文本与我在settings.gradle文件中选择的文本相同:ZC88ED1A7CD68923

    在此处输入图像描述

    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):您可能也想将应用程序名称更改为相同的名称,因此请在strings.xml资源文件中进行更改(更改将反映在AndroidManifest.xml文件中,这很重要):

    Before renaming:改名前:

    在此处输入图像描述

    After renaming:改名后:

    在此处输入图像描述

  2. com.something. 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, ie myrenamedapplication :更改build.gradle (模块级)文件中的applicationID - 源自“My Renamed Application”的新名称将不包含空格,全部小写,即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:单击右侧的“立即同步”:

    在此处输入图像描述

  3. Now close the Android Studio, and rename the folder现在关闭 Android Studio,并重命名文件夹

    MyApplication

    (probably located in the folder C:\Users\someuser\AndroidStudioProjects\ ) (可能位于文件夹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.尽管此步骤是可选的,但强烈建议保持整洁。

Note:笔记:

Opening the renamed project with File → Open Recent will of course fail, so for the first time after renaming, open it with File → Open .File → Open Recent打开重命名的项目当然会失败,所以第一次重命名后,用File → Open 打开

To just rename the project:要重命名项目:

  1. Refractor and rename the top level directory折射并重命名顶级目录
  2. Close Android Studio关闭 Android Studio
  3. IMPORT the whole project again再次导入整个项目

To change the package name:要更改包名称:

The easiest and fastest solution is here: https://stackoverflow.com/a/35057550/4908798最简单和最快的解决方案在这里: https ://stackoverflow.com/a/35057550/4908798

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

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