我有使用它的库项目和常规 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