我正在开发的应用程序有许多活动,这些活动组织成七个 java 包.最初,我将 java 包中每组活动的所有编码和内容编写为不同的项目.
The app I am developing has many activities organized into seven java packages. Originally I wrote all the coding and stuff for each group of activities in a java package as different projects.
现在我想将所有包放在一个项目中.当我将新包添加到 src 文件夹时,我的所有 R.id.* 值都会出现错误(R 无法解析").
Now I'm at the point where I want to put all the packages together into one project. When I add a new package to the src folder, I get an error for all my R.id.* values ("R cannot be resolved").
我的直觉告诉我,我必须在项目清单中添加一些花哨的东西,但我在网上找不到任何资源来告诉我如何操作.
My instinct tells me that there is something fancy I have to put in the project manifest, but I can't find any resource online to tell me how.
(注意:我已阅读 this 和 this 我仍然不知道如何向我的项目添加额外的包.)
(Note: I have read this and this and I still couldn't figure out how to add additional packages to my project.)
确保 Activity 顶部的 import 语句引用了正确的 R 文件.每个项目都有自己的 R 文件,因此如果您将 Activity 从一个项目复制到另一个项目,它仍会尝试从旧项目中引用 R 文件.
Make sure that the import statement at the top of the Activity references the correct R file. Each project has its own R file, so if you copy an Activity from one project to another it will still be trying to reference the R file from the old project.
您不需要在清单中明确包含不同的包.要包含来自两个不同包的活动,请说:
You do not need any explicit inclusion of different packages in the manifest. To include activities from two different packages, say:
com.example.package1.Activity1
com.example.package2.Activity2
您可以执行以下操作:
<manifest package="com.example" . . . >
<application . . .>
<activity android:name=".package1.Activity1" . . . />
<activity android:name=".package2.Activity2" . . . />
</application>
</manifest>
这篇关于Android:包括多个要清单的 Java 包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!