I have library project and regular android project which uses it.
Library project:
src folder package 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>
Standalone project(is an Android project and uses library project):
src folder package 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>
What I want to achieve:
ChildActivity from Android project should override ChildActivity from library project.
Compilation fails:
[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
If I change src folder in Standalone project to com.myproject.standalone and change manifest entry to
<activity android:name="com.myproject.standalone.ChildActivity">
I got exception:
android.content.ActivityNotFoundException: Unable to find explicit activity class
You don't need to declare an activity in both manifests. pick one and use it. I prefer using the app manifest for all activity declarations.
Update: Also, a library project should NEVER EVER contain references to any project that references it. That is called circular dependency.
Update: So your code is a little confusing, but it looks like you are declaring classes with the same fully qualified name in both the library and standalone projects. This won't work. They need to have different qualified names. The qualified name is the full package and class name. Your AndroidManifest for the library declares the package as "com.myproject.library" but then declares 2 activities with the package "com.myproject". If they are in the library project, change the qualified name to "com.myproject.library.ActivityName" or use the ".ActivityName" shorthand. If they are in the same package, they need to be in a different package.