Java Question Question about ressources

Discussion in 'Libraries developers questions' started by corwin42, Mar 16, 2015.

  1. corwin42

    corwin42 Expert Licensed User

    I have wrapped an Android library (FloatingActionBar Library) with ressources.

    The package name of the library is de.amberhome.objects.floatingactionbutton so I add the ressources to a B4A project with:
    #AdditionalRes: C:\Users\stm\Dropbox\Basic4Android\CustomLibsRes\b4a_floatingactionbutton, de.amberhome.objects.floatingactionbutton
    The library references a drawable named "shadow" so there are several shadow.png files in the res/drawable-xxxx folders of the library.

    I have thought that because of the package name the library will always use the drawables from its corresponding ressource folder.

    Now a user has added some resource files to the projects Objects/res/drawable-xxx folders (read only). Unfortunately he added a shadow.png file there. Now the library started to use the wrong resource file from the Objects/res path and not from the res path given with the #AdditionalRes attribute.

    Why? I really thought that because of the package name always the right resource file would be used. With this behavior in mind it may give conflicts if many libraries are added with resources and two libraries have resource files with the same name.
    nadhiras likes this.
  2. Erel

    Erel Administrator Staff Member Licensed User

  3. DonManfred

    DonManfred Expert Licensed User

    Watching the thread... I´m interested in the answer too ;)
  4. corwin42

    corwin42 Expert Licensed User


    After searching a bit this is expected behavior. The story behind this is that a developer should be able to replace the libraries resources to customize the look and feel of his app.

    If I correctly understand there are two build systems now for Android. The new one which uses Gradle and the "old" one. B4A uses the "old" one and there is no option to change this resource merging behavior.

    I just played with it a bit more. If I use a project resource folder in the project home that I include with
    #AdditionalRes: ..\resource
    everything seems to be fine and the library uses the resource from the correct folder. Only if I put the resrouces to Objects\res folder and make them read only the library resources get overwritten.

    Edit: If I do the #AdditionalRes: ..\resource (with the wrong shadow) below the #AdditionalRes of the library, it works and the library uses the correct resources. If I place the #AdditionalRes: ..\resource line BEFORE the #AdditionalRes of the library the wrong resource is used. I would have expected it the other way that resources that are specified at the end will overwrite the resources placed on top. Seems to be the other way.

    @Erel can we see, how these resource folders are added somewhere in a logfile?
    Last edited: Mar 17, 2015
  5. Troberg

    Troberg Well-Known Member Licensed User

    The simple solution, in my mind, is to name things so that such clashes are unlikely. In your case, name all your resources something like FloatingActionBar_Shadow.png.

    Then, the user still has the option to replace it, but the chance of an accidental clash is more or less eliminated.
  6. corwin42

    corwin42 Expert Licensed User

    Yes, thats what Google recommends, too
    Troberg likes this.
  7. Erel

    Erel Administrator Staff Member Licensed User

    This information is not logged.

    All of the folders are added as arguments to aapt.exe. The first one is the internal res folder and then all the other AdditionalRes folders.

    Based on you tests aapt.exe sets the highest priority for the first folders.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice