1. Download our Official Android App: Forums for Android!

Apps Packing resources in android library

Discussion in 'Android Development' started by Zerjillo, Apr 30, 2012.

  1. Zerjillo

    Zerjillo Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    3
    Joined:
    Apr 30, 2012

    Apr 30, 2012
    3
    0
    5
    Hi all

    I'm developing an Android library that can be reused in future apps. The library does use several resources (mainly some small icons). I would like them to be packaged in the library jar file. However, when I activate the option that makes the project a library one, everything gets compiled, compressed in the jar, but the images are not included in the jar file.

    Googling I've found some messages that suggest that you should put those images in the res directory in every new project that uses the library, but that solution seems a little bit odd and could probably induce some errors.

    So, is there some easy (or maybe not so easy) way to include those images in the jar file and that they are directly used by the classes in the library?

    Thanks for your time.
     

    Advertisement

  2. jonbonazza

    jonbonazza Android Expert
    Rank:
    None
    Points:
    163
    Posts:
    1,930
    Joined:
    Jul 13, 2010

    Jul 13, 2010
    1,930
    457
    163
    Male
    I am pretty sure that you cannot package resources with a library. Thats definitely how it is for Java and I believe ig you try to package them with Android, you will end up with import errors
     
  3. Zerjillo

    Zerjillo Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    3
    Joined:
    Apr 30, 2012

    Apr 30, 2012
    3
    0
    5
    Hi and thanks for your answer.

    As you suggest it seems that in Android you may not be able to package the resource file in the jar file but this is not the general case for Java. I've done several different Java projects (not related to Android) and all the images that I've used in those projects have been packaged into the jar file and worked flawlessly.

    I do not know why it is different with Android but, as it seems to be... what would be the better option to distribute the library? A compressed file in which I pack the jar file and the res folder and a README file with simple instructions about where to place the resources and jar file?

    Best regards.
     
  4. jonbonazza

    jonbonazza Android Expert
    Rank:
    None
    Points:
    163
    Posts:
    1,930
    Joined:
    Jul 13, 2010

    Jul 13, 2010
    1,930
    457
    163
    Male
    Resources are packaged in the jar file in java and in the apk file in Android, but when you make a library build, I don't think you can pack resources in there. Building a library JAR is different from building an executable JAR or an executable APK.

    I do know that in the past, I have created libraries for android and I compiled them as non-executable jars, but if I tried to including anything other than the src directory, it would not import correctly as the compiler doesn't know what to do with the other directories (such as res).
     
  5. Zerjillo

    Zerjillo Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    3
    Joined:
    Apr 30, 2012

    Apr 30, 2012
    3
    0
    5
    Ok thanks for your answer. I've not found any particular reason why it cannot be done, but it seems it cannot be done.

    Thanks for your time.
     

Share This Page

Loading...