Android 在Eclipse中完全重命名项目

Android 在Eclipse中完全重命名项目,android,eclipse,project,rename,Android,Eclipse,Project,Rename,我已经在Eclipse中完成了重构->重命名,并且该项目已经在Eclipse中成功重命名。但当我将其复制/粘贴到文件夹中时,它仍然保留旧名称 如何完全重命名它?从项目文件夹中打开.project文件,并更改其中的以下值 您需要在其中更改为项目名称 另一方面, 从project explorer复制旧项目,并将其粘贴到那里,它将请求新名称,给出新名称,然后完成。1)右键单击包->重构->重命名。选择更新引用并重命名子包 2) 更改AndroidMenifest.xml中的packagename

我已经在Eclipse中完成了重构->重命名,并且该项目已经在Eclipse中成功重命名。但当我将其复制/粘贴到文件夹中时,它仍然保留旧名称


如何完全重命名它?

从项目文件夹中打开
.project
文件,并更改其中的以下值

您需要在其中更改为项目名称

另一方面,

从project explorer复制旧项目,并将其粘贴到那里,它将请求新名称,给出新名称,然后完成。

1)右键单击包->重构->重命名。选择更新引用并重命名子包

2) 更改AndroidMenifest.xml中的packagename

package=”com.example.new_package_name”
3) 在resources->values->string.xml中将app\u name更改为“new\u name”

“新名称”

希望这能奏效

复制粘贴ANDROID项目并创建一个新项目很整洁。按照以下步骤操作:

A.如果您使用的是Eclipse,您需要做的只是首先打开您想要复制的项目(不要忘记打开您需要复制的项目), 然后在Eclipse左侧的explorer包窗口中克隆(复制/粘贴)您的Android项目。 粘贴时Eclipse将要求您输入一个新的项目名称。请给它一个新的项目名称。 由于Eclipse项目名称和目录独立于应用程序名称和包, 以下步骤将帮助您更改包名。注意:有两种类型的包名。 (清单文件中所示的主包和包含所有java文件的子包)


TrueStudio也是基于Eclipse的,它可能以类似的方式工作。但是重构项目名称不起作用。 我将一个项目克隆到另一个项目的方法是在主文件夹上使用Ctrl-C/Ctrl-V,然后将新文件夹重命名为所需的名称。现在,我们只需要更改目录名和一些文件名。我们需要修改几个文件的内容。然后,可以在TrueStudio中打开该项目

简而言之,请参见以下示例:

Rename Project:
Copy the project directory
“Nucleo-H743ZI_Jack_01-”
“Nucleo-H743ZI_Jack_010 - Copy”

Rename it to the new name
“Nucleo-H743ZI_Jack_010 - Copy”
“Nucleo-H743ZI_Jack_011_tcp”

Rename this directory
“Nucleo-H743ZI_Jack_011_tcp\TrueSTUDIO\Nucleo-H743ZI_Jack_010”
“Nucleo-H743ZI_Jack_011_tcp\TrueSTUDIO\Nucleo-H743ZI_Jack_011_tcp”

Rename these files
“Nucleo-H743ZI_Jack_011_tcp\Nucleo-H743ZI_Jack_010.ioc”
“Nucleo-H743ZI_Jack_011_tcp\Nucleo-H743ZI_Jack_011_tcp.ioc”
“Nucleo-H743ZI_Jack_011_tcp\TrueSTUDIO\Nucleo-H743ZI_Jack_011_tcp\Nucleo-H743ZI_Jack_010.elf.launch”
“Nucleo-H743ZI_Jack_011_tcp\TrueSTUDIO\Nucleo-H743ZI_Jack_011_tcp\Nucleo-H743ZI_Jack_011_tcp.elf.launch”

Change these files
“Nucleo-H743ZI_Jack_011_tcp\.mxproject” (3 occurrences)
“Nucleo-H743ZI_Jack_011_tcp\Nucleo-H743ZI_Jack_011_tcp.ioc” (2 occurrences)
“Nucleo-H743ZI_Jack_011_tcp\TrueSTUDIO\Nucleo-H743ZI_Jack_011_tcp\.cproject” (3 occurrences)
“Nucleo-H743ZI_Jack_011_tcp\TrueSTUDIO\Nucleo-H743ZI_Jack_011_tcp\.project” (1 occurrence)
“Nucleo-H743ZI_Jack_011_tcp\TrueSTUDIO\Nucleo-H743ZI_Jack_011_tcp\Nucleo-H743ZI_Jack_011_tcp.elf.launch” (5 occurrences)

Note: also get rid of absolute paths in Nucleo-H743ZI_Jack_011_tcp\TrueSTUDIO\Nucleo-H743ZI_Jack_011_tcp\.project

Open project
File -> Open Project from File System…
Directory: “Nucleo-H743ZI_Jack_011_tcp\TrueSTUDIO\Nucleo-H743ZI_Jack_011_tcp”
Click OK and Finish
放置在项目根目录中的python脚本可以执行以下操作:

chproj.py

# Changed the name of an TrueStudio project
import os
import sys

def inplace_change(filename, old_string, new_string):
    # Safely read the input filename using 'with'
    with open(filename) as f:
        s = f.read()
        if old_string not in s:
            print '"{old_string}" not found in {filename}.'.format(**locals())
            return

    # Safely write the changed content, if found in the file
    with open(filename, 'w') as f:
        print 'Changing "{old_string}" to "{new_string}" in {filename}'.format(**locals())
        s = s.replace(old_string, new_string)
        f.write(s)

# Getting the current work directory (cwd)
dir_abs = os.getcwd()
dir_abs_split=dir_abs.split('\\')
n = len(dir_abs_split)
dst_dir = dir_abs_split[n-1]
new_name = dst_dir
print dir_abs

# Get original name
#src_dir = os.listdir(ts_dir)[0]
#old_name = src_dir
#print "old_name: " + old_name

mxproject_filename = dir_abs + "\.mxproject"
with open(mxproject_filename) as f:
    content = f.readlines()
second_line = content[1]
#print second_line
second_line_split=second_line.split('/')
n=len(second_line_split)
old_name = second_line_split[n-2]
print "old_name: " + old_name
print "new_name: " + new_name

ioc_filename_old = dir_abs + "\\" + old_name + ".ioc"
ioc_filename_new = dir_abs + "\\" + new_name + ".ioc"

ts_dir = dir_abs + "\TrueSTUDIO"

ts_name_old = ts_dir + "\\" + old_name
ts_name_new = ts_dir + "\\" + new_name

elf_launch_old = ts_dir + "\\" + new_name + "\\" + old_name + ".elf.launch"
elf_launch_new = ts_dir + "\\" + new_name + "\\" + new_name + ".elf.launch"

cproject = ts_dir + "\\" +  new_name + "\.cproject"
project = ts_dir + "\\" +  new_name + "\.project"

print "Change path in " + project

new_path = "PARENT-2-PROJECT_LOC"
old_path = dir_abs.replace("\\", "/")
old_path = old_path.replace("c:", "C:")
print old_path
print new_path

if os.path.isfile(project):
    # file exists
    print "Modify file " + project
    inplace_change(project, old_path, new_path)

if (new_name == old_name):
    print "Nothing else to change"
    sys.exit(0)


print "Rename directories and files:"

#os.rename(src, dst)
if os.path.isdir(ts_name_old):
    # dir exists
    print "Rename directory " + ts_name_old + " to " + ts_name_new
    os.rename(ts_name_old, ts_name_new)

#os.rename(src, dst)
if os.path.isfile(ioc_filename_old):
    # file exists
    print "Rename file " + ioc_filename_old + " to " + ioc_filename_new
    os.rename(ioc_filename_old, ioc_filename_new)

if os.path.isfile(elf_launch_old):
    # file exists
    print "Rename file " + elf_launch_old + " to " + elf_launch_new
    os.rename(elf_launch_old, elf_launch_new)

print "Replace strings in files:"

if os.path.isfile(cproject):
    # file exists
    print "Modify file " + cproject
    inplace_change(cproject, old_name, new_name)

if os.path.isfile(project):
    # file exists
    print "Modify file " + project
    inplace_change(project, old_name, new_name)
    inplace_change(project, old_path, new_path)

if os.path.isfile(ioc_filename_new):
    # file exists
    print "Modify file " + ioc_filename_new
    inplace_change(ioc_filename_new, old_name, new_name)

if os.path.isfile(elf_launch_new):
    # file exists
    print "Modify file " + elf_launch_new
    inplace_change(elf_launch_new, old_name, new_name)

if os.path.isfile(mxproject_filename):
    # file exists
    print "Modify file " + mxproject_filename
    inplace_change(mxproject_filename, old_name, new_name)

欢迎提出任何改进意见或建议!

当我将其复制/粘贴到文件夹中时,您的意思是:
?您的意思是包名是旧的吗?当我备份应用程序的某些版本时,我将其复制并粘贴到备份文件夹中。包含项目的文件夹名保留其旧名称。其中的名称更改为e新名称,但文件夹仍保留旧名称。这是因为您没有重命名文件夹。从project explorer复制旧项目,并将其粘贴到那里,它将请求新名称,给出新名称,然后完成。似乎是合法的操作xDOk,如果您有任何与Android相关的错误,请点击我,我一定会在空闲时间尝试帮助您:)只需将任何消息写入我的任何帖子或此处,完成。上述内容可能不适用,它适用于STM32。
Rename Project:
Copy the project directory
“Nucleo-H743ZI_Jack_01-”
“Nucleo-H743ZI_Jack_010 - Copy”

Rename it to the new name
“Nucleo-H743ZI_Jack_010 - Copy”
“Nucleo-H743ZI_Jack_011_tcp”

Rename this directory
“Nucleo-H743ZI_Jack_011_tcp\TrueSTUDIO\Nucleo-H743ZI_Jack_010”
“Nucleo-H743ZI_Jack_011_tcp\TrueSTUDIO\Nucleo-H743ZI_Jack_011_tcp”

Rename these files
“Nucleo-H743ZI_Jack_011_tcp\Nucleo-H743ZI_Jack_010.ioc”
“Nucleo-H743ZI_Jack_011_tcp\Nucleo-H743ZI_Jack_011_tcp.ioc”
“Nucleo-H743ZI_Jack_011_tcp\TrueSTUDIO\Nucleo-H743ZI_Jack_011_tcp\Nucleo-H743ZI_Jack_010.elf.launch”
“Nucleo-H743ZI_Jack_011_tcp\TrueSTUDIO\Nucleo-H743ZI_Jack_011_tcp\Nucleo-H743ZI_Jack_011_tcp.elf.launch”

Change these files
“Nucleo-H743ZI_Jack_011_tcp\.mxproject” (3 occurrences)
“Nucleo-H743ZI_Jack_011_tcp\Nucleo-H743ZI_Jack_011_tcp.ioc” (2 occurrences)
“Nucleo-H743ZI_Jack_011_tcp\TrueSTUDIO\Nucleo-H743ZI_Jack_011_tcp\.cproject” (3 occurrences)
“Nucleo-H743ZI_Jack_011_tcp\TrueSTUDIO\Nucleo-H743ZI_Jack_011_tcp\.project” (1 occurrence)
“Nucleo-H743ZI_Jack_011_tcp\TrueSTUDIO\Nucleo-H743ZI_Jack_011_tcp\Nucleo-H743ZI_Jack_011_tcp.elf.launch” (5 occurrences)

Note: also get rid of absolute paths in Nucleo-H743ZI_Jack_011_tcp\TrueSTUDIO\Nucleo-H743ZI_Jack_011_tcp\.project

Open project
File -> Open Project from File System…
Directory: “Nucleo-H743ZI_Jack_011_tcp\TrueSTUDIO\Nucleo-H743ZI_Jack_011_tcp”
Click OK and Finish
chproj.py

# Changed the name of an TrueStudio project
import os
import sys

def inplace_change(filename, old_string, new_string):
    # Safely read the input filename using 'with'
    with open(filename) as f:
        s = f.read()
        if old_string not in s:
            print '"{old_string}" not found in {filename}.'.format(**locals())
            return

    # Safely write the changed content, if found in the file
    with open(filename, 'w') as f:
        print 'Changing "{old_string}" to "{new_string}" in {filename}'.format(**locals())
        s = s.replace(old_string, new_string)
        f.write(s)

# Getting the current work directory (cwd)
dir_abs = os.getcwd()
dir_abs_split=dir_abs.split('\\')
n = len(dir_abs_split)
dst_dir = dir_abs_split[n-1]
new_name = dst_dir
print dir_abs

# Get original name
#src_dir = os.listdir(ts_dir)[0]
#old_name = src_dir
#print "old_name: " + old_name

mxproject_filename = dir_abs + "\.mxproject"
with open(mxproject_filename) as f:
    content = f.readlines()
second_line = content[1]
#print second_line
second_line_split=second_line.split('/')
n=len(second_line_split)
old_name = second_line_split[n-2]
print "old_name: " + old_name
print "new_name: " + new_name

ioc_filename_old = dir_abs + "\\" + old_name + ".ioc"
ioc_filename_new = dir_abs + "\\" + new_name + ".ioc"

ts_dir = dir_abs + "\TrueSTUDIO"

ts_name_old = ts_dir + "\\" + old_name
ts_name_new = ts_dir + "\\" + new_name

elf_launch_old = ts_dir + "\\" + new_name + "\\" + old_name + ".elf.launch"
elf_launch_new = ts_dir + "\\" + new_name + "\\" + new_name + ".elf.launch"

cproject = ts_dir + "\\" +  new_name + "\.cproject"
project = ts_dir + "\\" +  new_name + "\.project"

print "Change path in " + project

new_path = "PARENT-2-PROJECT_LOC"
old_path = dir_abs.replace("\\", "/")
old_path = old_path.replace("c:", "C:")
print old_path
print new_path

if os.path.isfile(project):
    # file exists
    print "Modify file " + project
    inplace_change(project, old_path, new_path)

if (new_name == old_name):
    print "Nothing else to change"
    sys.exit(0)


print "Rename directories and files:"

#os.rename(src, dst)
if os.path.isdir(ts_name_old):
    # dir exists
    print "Rename directory " + ts_name_old + " to " + ts_name_new
    os.rename(ts_name_old, ts_name_new)

#os.rename(src, dst)
if os.path.isfile(ioc_filename_old):
    # file exists
    print "Rename file " + ioc_filename_old + " to " + ioc_filename_new
    os.rename(ioc_filename_old, ioc_filename_new)

if os.path.isfile(elf_launch_old):
    # file exists
    print "Rename file " + elf_launch_old + " to " + elf_launch_new
    os.rename(elf_launch_old, elf_launch_new)

print "Replace strings in files:"

if os.path.isfile(cproject):
    # file exists
    print "Modify file " + cproject
    inplace_change(cproject, old_name, new_name)

if os.path.isfile(project):
    # file exists
    print "Modify file " + project
    inplace_change(project, old_name, new_name)
    inplace_change(project, old_path, new_path)

if os.path.isfile(ioc_filename_new):
    # file exists
    print "Modify file " + ioc_filename_new
    inplace_change(ioc_filename_new, old_name, new_name)

if os.path.isfile(elf_launch_new):
    # file exists
    print "Modify file " + elf_launch_new
    inplace_change(elf_launch_new, old_name, new_name)

if os.path.isfile(mxproject_filename):
    # file exists
    print "Modify file " + mxproject_filename
    inplace_change(mxproject_filename, old_name, new_name)