为什么会生成多个R.java

发布于 2024-12-28 16:50:59 字数 3723 浏览 7 评论 0原文

我找到了解决问题的方法。答案就在我的回答里。我稍微修改了问题。


问题仍未解决。

使用Eclipse构建android项目时,是否会生成超过1个R.java 文件?

是的,它会为每个已导入的库生成 R.java

我如何保留它不会生成额外的 2 个 R.java 文件

不要导入其他 2 个库,但您可能需要修复您的依赖项。多个不是问题。

下面的问题已得到解决,但是... Eclipse 仍然生成 3 个 R.java 文件,而我的 ant 脚本仅生成 1 个。对于 中的项目问题,在两种情况下(ant 或 eclipse)一切都编译得很好,但这可能会在另一个项目中引起问题,我想知道上面问题的答案。


下面是已经解决的老问题

我正在尝试为多个应用程序创建一些 ant 构建脚本。当尝试运行此代码时:

<target name="resource-src" description="Generate the R.java file for this project's resources.">
    <exec executable="${aapt}" failonerror="true">
        <arg value="package"/>
        <arg value="-f"/>
        <arg value="-v"/>
        <arg value="-M"/>
        <arg path="../AndroidManifest.xml"/>
        <arg value="-A"/>
        <arg path="../assets"/>
        <arg value="-I"/>
        <arg path="${android_jar}"/>
        <arg value="-m"/>
        <arg value="-J"/>
        <arg path="../gen"/> <!-- Create R.java in the gen directory -->
        <arg value="-S"/>
        <arg path="../res"/>
    </exec>
</target>

我收到此错误:

C:\BoogerReport\builder\build.xml:76: exec returned: 1

我注意到该应用程序在使用 eclipse 构建项目(在 gen 文件夹中)时生成多个 R.java 文件。我认为 Android 应用程序只应该生成 1 个 R.java 文件。

1.是这样吗?

2.如果不是,可能是什么问题?

3.另外,这两个问题是否相关,还是还有其他错误?


下面是相关项目的 AndroidManifest.xml。


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="alpha.beta.charley.delta.echo.booger.ui"
      android:versionCode="2"
      android:versionName="UnofficialBuild">
    <uses-sdk android:minSdkVersion="10" />
    <application android:icon="@drawable/booger"
        android:label="@string/app_name">
        <activity android:name=".BoogerReport"
                  android:label="@string/app_name"
                  android:configChanges="keyboardHidden|orientation"
                  android:windowSoftInputMode="stateHidden">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <intent-filter>
                <action android:name="alpha.beta.charley.delta.message.boogerreport.CREATE" />
                <category android:name="android.intent.category.DEFAULT"/>
                <category android:name="alpha.beta.charley.delta.message.category.LOCATION" /> 
            </intent-filter>
        </activity>
        <activity android:name=".BoogerReportView"
                  android:configChanges="orientation">
            <intent-filter>
                <action android:name="alpha.beta.charley.delta.message.boogerreport.OPEN" />
                <category android:name="android.intent.category.DEFAULT"/>
            </intent-filter>
        </activity>
        <activity android:name=".BoogerList" 
                  android:configChanges="orientation" /> 
    </application>
</manifest>

回答问题的附加信息:

生成的 R.java 文件的路径:

  1. alpha.beta.charley.delta
  2. alpha.beta.charley.delta.echo.booger.ui
  3. alpha.beta.charley.datamodel

I figured out the solution to the problems. Answers are in my answer. And i modified the question a little.


Problem still not resolved.

When using Eclipse to build an android project, should it be generating more than 1
R.java
file?

Yes, it will generate R.java for each library that has been imported.

How do I keep it from generating the extra 2 R.java files

Dont, import those other 2 libraries, but you will probably need to to fix your dependencies. Multiple is not a problem.

The problem below has been fixed, however... Eclipse is still generating 3 R.java files and my ant script is only generating 1. For the project in question, everything compiles fine in both scenarios (ant or eclipse) but this could possibly be causing an issue in another project and i would like to know the answer to the question above.


Below is the old problem that has been kinda solved

I am trying to create some ant build scripts for several apps. When trying to run this code:

<target name="resource-src" description="Generate the R.java file for this project's resources.">
    <exec executable="${aapt}" failonerror="true">
        <arg value="package"/>
        <arg value="-f"/>
        <arg value="-v"/>
        <arg value="-M"/>
        <arg path="../AndroidManifest.xml"/>
        <arg value="-A"/>
        <arg path="../assets"/>
        <arg value="-I"/>
        <arg path="${android_jar}"/>
        <arg value="-m"/>
        <arg value="-J"/>
        <arg path="../gen"/> <!-- Create R.java in the gen directory -->
        <arg value="-S"/>
        <arg path="../res"/>
    </exec>
</target>

I get this error:

C:\BoogerReport\builder\build.xml:76: exec returned: 1

I noticed that this app is generating multiple R.java files when using eclipse to build the project (in the gen folder). I thought android apps were only supposed to generate 1 R.java file.

1. Is this the case?

2. If not, what could be the issue?

3. Also, are these two problems related or is there something else wrong?


Below is the AndroidManifest.xml for the project in question.


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="alpha.beta.charley.delta.echo.booger.ui"
      android:versionCode="2"
      android:versionName="UnofficialBuild">
    <uses-sdk android:minSdkVersion="10" />
    <application android:icon="@drawable/booger"
        android:label="@string/app_name">
        <activity android:name=".BoogerReport"
                  android:label="@string/app_name"
                  android:configChanges="keyboardHidden|orientation"
                  android:windowSoftInputMode="stateHidden">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <intent-filter>
                <action android:name="alpha.beta.charley.delta.message.boogerreport.CREATE" />
                <category android:name="android.intent.category.DEFAULT"/>
                <category android:name="alpha.beta.charley.delta.message.category.LOCATION" /> 
            </intent-filter>
        </activity>
        <activity android:name=".BoogerReportView"
                  android:configChanges="orientation">
            <intent-filter>
                <action android:name="alpha.beta.charley.delta.message.boogerreport.OPEN" />
                <category android:name="android.intent.category.DEFAULT"/>
            </intent-filter>
        </activity>
        <activity android:name=".BoogerList" 
                  android:configChanges="orientation" /> 
    </application>
</manifest>

Additional information to answer questions asked:

Paths to the generated R.java files:

  1. alpha.beta.charley.delta
  2. alpha.beta.charley.delta.echo.booger.ui
  3. alpha.beta.charley.datamodel

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

鹿港巷口少年归 2025-01-04 16:51:00

最近的问题答案

这样做的原因是,当您将库导入 android 时,它会自动生成附加到这些库的 R.java 。所以,是的,多个 R.java 就可以了。


原始问题答案

我们找到了解决方案。有人从另一个项目导入了 R.java 文件。去掉这个导入,解决了问题。

这实际上解决了返回错误代码 1 的问题。但是,当使用 Eclipse 构建项目时,它仍然构建 3 个 R.java 文件。在主要帖子中添加有关此情况的详细信息。

The most recent problem answer

The reason why it does that is because when you import a library into android it will auto generate the R.java that are attached to those libraries. So yes, multiple R.java is fine.


Original problem answer

We found the solution. Someone had imported an R.java file from another project. Taking this import out, fixed the problem.

This actually fixed the problem where it was returning an error code of 1. However, when using Eclipse to build the project it still builds 3 R.java files. Adding details to main post about this situation.

孤独陪着我 2025-01-04 16:51:00

我的猜测是,除了您的脚本正在制作的 R.java 之外,ADT 插件还尝试生成自己的 R.java 。如果您使用 Eclipse 而不是命令行,只需使用 ADT 插件来构建您的应用程序。

My guess is that the ADT plugin is trying to generate its own R.java in addition to the R.java that your script is making. If you're using Eclipse and not the command line, just use the ADT plugin to build your app.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文