Showpath
Showpath

Reputation: 678

Android library with same package name

I have a main app with a package name: com.company.package

and I have a library with a package name: com.company.package.librarypackage

In my main manifest file I've put:

<activity
      android:configChanges="orientation"
      android:name="com.company.package.librarypackage.classA"
      android:screenOrientation="landscape" >
</activity>

I've also tried:

<activity
      android:configChanges="orientation"
      android:name=".librarypackage.classA"
      android:screenOrientation="landscape" >
</activity>

However my code is currently crashing with message:

java.lang.NoClassDefFoundError: com.company.package.librarypackage.classA

I wonder then if it's possible to have library which share a part of it's package name with the main app.

Any suggestion?

Thanks!

Upvotes: 1

Views: 3672

Answers (4)

Showpath
Showpath

Reputation: 678

Solved. There was a Jar file dependency missing in the buildPath. Sorry for bothering...

Upvotes: 0

jjNford
jjNford

Reputation: 5270

You only need to extend the base package in your manifest.... so just use

<activity
      android:configChanges="orientation"
      android:name=".librarypackage.classA"
      android:screenOrientation="landscape" >
</activity>

Don't forget the "."

UPDATE

You also need to set the intent-filter and action/category. If you want this to be your default activity you would need:

<activity
      android:configChanges="orientation"
      android:name=".librarypackage.classA"
      android:screenOrientation="landscape" >
      <intent-filter>
          <action android:name="android.intent.action.MAIN" />
          <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
</activity>

If you are calling the activity with an intent you would need to specify this in the name attribute.

Here is a reference...

Upvotes: 1

Ted Hopp
Ted Hopp

Reputation: 234795

The activity needs to be declared in the manifest for the main app. Declaring it in the manifest for the library is useless.

The package name for the library and the main app can be the same.

Note that the class for an activity does not need to be in the application package or a sub-package. (You can abbreviate the manifest a bit if it is, but this is not a requirement.) Be sure that classA is actually part of the specified package.

Upvotes: 0

wnafee
wnafee

Reputation: 2136

If your main app package is com.company.package, then if you should remove that from your activity manifest xml. It should be:

android.name=".librarypackage.classA"

rather than what you have above...

Upvotes: 1

Related Questions