Android Tutorial Modules Attributes

Basic4android v2.50 includes a new method for handling project and modules settings.

These settings are now set in the code itself. The menu items were removed.

SS-2012-12-31_13.38.49.png


The attributes syntax is simple. The hash sign (#) followed by the attribute name, a colon and the value.
Some attributes can appear more than once in the same module.

Different modules (activities, services, ...) support different attributes. The IDE will show a list with the supported attributes when you press on the hash key.

The project related attributes should be placed in the main activity.
Note that the #Region / #End Region directives are not required.

The attributes will be added automatically to existing projects when they are first loaded with the new version.

The purpose of this feature is to make it simpler to support new features that require advanced settings.

Project attributes (should be placed in the main activity)
  • CanInstallToExternalStorage - Whether the application can be installed to the external storage. Values: True or False
  • SupportedOrientations - Sets the supported orientations. Values (case is important): unspecified, portrait or landscape (other possible values)
  • ApplicationLabel - The application label that will appear in the applications list (string)
  • VersionName - Version name (string)
  • VersionCode - Version code. Must be an integer
  • Library compilation attributes. Covered in the library compilation tutorial
  • CustomBuildAction - See the Custom Build Actions section in this tutorial.
  • AdditionalRes - Specifies a folder with resource files. These resource files will be added to the APK. This attribute also accepts an optional parameter, the package name of an Android library project. This is required when wrapping a library that includes resource files. See this example: jfeinstein10 SlidingMenu libraryYou can use this attribute multiple times.
  • DebuggerForceFullDeployment - Forces the rapid debugger to redeploy the complete project every compilation. This can be useful if you see slow performance after modify the code. It will disable the quick redeployment feature of the rapid debugger.
    Values: True or False.
  • DebuggerForceStandardAssets - Disables the virtual assets feature of the rapid debugger. By default the rapid debugger doesn't use the standard assets folder. This allows the debugger to only redeploy updated files. Values: True or False.
  • ExcludeClasses - Can be used to strip library classes during compilation: https://www.b4x.com/android/forum/threads/new-feature-three-birds-with-one-stone.63127/

Activity attributes
  • FullScreen - Whether to show the top bar. Values: True or False
  • IncludeTitle- Whether to show the title. Values: True or False

Service attributes
  • StartAtBoot - Whether this service should start automatically after boot. Values: True or False
  • StartCommandReturnValue - (advanced) Sets the value that will be returned from onStartCommand. The default value is android.app.Service.START_NOT_STICKY. See this link for the possible values.

All modules support the following attributes:
  • ExcludeFromDebugger - Whether to exclude this module from the debugger. Debug information will not be added to this module. Values: True or False
    This attribute is only relevant to the legacy debugger.
  • IgnoreWarnings - A list of warnings numbers that will be ignored in this module.

Custom Build Actions

The build process is made of a number of steps. You can add additional steps that will run as part of the build process. For example you can run a batch file that will copy the latest resource files from some folder before the files are packed.

Another example. You can use this code to mark all files under res folder as read-only (and prevent the compiler from deleting them):
B4X:
#CustomBuildAction: 1, c:\windows\system32\attrib.exe, +r res\*.* /s

Note that you can add any number of build actions.
CustomBuildAction should be added to the main activity.
The running folder is set to the program objects folder.
The syntax is:
<step id>, <program to run>, <program arguments>

step id can be one of the following:
1 - Before the compiler cleans the objects folder (it happens after the code is parsed).
2 - Before R.java file is generated.
3 - Before the package is signed (the APK file at this point is: bin\temp.ap_).
4 - Before the APK is installed.
5 - After the APK is installed.
6 (new in v5.01) - After Java compilation.
 
Last edited:

dclarkchem

Member
Licensed User
I have tried every combination (and different browsers) of the above code and the Android publishing site at google.play keeps giving me this error:

You need to use a different version code for your APK because you already have one with version code 1.

This s what I have in the main module:


#Region project attributes
#VersionCode: 2
#End Region

Do I need to change the version code somewhere else?
 

jgmdavies

Member
Licensed User
I haven't got time to check, but maybe the first line is case-sensitive?

#Region Project Attributes

HTH
Jim
 

AscySoft

Active Member
Licensed User
So, let's say I want a "history.txt" file to be copied in Files folder before step3.
And I have a new history.txt on my hdd at "C:\Changes\history.txt" location.

Using Custom build action, how should I write the syntax?
 

AscySoft

Active Member
Licensed User
Thanks.
Meanwhile I figure that if I import the text file with IDE FIles>Add File, then I could just easily edit this file from explorer/notepad and save it.
When program is compiled, the new file is correctly displayed.

Is the above procedure "wrong"? Or should I use new Custom Build Action?
 

JTmartins

Active Member
Licensed User
(WHISH) Exclude from compile

I just came across a situation, where it would be very useful to have a directive to exclude a particular module from compilation.

I have lot's of code, there, that I know it's correct and fully tested, and now I'm slowly integrating that code in the main project.

I loaded it as it's easier than have 2 instances of the B4A open...But can't compile, due to several errors...which are not real errors...

I just don't want that module to be compiled...It's not supposed to.

Apparently there is no way to do that besides removing, the module...Which as not my favorite solution.

I can also comment out the lines...but then everything becomes green...a little confusing !!

Thanks

José
 
Last edited:

Roger Garstang

Well-Known Member
Licensed User
Any plans for an auto complete, so after we type the : it gives us the available options for that field? This would mostly be for the Orientations field and possibly True/False and others.

The comment line of- ['SupportedOrientations possible values: unspecified, landscape or portrait.] isn't added to existing files either, only new.
 
Last edited:

DouglasR

Member
Licensed User
More non-BASIC to remember...oh joy.

I am becoming less and less a fan of b4a.:sign0148: Everytime I do almost anything, i have to look up how to do it as opposed to just relying on my BASIC knowledge. Maybe someone ought to write an interpreter to convert VB6 into b4a?:BangHead:
 

Mike Maurice

Member
Licensed User
Custom Build Action fails.

#CustomBuildAction: 1, c:\Program Files (x86)\Git\bin\git.exe, describe --tags>gitv.txt


The following line executes without problems --- c:\Program Files (x86)\Git\bin\git.exe, describe --tags>gitv.txt

When used in a CustomBuildAction the: --tags>gitv.txt
is not passed properly to git.

Here is the error:
error: unknown option `tags>gitv.txt'

If the redirection is removed, it seems to work ok.
 

Erel

Administrator
Staff member
Licensed User

Chelu

Member
Licensed User
Subversion number

Can not be used with subversion number?
For example:
3.1
2.7
1.3.7
 

bishmedia

Member
Licensed User
Orientation Issue

I have started a new module which opens a new activity which i want only to open in landscape, but when i add #SupportedOrientations: landscape i get an error..

B4X:
#Region  Activity Attributes 
   #FullScreen: False
   #IncludeTitle: True
   #SupportedOrientations: landscape
#End Region

Parsing code. Error
Error parsing program.
Error description: Attribute not supported: supportedorientations
Occurred on line: 4
#SupportedOrientations: landscape

How can i get a new activity window outside Main to load in Landscape only??
 
Top