Android:包括多个要清单的 Java 包

Android: Including multiple Java Packages to Manifest(Android:包括多个要清单的 Java 包)
本文介绍了Android:包括多个要清单的 Java 包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在开发的应用程序有许多活动,这些活动组织成七个 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 包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Android release APK crash with java.lang.AssertionError: impossible in java.lang.Enum(Android 发布 APK 因 java.lang.AssertionError 崩溃:在 java.lang.Enum 中不可能)
Finished with Non Zero Exit Value 3(以非零退出值 3 结束)
On gradle:3.0.0 More than one file was found with OS independent path #39;META-INF/ASL2.0#39;(在 gradle:3.0.0 上找到多个文件,其独立于操作系统的路径为“META-INF/ASL2.0)
Android : app loading library at runtime on Lollipop but not IceCreamSandwich(Android:运行时在 Lollipop 上而不是 IceCreamSandwich 上的应用程序加载库)
buildConfigField depending on flavor + buildType(buildConfigField 取决于风味 + buildType)
How do I suppress warnings when compiling an android library with gradle?(使用 gradle 编译 android 库时如何抑制警告?)