如何在基于IntelliJ IDEA的新IDE Android Studio中重命名软件包?
是否包含自动重构?
我想进行大规模重构,但我不知道怎么做。我在Eclipse工作了两年,在Eclipse中它是一个一键操作。
如何在基于IntelliJ IDEA的新IDE Android Studio中重命名软件包?
是否包含自动重构?
我想进行大规模重构,但我不知道怎么做。我在Eclipse工作了两年,在Eclipse中它是一个一键操作。
当前回答
如何将com.example.app重命名为com.android.app:
在包com.example.app中选择示例移位+F6选择重命名包将示例重命名为android确认进行重构
其他回答
对我来说会很好的
Change Following.
步骤1:确保ApplicationId和PackageName相同。例子:
android {
defaultConfig {
applicationId "com.example.myapplication"
}
}
and package name the same. package="com.example.myapplication"
步骤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
步骤3关闭项目
步骤4现在复制您的旧项目并粘贴任何其他根或复制项目文件夹并粘贴任何其他董事。
Example C:\Users\ashif\Documents/MyApplication
步骤5
Now open Android Studio and open Existing Project
C:\Users\ashif\Documents/MyApplication
试试看会奏效的
安卓工作室2022
分步实施
步骤1:要在Android studio中重命名包名,请首先在Android模式下打开项目,如下图所示。
步骤2:现在单击设置齿轮图标并取消选择紧凑型中间包。
步骤3:现在,packages文件夹被分解为下图所示的部分。
步骤4:现在右键单击第一个包名(com),然后Refactor>Rename。将显示警告消息,但继续并单击重命名当前按钮。
步骤5:根据需要重命名目录名,然后单击Refactor按钮。
注意:转到“Build”>“Rebuild Project”以显示更新的名称。
现在,您可以从com->gfg中看到目录名的更改,如下图所示。
步骤6:根据您的要求,对域名扩展名和应用程序文件夹名称执行相同操作。
现在,您可以看到包名已从com.example.pulltorefreshwithlistview更改为gfg.geekesforgeekes.listview,如下图所示。
步骤7:现在转到gradle脚本中的build.gradle(模块:app)。此处更改applicationId并单击“立即同步”。并且成功地重命名了包名。
资料来源:如何在Android Studio中重命名软件包名称?
首先,您需要转到左侧显示的设置图标。单击该下拉列表并取消选中压缩空中间包
转到AndroidManifest.xml
选择所有包,然后右键单击重构,然后根据需要重命名。然后转到build.gradle,然后使用Android Manifest中的packagename更改Applicationid。
这对我来说很有效
在使用这些技术之一重命名包之后,可能会开始看到错误。
如果/当你的R.java没有正确生成时,你会在项目中收到很多错误,比如错误:找不到符号类R,以及错误:包R不存在。
记住检查应用程序清单xml。清单包名称必须与实际包名称匹配。R.java似乎是从应用程序清单生成的,如果不匹配,可能会导致这些错误。
记住检查<manifestpackage=“com.yourcompany.coolapp”>中的package属性匹配
接受的答案对我不起作用。这里有一个python脚本,可以直接在源文件上更改包名。
"""
Notes:
1 - This script it for python3
2 - Create a backup first
3 - Place on the root folder of the android project you want to change
4 - run `python change_android_studio_pkg_name.py`
5 - Type the old package name
6 - Type the new package name
7 - Clean and Rebuild on Android Studio
8 - SRC folder names won't be changed but app will work
"""
import os, glob, traceback
from pathlib import Path
def rwf(fp, mode="r", data="" ):
if mode == "r":
with open(fp, "r", encoding='utf8') as f:
return(f.read())
elif mode == "w":
with open(fp, "w", encoding='utf8') as f:
f.write(data)
old_pkg = input("Old PKG\n").strip()
new_pkg = input("New PKG\n").strip()
if not old_pkg or not new_pkg:
exit("Args Missing")
dirname, filename = os.path.split(os.path.abspath(__file__))
file_types = ['xml', 'txt', 'json', 'gradle', 'java']
_fs = glob.iglob(f"{dirname}/**", recursive=True)
for file_path in _fs:
ext = Path(file_path).suffix.replace(".", "").lower()
if os.path.isfile(file_path) and ext in file_types:
try:
content = rwf(file_path)
new_content = content.replace(old_pkg, new_pkg)
rwf(file_path, "w", new_content)
except:
print(traceback.format_exc())
pass
蟒蛇3要点