Packaging model

General topics about the Android-Platform itself.
Coding issues please to the subforum right below.

Packaging model

Postby Chez » Thu Sep 04, 2008 5:06 pm

Hello droids :D

I am very newbie in Android but experienced in J2ME and J2SE. I have probably a stupid question, but its so basic and I nowhere found an exact answer to it...

1) The question is - what is the exact meaning of the manifest's 'package' attribute in AndroidManifest.xml

It is the general question but also I would like to know some particulars.. :

2) What will happen if two applications have the same activity names in the same package?

3) What will happen if two applications have different activity names in the same package (but maybe use same classes)?

4) May I keep manifest package empty and have an activity in default Java package ?

5) Is it right: all classes of every simple Android application (game) MUST reside in single package? What will happen if I export activity a.b.c.MyGame and all other classes in another packages, in the Java default package in particular?

6) What is the recommended approach to handle program versioning on Android?
    Chez
    Freshman
    Freshman
     
    Posts: 4
    Joined: Thu Sep 04, 2008 4:47 pm
    Location: Taganrog

    Top

    Re: Packaging model

    Postby plusminus » Wed Sep 10, 2008 6:29 pm

    Chez wrote:Hello droids :D

    I am very newbie in Android but experienced in J2ME and J2SE. I have probably a stupid question, but its so basic and I nowhere found an exact answer to it...

    1) The question is - what is the exact meaning of the manifest's 'package' attribute in AndroidManifest.xml

    It is the general question but also I would like to know some particulars.. :

    2) What will happen if two applications have the same activity names in the same package?

    3) What will happen if two applications have different activity names in the same package (but maybe use same classes)?

    4) May I keep manifest package empty and have an activity in default Java package ?

    5) Is it right: all classes of every simple Android application (game) MUST reside in single package? What will happen if I export activity a.b.c.MyGame and all other classes in another packages, in the Java default package in particular?

    6) What is the recommended approach to handle program versioning on Android?

      1. it is the rootpackage of your app, where for example the R.java will appear. Also Activities defined in the AndroidManifest need to be in that package or in a subpackage (thats why they all look like: ".ui.MyActivity")
      2. Like two different projects? Nothing.
      3. Same as 2.
      4. Never tested it, but thats not how it should be :!: ;)
      5. Don't know what should be different to 'normal' java apps in versioning-issues?

      Regards,
      plusminus
      Image
      Image | Android Development Community / Tutorials
      User avatar
      plusminus
      Site Admin
      Site Admin
       
      Posts: 2688
      Joined: Wed Nov 14, 2007 8:37 pm
      Location: Schriesheim, Germany

      Re: Packaging model

      Postby Xav » Thu Sep 11, 2008 2:49 am

      Chez wrote:1) The question is - what is the exact meaning of the manifest's 'package' attribute in AndroidManifest.xml

      2) What will happen if two applications have the same activity names in the same package?


      The "package" that is declared in the manifest uniquely identifies your application in the system. You cannot have two applications with the same package.

      If you have an application already installed and install a different app that declares the same package in its manifest, it will override the first application.

      You can have any number of sub packages, it doesn't matter.
      User avatar
      Xav
      Junior Developer
      Junior Developer
       
      Posts: 11
      Joined: Fri Dec 14, 2007 3:09 am
      Location: Mountain View, CA

      Re: Packaging model

      Postby Chez » Thu Sep 11, 2008 11:32 am

      Xav wrote:The "package" that is declared in the manifest uniquely identifies your application in the system. You cannot have two applications with the same package.

      If you have an application already installed and install a different app that declares the same package in its manifest, it will override the first application.

      You can have any number of sub packages, it doesn't matter.


      Thank you!
      Things became clearer for me :)
      One moment I didn't clarified still for myself: you say "You can have any number of sub packages", thats good, but what about just another packages, which are not all sub? For example, may I have classes in package a.b whereas the activity is in the package x.y.z? I assume yes, but don't know is it conflict-safe...
      Chez
      Freshman
      Freshman
       
      Posts: 4
      Joined: Thu Sep 04, 2008 4:47 pm
      Location: Taganrog

      Re: Packaging model

      Postby plusminus » Thu Sep 11, 2008 2:32 pm

      Chez wrote:
      Xav wrote:The "package" that is declared in the manifest uniquely identifies your application in the system. You cannot have two applications with the same package.

      If you have an application already installed and install a different app that declares the same package in its manifest, it will override the first application.

      You can have any number of sub packages, it doesn't matter.


      Thank you!
      Things became clearer for me :)
      One moment I didn't clarified still for myself: you say "You can have any number of sub packages", thats good, but what about just another packages, which are not all sub? For example, may I have classes in package a.b whereas the activity is in the package x.y.z? I assume yes, but don't know is it conflict-safe...


      Of course you can, but all Activities you display have to be in a subpackage of what you define the "package"-attribute in your AndroidManifest.xml .

      Regards,
      plusminus
      Image
      Image | Android Development Community / Tutorials
      User avatar
      plusminus
      Site Admin
      Site Admin
       
      Posts: 2688
      Joined: Wed Nov 14, 2007 8:37 pm
      Location: Schriesheim, Germany

      Re: Packaging model

      Postby Chez » Thu Sep 11, 2008 2:44 pm

      plusminus wrote:Of course you can, but all Activities you display have to be in a subpackage of what you define the "package"-attribute in your AndroidManifest.xml .


      Thanks!
      Chez
      Freshman
      Freshman
       
      Posts: 4
      Joined: Thu Sep 04, 2008 4:47 pm
      Location: Taganrog

      Top

      Re: Packaging model

      Postby Xav » Thu Sep 11, 2008 8:28 pm

      plusminus wrote:Of course you can, but all Activities you display have to be in a subpackage of what you define the "package"-attribute in your AndroidManifest.xml .


      Actually they don't have to.

      The name attribute of the <activity> (or receiver, provider, service) node can contain several values.

      Single segment value (e.g. "MyActivity"): this is appended to the manifest package.
      Multi-segment value (e.g. "com.company.product.MyActivity"): this is the fully qualified name of the activity class. It does not have to be a sub package of the package declared in the manifest.
      Multi-segment value, starting with a dot (e.g. ".ui.MyActivity"): this is appended to the manifest package.
      User avatar
      Xav
      Junior Developer
      Junior Developer
       
      Posts: 11
      Joined: Fri Dec 14, 2007 3:09 am
      Location: Mountain View, CA

      Re: Packaging model

      Postby plusminus » Thu Sep 11, 2008 8:49 pm

      Xav wrote:
      plusminus wrote:...Multi-segment value, starting with a dot (e.g. ".ui.MyActivity"): this is appended to the manifest package.


      :? That was what I meant :P
      Image
      Image | Android Development Community / Tutorials
      User avatar
      plusminus
      Site Admin
      Site Admin
       
      Posts: 2688
      Joined: Wed Nov 14, 2007 8:37 pm
      Location: Schriesheim, Germany

      Postby Chez » Fri Sep 12, 2008 11:54 am

      Well, some my experiences on that:
      - if the manifest's package attribute is absent, aapt fails.
      - if it is empty (i.e. package=""), the build succeeds, but when trying upload the APK to emulator it says:
      Code: Select all
      Failure [INSTALL_FAILED_INVALID_APK]

      I found out that package must have two dots or more.

      Then, I created a manifest in package "a.b.c" and activity in default package (<activity android:name="AndroidApp" .../>) And it succeeded to compile and install! :D But... when trying to run it crashed with this error message :cry: :
      Sorry! The application a.b.c (process a.b.c) has stopped unexpectedly. Please try again.
      I suspect the issue may be caused by resource access violation, isn't it? Anyways I hope you can tell me something important to help with the issue.
      [hr]
      Let me describe the reason why I am trying to use default package. I have a library (.jar) to compile into the application, w/o source code and it have "fat interface" class in the default package. I need to access it, but in Java its possible only from the class of the same default package... I can "refactor" the library using some utility like JarJar or BCEL (move it to some "named" package, thus allowing it be imported), but don't want to do that if there is a way to have an Activity in the default package.
      Chez
      Freshman
      Freshman
       
      Posts: 4
      Joined: Thu Sep 04, 2008 4:47 pm
      Location: Taganrog

      Postby Xav » Fri Sep 12, 2008 6:15 pm

      Chez wrote:I found out that package must have two dots or more.

      Then, I created a manifest in package "a.b.c" and activity in default package (<activity android:name="AndroidApp" .../>) And it succeeded to compile and install! :D But... when trying to run it crashed with this error message :cry: :
      Sorry! The application a.b.c (process a.b.c) has stopped unexpectedly. Please try again.
      I suspect the issue may be caused by resource access violation, isn't it? Anyways I hope you can tell me something important to help with the issue.


      First, I think it's two segments for the package, not two dots. "a.b" should work.

      Now, regarding your use of the default package, I don't think this is going to work. When the activity name contains only one segment, it is considered to be in the package declared in the manifest. In this case a.b.c.AndroidApp

      Looking at the logcat output may provide you with more information, but it's most likely not able to find the activity class as you created it in a different package than the manifest declaration.
      User avatar
      Xav
      Junior Developer
      Junior Developer
       
      Posts: 11
      Joined: Fri Dec 14, 2007 3:09 am
      Location: Mountain View, CA

      Top

      Return to General

      Who is online

      Users browsing this forum: Yahoo [Bot] and 4 guests