简体   繁体   English

重命名Android程序包名称失败

[英]Rename Android Package name fails

I right click on my project in eclipse, android tools , 'Rename application package'. 我在eclipse,android工具,'重命名应用程序包'中右键单击我的项目。

Pick any name and it will fail, directing you to the error log for details. 选择任何名称,它将失败,将您引导至错误日志以获取详细信息。

There i find the following: 在那里我找到以下内容:

eclipse.buildId=M20110210-1200
java.version=1.6.0_26
java.vendor=Sun Microsystems Inc.
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=nl_BE
Framework arguments:  -product org.eclipse.epp.package.java.product
Command-line arguments:  -os win32 -ws win32 -arch x86_64 -product org.eclipse.epp.package.java.product

Error Fri Jun 24 10:11:31 CEST 2011 Internal Error 错误周五6月24日10:11:31 CEST 2011内部错误

java.lang.reflect.InvocationTargetException
at org.eclipse.ltk.internal.ui.refactoring.WorkbenchRunnableAdapter.run(WorkbenchRunnableAdapter.java:91)
at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)
Caused by: org.eclipse.core.internal.resources.ResourceException: An error occurred while traversing resources.
at org.eclipse.core.internal.resources.Resource.accept(Resource.java:83)
at org.eclipse.core.internal.resources.Resource.accept(Resource.java:110)
at org.eclipse.core.internal.resources.Resource.accept(Resource.java:94)
at com.android.ide.eclipse.adt.internal.refactorings.renamepackage.ApplicationPackageNameRefactoring.createChange(ApplicationPackageNameRefactoring.java:128)
at org.eclipse.ltk.core.refactoring.CreateChangeOperation.run(CreateChangeOperation.java:124)
at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1975)
at org.eclipse.ltk.internal.ui.refactoring.WorkbenchRunnableAdapter.run(WorkbenchRunnableAdapter.java:87)
... 1 more
Caused by: java.lang.NullPointerException
at com.android.ide.eclipse.adt.internal.refactorings.renamepackage.ApplicationPackageNameRefactoring.updateJavaFileImports(ApplicationPackageNameRefactoring.java:151)
at com.android.ide.eclipse.adt.internal.refactorings.renamepackage.ApplicationPackageNameRefactoring$JavaFileVisitor.visit(ApplicationPackageNameRefactoring.java:427)
at org.eclipse.core.internal.resources.Resource$2.visit(Resource.java:112)
at org.eclipse.core.internal.resources.Resource$1.visitElement(Resource.java:64)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:82)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:86)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:86)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:86)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:86)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:86)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:86)
at org.eclipse.core.internal.watson.ElementTreeIterator.iterate(ElementTreeIterator.java:127)
at org.eclipse.core.internal.resources.Resource.accept(Resource.java:74)
... 7 more
Root exception:
org.eclipse.core.internal.resources.ResourceException(/Touring Mobilis)[566]: java.lang.NullPointerException
at com.android.ide.eclipse.adt.internal.refactorings.renamepackage.ApplicationPackageNameRefactoring.updateJavaFileImports(ApplicationPackageNameRefactoring.java:151)
at com.android.ide.eclipse.adt.internal.refactorings.renamepackage.ApplicationPackageNameRefactoring$JavaFileVisitor.visit(ApplicationPackageNameRefactoring.java:427)
at org.eclipse.core.internal.resources.Resource$2.visit(Resource.java:112)
at org.eclipse.core.internal.resources.Resource$1.visitElement(Resource.java:64)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:82)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:86)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:86)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:86)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:86)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:86)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:86)
at org.eclipse.core.internal.watson.ElementTreeIterator.iterate(ElementTreeIterator.java:127)
at org.eclipse.core.internal.resources.Resource.accept(Resource.java:74)
at org.eclipse.core.internal.resources.Resource.accept(Resource.java:110)
at org.eclipse.core.internal.resources.Resource.accept(Resource.java:94)
at com.android.ide.eclipse.adt.internal.refactorings.renamepackage.ApplicationPackageNameRefactoring.createChange(ApplicationPackageNameRefactoring.java:128)
at org.eclipse.ltk.core.refactoring.CreateChangeOperation.run(CreateChangeOperation.java:124)
at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1975)
at org.eclipse.ltk.internal.ui.refactoring.WorkbenchRunnableAdapter.run(WorkbenchRunnableAdapter.java:87)
at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)

Does this tool work for anyone? 这个工具适用于任何人吗? If so, please let me know what version of eclipse you are using. 如果是这样,请告诉我您使用的是哪个版本的日食。

I'm using the latest versions of eclipse (64bit) on windows 7 with the latest ADT eclipse plugin. 我在Windows 7上使用最新版本的eclipse(64位)和最新的ADT eclipse插件。

You can not belive this. 你不能相信这一点。 I have exactly the same problem and is because I comment a class entirely. 我有完全相同的问题,因为我完全评论了一个类。 So I think that when eclipse try to change the package name of a commented class it throw this error. 所以我认为当eclipse尝试更改注释类的包名时会抛出此错误。

To solve the problem you only has to delete the class or uncomment it. 要解决此问题,您只需删除该类或取消注释。

I was facing the same problem. 我遇到了同样的问题。 I just was was not able to rename the package using package > right click > rename package. 我只是无法使用包>右键单击>重命名包重命名包。 It appeared the package references in some xml templates, using custom controls were not updated, so the R file could not be generated. 在某些xml模板中出现了包引用,使用自定义控件未更新,因此无法生成R文件。 After looking at the xml and renaming the references, the R file was generated and I could continue renaming. 查看xml并重命名引用后,生成了R文件,我可以继续重命名。

Actually I decided to create my own package rename tool. 实际上我决定创建自己的包重命名工具。

It's very simple in fact: 事实很简单:

  • Replace the AndroidManifest.xml with the [packagename]. 用[packagename]替换AndroidManifest.xml。
  • Replace [packagename].R in all *.java files 在所有* .java文件中替换[packagename] .R
  • Replace SCHEMAS in xml files: http://schemas.android.com/apk/res/[packagename] 在xml文件中替换SCHEMAS:http://schemas.android.com/apk/res/ [packagename]

I then choose to 'not update launch configurations' and refresh eclipse project. 然后我选择“不更新启动配置”并刷新eclipse项目。

All goes well then :). 一切顺利然后:)。

That combined with git branches and the antenna preprocessor helps me to get the flexibility I need to perform many versions of an application with various options. 结合git分支和天线预处理器有助于我获得执行具有各种选项的应用程序的许多版本所需的灵活性。

Apparently the following way can help you rename. 显然,以下方式可以帮助您重命名。

1.Right Click the gen folder and rename the package name to what you want it to be.see the image below. 1.右键单击gen文件夹并将包名重命名为您想要的名称。请参见下图。

在此输入图像描述

2.After renaming the above open your manifest file and change the package declaration to what you want it to be but it should be the same as the package in the gen folder see below. 2.重命名上面后打开你的清单文件,并将包声明更改为你想要的,但它应该与gen文件夹中的包相同,见下文。

在此输入图像描述

That should be it folks.Happy coding! 应该是人们。快乐的编码!

haha The reason of this bug is as follows: 哈哈这个bug的原因如下:

Caused by: java.lang.NullPointerException
at com.android.ide.eclipse.adt.internal.refactorings.renamepackage.ApplicationPackageNameRefactoring.updateJavaFileImports(ApplicationPackageNameRefactoring.java:151).

So,you need to check if one of your java files doesn't have a package name. 因此,您需要检查一个java文件是否没有包名。

For example: 例如:

//package com.telecom.request.login;
//
//import android.content.Context;
//import android.content.Intent;

The package of my java file has been commented,then eclipse can't get the file's package name,nullpointer comes out. 我的java文件的包已被注释,然后eclipse无法获取文件的包名,nullpointer出来了。

Hope helpful for you. 希望对你有所帮助。

Try right-clicking on the package and choose Refactor->Rename, it works fine for me, never had any troubles. 尝试右键单击包并选择Refactor-> Rename,它对我来说很好,从来没有遇到任何麻烦。 Hope this helps. 希望这可以帮助。

I have had similar problems while refactoring / renaming projects with some versions of eclipse. 我在使用某些版本的eclipse重构/重命名项目时遇到了类似的问题。 If you need a quick fix , I'd suggest this. 如果你需要快速修复 ,我建议这样做。

Create a new android application with the name you want to market it as and copy the source code file by file into your new application. 创建一个新的Android应用程序,其中包含您要将其推向市场的名称,并将源代码文件按文件复制到新应用程序中。 Warning: Do not copy the files themselves, just the code in the files, as eclipse has some meta data associated with each file and this could possibly cause linking errors. 警告:不要复制文件本身,只复制文件中的代码,因为eclipse有一些与每个文件关联的元数据,这可能会导致链接错误。

Hope this helps. 希望这可以帮助。

I had the same error about "traversing resources." 关于“遍历资源”我有同样的错误。 I deleted the referenced folder (it was unused) and I was able to refactor the package name after that. 我删除了引用的文件夹(它没有使用),之后我能够重构包名。

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

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