Android Tutorial Manifest Editor

Basic4android v1.8 introduces a new tool named Manifest Editor.
Every Android application includes a file named AndroidManifest.xml.
This is an XML file that describes the application for the OS. It includes elements such as the application components (activities, services and receivers), icons, permissions and other required information.
You can see more information about this file here: The AndroidManifest.xml File | Android Developers

Basic4android compiler generates this file automatically. In most cases there is no need to change anything. However in some cases, especially when using third party libraries (ads for example), the developer is required to add some elements to the manifest file.

Until version 1.8 the solution was to mark the manifest file as read-only or check the "Do not write manifest file" option and prevent the compiler from recreating this file during compilation.
This however means that from now on, the developer needs to maintain the manifest file and update it when the project is updated.

The new manifest editor solves the above issue. It allows developers to add or modify elements in the manifest while also allowing the compiler to add the standard elements.

Choosing Project - Manifest Editor will open the editor:

SS-2012-01-08_12.46.34.png


As shown in the above screenshot the editor starts with several default elements.
You can modify these elements or add other elements as needed.
To make it easier to add multiline strings and strings that contain quote characters the manifest editor treats all characters between the open parenthesis and the closing parenthesis or comma (for commands with multiple parameters) as a single string.

Escaping end of string characters
If you need to write a string with a comma you should write two commas: ,,
The same thing is true for strings with closing parenthesis: ))

Editor commands
There are several types of commands: commands that add an additional text inside an element, commands that set the value of an attribute (replacing the old value if it already exists) and two other commands which will be discussed later.

List of commands

Add text commands

For example the AdMob library requires us to add an activity to the manifest file:
SS-2012-01-08_12.58.24.png


The result is that this text is added under the 'application' element:
SS-2012-01-08_12.59.27.png


Note that you can call 'add text' commands multiple times.

AddActivityText / AddServiceText / AddReceiverText - expect two parameters: component name and the text to add.
For example to use C2DM push framework you should add some text to the receiver. Note that a Service module in Basic4android is actually made of a native service and a native receiver. The name of the receiver is the same as the service module.
AddReceiverText(PushService,
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="anywheresoftware.b4a.samples.push" />
</intent-filter>
<intent-filter>
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="anywheresoftware.b4a.samples.push" />
</intent-filter>)

Other "add text" commands: AddApplicationText and AddManifestText. Both expect a single parameter which is the text to add.

Set attribute commands
For example the following command can be used to set the orientation of a specific activity:
SetActivityAttribute(Main, android:screenOrientation, "portrait")

Note that the attributes keys are case sensitive.

SetActivityAttribute / SetReceiverAttribute / SetServiceAttribute - expect three parameters: component name, attribute key and attribute value.
SetManifestAttribute / SetApplicationAttribute - expect two paramters: attribute key and attribute value.

Other commands
AddReplacement - this method allows you to declare a string that will be replaced with a second string. The compiler automatically adds the following declarations: $PACKAGE$ (replaced with the package name), $LABEL$ (replaced with the application label) and $ORIENTATION$ (replaced with the orientation value).
The string replacement happens as the last step. You can use it to delete other strings by replacing them with an empty string.
Syntax: AddReplacement (OldString, NewString)

AddPermission - Adds a permission if it doesn't already exist. You can also add permissions using AddApplicationText. The advantage of AddPermission is that it makes sure to only add each permission once.

Syntax: AddPermission (Permission)
Example: AddPermission (android.permission.INTERNET)

RemovePermission - Removes a permission. Same syntax as AddPermission.

CreateResource - Creates a XML resource file: https://www.b4x.com/android/forum/threads/new-feature-three-birds-with-one-stone.63127/#post-398974

Tips
- Deleting the whole text will restore the default text (after you reopen the manifest editor).
- As written at the beginning, in most cases you do not need to add anything to the manifest editor.
- Open AndroidManifest.xml to better understand how it is built.
- The "Do not modify manifest file" option is still available for backwards compatibility. It is recommended to use the new editor instead.
 
Last edited:

Roy Raymundo

Member
Licensed User
Longtime User
The numbers are based on the API version. 5 means Android 2.0.

The default manifest code sets the minimum version to Android 2.0 and the target version to Android 4.0. Your app will work on all devices running Android 2.0+ and will use Android holo theme by default (on Android 4+ devices).
May I edit this to minimum sdk = 14 and target SDK = 16?
There won't be any problem with that?
 

Gaver Powers

Member
Licensed User
Longtime User
Where is the manifest package name obtained from?
Reference:
B4X:
<manifest
    xmlns:android="http://schemas.android.com/apk/res/android"
    package="flashlight.gaver"
    android:versionCode="4"
    android:versionName="1.3"
    android:installLocation="internalOnly">

Trying to upload same apk to different store on Google Play and it (apparently) knows there's a duplicate there by looking at this package name.

G
 

moster67

Expert
Licensed User
Longtime User
Probably I am doing something wrong using the manifest editor but I am unable to add android:configChanges="orientation|screenSize" to my main activity (the launcher activity).

I tried adding this in the manifest editor:

B4X:
'xx
AddApplicationText(
<activity android:name="b4a.example.main"
android:configChanges="orientation|screenSize"/>
)
'End of xx

or like this:

B4X:
'xx
AddApplicationText(
<activity android:name=".main"
android:configChanges="orientation|screenSize"/>
)
'End of xx

but it does not end up in the right place (it creates a separate entry).

I want to add the android:configChanges so it ends up here:

B4X:
<activity
            android:windowSoftInputMode="stateHidden"
            android:launchMode="singleTop"
            android:name=".main"
            android:label="B4A vlc sample"
            android:configChanges="orientation|screenSize"
            android:screenOrientation="unspecified">
            <intent-filter>
               <action android:name="android.intent.action.MAIN" />
               <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
           
        </activity>

What I am doing wrong?

In the meantime, I am setting the manifest file as read-only but I prefer not.
 

wstein25

Member
Licensed User
Google insists on version numbers for revisions. Their example is:

<?xml version="1.0" encoding="utf-8"?><manifestxmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.package.name"
android:versionCode="2"
android:versionName="1.1">
<applicationandroid:icon="@drawable/icon"android:label="@string/app_name">
...
</application></manifest>


How exactly should this be inserted using the Manifest editor. Thanks from a newbie !

Bill
 

Misterbates

Active Member
Licensed User
Basic4android v1.8 introduces a new tool named Manifest Editor.
Every Android application includes a file named AndroidManifest.xml.
This is an XML file that describes the application for the OS. It includes elements such as the application components (activities, services and receivers), icons, permissions and other required information.
You can see more information about this file here: The AndroidManifest.xml File | Android Developers

...

Other commands
AddReplacement - this method allows you to declare a string that will be replaced with a second string. The compiler automatically adds the following declarations: $PACKAGE$ (replaced with the package name), $LABEL$ (replaced with the application label) and $ORIENTATION$ (replaced with the orientation value).
The string replacement happens as the last step. You can use it to delete other strings by replacing them with an empty string.
Syntax: AddReplacement (OldString, NewString)

I'm looking for a way to have two versions of my app on my device - a stable version and the current unstable (development) version. To do this, they two versions need unique package names. An easy solution seems to be to append .dev to the package name when compiling in DEBUG mode using conditional compilation.

I tried to use:
B4X:
AddReplacement($PACKAGE$, $PACKAGE$.dev)
but the resulting manifest contains the first line below when what I wanted was the second line
B4X:
package="$PACKAGE$.dev"
package="ScB.MisterBates.IntervalsPlus.dev"

Can I use the manifest editor to append .dev to the package name?
 

Misterbates

Active Member
Licensed User
Why does the first line below work, while the second gives me an error?
B4X:
SetManifestAttribute(package, "$PACKAGE$")
SetManifestAttribute(package, "$PACKAGE$.dev")

Error is:
B4A version: 6.80
Parsing code. (0.05s)
Compiling code. (0.20s)
Compiling layouts code. (0.00s)
Organizing libraries. (0.00s)
Running custom action. (0.31s)
Generating R file. (0.08s)
Compiling debugger engine code. (2.88s)
Compiling generated Java code. Error
javac 1.8.0_131
javac: file not found: gen\see\manifesteditor\R.java
Usage: javac <options> <source files>
use -help for a list of possible options

This error usually happens when you save the project under a restricted folder such as "Program Files".
 

Misterbates

Active Member
Licensed User
Top