Other New feature - Manifest macros

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:
B4X:
CreateResourceFromFile(Macro, Themes.LightTheme)
'Or
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:
B4X:
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:

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.
 

sorex

Expert
Licensed User
hello,

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.
 

DonManfred

Expert
Licensed User
based on your post i guess
CreateResourceFromFile(Macro, libraryname)
should have been
B4X:
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

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

or

B4X:
CreateResourceFromFile(Macro, Themes.LightTheme)
It is the file Themes.jar/LightTheme.b4x_excluded
 

sorex

Expert
Licensed User
I figure it out.

This method doesn't allow us to use

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

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

sorex

Expert
Licensed User
yes, Don it's libraryname.manifestfilename I had that line changed aswell.
 

lerneBasic4Android

Member
Licensed User
Hi,

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.

Thanks,
Thomas
 
Top