简体   繁体   English

Android和Eclipse将现有应用程序复制到新项目中会创建一个有趣的R. *

[英]Android & Eclipse copy existing app to new project creates a funny R.*

I am trying to create a trial version of an app i wrote. 我正在尝试创建我编写的应用程序的试用版。 I copied my main project, then pasted it as a new project with a new name. 我复制了主项目,然后将其粘贴为具有新名称的新项目。 I then refactored (appended Trial) to my activities, then i fixed any errors that cropped up because of this. 然后,我将活动重构(附加到试用版中),然后修复由于此而出现的所有错误。 Once the project compiled, I tried running the app. 项目编译后,我尝试运行该应用程序。

When I try to run the trial app on the emulator, my app cannot find any of its resources (drawables, styles, etc) if I programatically access 'R.*'. 当我尝试在模拟器上运行试用版应用程序时,如果我以编程方式访问“ R. *”,则我的应用程序将找不到其任何资源(可绘制,样式等)。 If my app starts an activity that hard coded a style, that works fine (except the drawables are missing). 如果我的应用程序启动了一项对样式进行硬编码的活动,则可以正常工作(除非缺少可绘制对象)。

Also, I am not sure how resources are mapped, but when I open my generated R.java for each project they are identical! 另外,我不确定如何映射资源,但是当我为每个项目打开生成的R.java时,它们是相同的! The errors thrown from my trial app say "Resource not found for xyz' and the id the exception shows me is different than the one in generated R.java. 从我的试用版应用抛出的错误说:“ xyz找不到资源”和异常显示给我的id与生成的R.java中的ID不同。

Any one have any ideas how i can get this working? 任何人有任何想法,我如何才能使它工作?

Thanks. 谢谢。

* Addition ** So I forgot to mention that I am targeting version Android 1.5 (api version 3). * 另外 **因此,我忘了提及我针对的是Android 1.5版本(api版本3)。 I just updated the target version to 4 and things worked... I would like to target 1.5 ... Anyone experience this? 我刚刚将目标版本更新为4,然后一切正常……我想以1.5为目标……有人会遇到这种情况吗? Thanks. 谢谢。

Look in the gen/ folder and see what package R.java is being generated in. All references to anything from R.java in your code must be either explicitly or implicitly to its actual current package name. 查看gen /文件夹,查看正在生成的R.java包。代码中对R.java中任何内容的所有引用都必须显式或隐式为其实际的当前包名称。

If R.java isn't being generated in the package you want, it can be tricky to convince eclipse to "move" it. 如果没有在所需的软件包中生成R.java,则说服Eclipse“移动”它可能很棘手。 What seems to work is making a copy of your primary java source file and renaming/relocating it to the package name you want R.java to be in, then deleting the original. 似乎有效的方法是复制您的主要Java源文件,并将其重命名/重定位为您想要R.java所在的程序包名称,然后删除原始文件。

That plus a project clean and rebuild should get things working again. 加上清理和重建的项目,应该会使事情重新开始。

For me, this is the best working solution i've found: Android - copy existing project with a new name 对我而言,这是我找到的最佳工作解决方案: Android-使用新名称复制现有项目

Seems like you first have to change the package name in manifest only, then your main package name (with refactor) and finally rename your application name in manifest. 似乎您首先必须仅在清单中更改软件包名称, 然后才需要更改主软件包名称(使用重构), 最后在清单中重命名应用程序名称。

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

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