Other New feature - Manifest macros

Discussion in 'Android Questions' started by Erel, Mar 8, 2018.

  1. Erel

    Erel Administrator Staff Member Licensed User

    Manifest macros is a new feature coming in B4A v8.0.
    The origin of this feature was to help with explicitly setting the theme. As explained here: https://www.b4x.com/android/forum/threads/version-safe-themes.87694/#content the default theme can be light or dark based on the device version.

    This means that if you are not explicitly setting the theme then your app will look completely different on different devices and there is a large potential that it will not look as the you expect.

    Setting it explicitly was not so simple.
    With the new feature, the theme is set with:
    CreateResourceFromFile(Macro, Themes.LightTheme)
    CreateResourceFromFile(Macro, Themes.DarkTheme) 'this line is added to the default manifest template
    In the future, when a new theme will be available then the macros will be updated accordingly.

    This feature can also be useful in many other cases. For example instead of directly adding all firebase snippets which can add quite a mess to the manifest editor they can be added with:
    CreateResourceFromFile(Macro, FirebaseAnalytics.GooglePlayBase)
    CreateResourceFromFile(Macro, FirebaseAnalytics.Firebase)
    CreateResourceFromFile(Macro, FirebaseAnalytics.FirebaseAnalytics)
    CreateResourceFromFile(Macro, FirebaseNotifications.FirebaseNotifications)
    Anyone, and especially library developers, can easily add new macros.
    The macro file is a text file with the manifest editor code. It should be located inside a jar file (which is a regular zip file).

    Example of FirebaseAds manifest in Eclipse:


    If you are using SLC to build the library then you should put the macros in the "additional" folder.
    Note that the extension should be b4x_excluded. This way the IDE knows not to include the macros in the APK.

    You can add multiple macros inside your library.

    Themes.jar which holds the theme macros looks like:

    Last edited: Mar 8, 2018
  2. Multiverse app

    Multiverse app Active Member Licensed User

    That is great! when will B4A v8.0 come out?
  3. DonManfred

    DonManfred Expert Licensed User

    A beta next week
    Multiverse app likes this.
  4. corwin42

    corwin42 Expert Licensed User

    Is there any way to see what macros are available? There is no code completion or anything for the macros. So the only way to find out what macros are available is to look into the library .jar files to see the .b4x_excluded files.
    Vincenzo Fabiano likes this.
  5. Erel

    Erel Administrator Staff Member Licensed User

  6. sorex

    sorex Expert Licensed User


    I'm sorry to say it but the instruction are not clear enough for me :(

    I have a jar file that just contains 3 sub dirs (test app package name) and a class file in the 3rd folder

    So the structure is not like in the screenshot above.

    I added my libname.b4x_excluded file to the jar's root, refreshed and at compile it gives a "error parsing manifest file - Invalid macro file" error.

    The code in the app manifest file that I uses was

    CreateResourceFromFile(Macro, libraryname)

    What is the relation between the above command, the library and the to be selected manifest file in the jar? As you wrote you can have multiple ones inthere.
  7. DonManfred

    DonManfred Expert Licensed User

    based on your post i guess
    should have been
    CreateResourceFromFile(Macro, libraryname.libname)
    where libraryname is the name of the Library and the libname is the libname.b4x_excluded file in the jar.

    Example from #1

    CreateResourceFromFile(Macro, FirebaseNotifications.FirebaseNotifications)
    It is the file FirebaseNotifications.jar/FirebaseNotifications.b4x_excluded


    CreateResourceFromFile(Macro, Themes.LightTheme)
    It is the file Themes.jar/LightTheme.b4x_excluded
  8. sorex

    sorex Expert Licensed User

    I figure it out.

    This method doesn't allow us to use

    CreateResourceFromFile(Macro, FirebaseAnalytics.GooglePlayBase)
    inside the .B4X_excluded file

    when I move that line to the app manifest it works fine.
  9. sorex

    sorex Expert Licensed User

    yes, Don it's libraryname.manifestfilename I had that line changed aswell.
  10. DonManfred

    DonManfred Expert Licensed User

    i think the issue is here
    It is not recursive
  11. Erel

    Erel Administrator Staff Member Licensed User

    That's true.
  12. lerneBasic4Android

    lerneBasic4Android Member Licensed User


    Is it possible to use this feature with b4xlib-Libraries?

    In multiple of my projects I use a b4xlib-library that is based on FileProivder and extends it. I would love to provide all the required manifest text for FileProvider inside this b4xlib and include it with the macro feature to the manifest of my projects instead of copying it manually and updating it manually if a change in the b4xlib-library makes it necessary.

  13. Erel

    Erel Administrator Staff Member Licensed User

    You will need to create a jar with the macro and a small XML file with the declaration. The "extra lib" can be referenced from the b4xlib.
    lerneBasic4Android likes this.
  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