Dori
Dori

Reputation: 18423

Java Package names and conflicts

a simple question but Ive realised im not sure of the answer for this one....

If I am creating an android application with a library package named

com.example.one

and then i create another app and include another package with the name

com.example.one

which has a slightly refactored class, could this cause any problems in either of the apps?

The reason i ask is recently I had a problem with some google source code and it was down to the fact that a device manufactorer had included the same libs in the custom OS that I had used in my apk, and it was not happy! (or so i was told)

If anyone can fill me in here, as i obviosuly dont understand something quite findamental here :)

thankx

EDIT: a good link on the diff between Android and Java package names http://blog.javia.org/android-package-name/

Upvotes: 2

Views: 1060

Answers (4)

KevinDTimm
KevinDTimm

Reputation: 14376

Yes, this can cause problems, but only if you have classnames that conflict within the package.

This doesn't seem to be an issue with your app though as you have two apps and two libraries (see answer from LordT)

Upvotes: 3

aksarben
aksarben

Reputation: 41

Any easy workaround is to include the the app/library name in the package. For example:

com.app1.example.one
com.app2.example.one

That eliminates confusion & interference between the two packages.

Upvotes: 0

Bozho
Bozho

Reputation: 597402

The classloader can't load two versions of the same class. It picks just one. But which one gets picked is undefined. So yes - it causes troubles.

Some platforms (java-ee) have options to specify jar precendence for these cases. I don't know about android.

Update: If my initial understanding is not correct, i.e. you are not having the same jar (library) twice on the classpath, but instead are starting 2 separate apps with different versions of the jar - then they won't interfere with each other (and hence no problems)

Upvotes: 4

Blitz
Blitz

Reputation: 5671

Actually, it shouldn't cause problems in the case of two separate Android apps. Android Apps run in Sandboxes, i.e. the Classloader of app A does not see any classes of app B and vice-versa. This is obviously different for system wide-libraries. They are accessible by the classloader (of course) and will cause troubles if you have the same class in your app.

Upvotes: 3

Related Questions