0

我有使用它的库项目和常规 android 项目。

图书馆项目:

src 文件夹包com.myproject

MainActivity
ChildActivity

AndroidManifest.xml

 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.project.library">
        <uses-sdk android:minSdkVersion="8" />
        <application>
            <activity android:name="com.myproject.MainActivity">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
            <activity android:name="com.myproject.ChildActivity">
            </activity>
        </application>
 </manifest>

独立项目(是一个Android项目,使用库项目):

src 文件夹包com.myproject

ChildActivity

AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.project">
        <uses-sdk android:minSdkVersion="8" />
        <application>
            <activity android:name="com.myproject.MainActivity">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
            <activity android:name="com.myproject.ChildActivity">
            </activity>
        </application>
</manifest>

我想要达到的目标:

Android 项目中的 ChildActivity 应覆盖库项目中的 ChildActivity。

编译失败:

[2012-10-16 20:02:02 - Standalone] Dx 
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.IllegalArgumentException: already added: Lcom/myproject/ChildActivity;
[2012-10-16 20:02:02 - Standalone] Dx   at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:123)
[2012-10-16 20:02:02 - Standalone] Dx   at com.android.dx.dex.file.DexFile.add(DexFile.java:163)
[2012-10-16 20:02:02 - Standalone] Dx   at com.android.dx.command.dexer.Main.processClass(Main.java:486)
[2012-10-16 20:02:02 - Standalone] Dx   at com.android.dx.command.dexer.Main.processFileBytes(Main.java:455)
[2012-10-16 20:02:02 - Standalone] Dx   at com.android.dx.command.dexer.Main.access$400(Main.java:67)
[2012-10-16 20:02:02 - Standalone] Dx   at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:394)
[2012-10-16 20:02:02 - Standalone] Dx   at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:135)
[2012-10-16 20:02:02 - Standalone] Dx   at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:191)
[2012-10-16 20:02:02 - Standalone] Dx   at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:123)
[2012-10-16 20:02:02 - Standalone] Dx   at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:191)
[2012-10-16 20:02:02 - Standalone] Dx   at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:123)
[2012-10-16 20:02:02 - Standalone] Dx   at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:191)
[2012-10-16 20:02:02 - Standalone] Dx   at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:123)
[2012-10-16 20:02:02 - Standalone] Dx   at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:191)
[2012-10-16 20:02:02 - Standalone] Dx   at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:123)
[2012-10-16 20:02:02 - Standalone] Dx   at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:109)
[2012-10-16 20:02:02 - Standalone] Dx   at com.android.dx.command.dexer.Main.processOne(Main.java:418)
[2012-10-16 20:02:02 - Standalone] Dx   at com.android.dx.command.dexer.Main.processAllFiles(Main.java:329)
[2012-10-16 20:02:02 - Standalone] Dx   at com.android.dx.command.dexer.Main.run(Main.java:206)
[2012-10-16 20:02:02 - Standalone] Dx   at sun.reflect.GeneratedMethodAccessor64.invoke(Unknown Source)
[2012-10-16 20:02:02 - Standalone] Dx   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[2012-10-16 20:02:02 - Standalone] Dx   at java.lang.reflect.Method.invoke(Method.java:597)
[2012-10-16 20:02:02 - Standalone] Dx   at com.android.ide.eclipse.adt.internal.build.DexWrapper.run(DexWrapper.java:180)
[2012-10-16 20:02:02 - Standalone] Dx   at com.android.ide.eclipse.adt.internal.build.BuildHelper.executeDx(BuildHelper.java:703)
[2012-10-16 20:02:02 - Standalone] Dx   at com.android.ide.eclipse.adt.internal.build.builders.PostCompilerBuilder.build(PostCompilerBuilder.java:577)
[2012-10-16 20:02:02 - Standalone] Dx   at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:728)
[2012-10-16 20:02:02 - Standalone] Dx   at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
[2012-10-16 20:02:02 - Standalone] Dx   at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:199)
[2012-10-16 20:02:02 - Standalone] Dx   at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:321)
[2012-10-16 20:02:02 - Standalone] Dx   at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:396)
[2012-10-16 20:02:02 - Standalone] Dx   at org.eclipse.core.internal.resources.Project$1.run(Project.java:618)
[2012-10-16 20:02:02 - Standalone] Dx   at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2344)
[2012-10-16 20:02:02 - Standalone] Dx   at org.eclipse.core.internal.resources.Project.internalBuild(Project.java:597)
[2012-10-16 20:02:02 - Standalone] Dx   at org.eclipse.core.internal.resources.Project.build(Project.java:124)
[2012-10-16 20:02:02 - Standalone] Dx   at com.android.ide.eclipse.adt.internal.project.ProjectHelper.doFullIncrementalDebugBuild(ProjectHelper.java:1000)
[2012-10-16 20:02:02 - Standalone] Dx   at com.android.ide.eclipse.adt.internal.launch.LaunchConfigDelegate.launch(LaunchConfigDelegate.java:147)
[2012-10-16 20:02:02 - Standalone] Dx   at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:855)
[2012-10-16 20:02:02 - Standalone] Dx   at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:704)
[2012-10-16 20:02:02 - Standalone] Dx   at org.eclipse.debug.internal.ui.DebugUIPlugin.buildAndLaunch(DebugUIPlugin.java:1047)
[2012-10-16 20:02:02 - Standalone] Dx   at org.eclipse.debug.internal.ui.DebugUIPlugin$8.run(DebugUIPlugin.java:1251)
[2012-10-16 20:02:02 - Standalone] Dx   at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
[2012-10-16 20:02:02 - Standalone] Dx 1 error; aborting
[2012-10-16 20:02:02 - Standalone] Conversion to Dalvik format failed with error 1

如果我将独立项目中的 src 文件夹更改为 com.myproject.standalone 并将清单条目更改为

<activity android:name="com.myproject.standalone.ChildActivity">

我有例外:

android.content.ActivityNotFoundException: Unable to find explicit activity class
4

1 回答 1

0

您无需在两个清单中声明活动。选择一个并使用它。我更喜欢将应用清单用于所有活动声明。

更新:此外,图书馆项目永远不应该包含对任何引用它的项目的引用。这称为循环依赖。

更新:所以你的代码有点混乱,但看起来你在库和独立项目中声明了具有相同完全限定名称的类。这行不通。它们需要具有不同的限定名称。限定名是完整的包名和类名。您的库的 AndroidManifest 将包声明为“com.myproject.library”,但随后使用包“com.myproject”声明了 2 个活动。如果它们在库项目中,请将限定名称更改为“com.myproject.library.ActivityName”或使用“.ActivityName”简写。如果它们在同一个包中,则它们需要在不同的包中。

于 2012-10-16T17:38:22.470 回答