Guide to the Android Manifest

Written by:  • Edited by: Simon Hill
Updated Jul 1, 2010
• Related Guides: Android | Google Android Programming | Configuration File

In this article we will try to understand a bit more about the meaning and the whys of the lines we put in the AndroidManifest.xml file, in our Android project.

In many of the articles I have written, the AndroidManifest.xml file has appeared in some way. Well, it's a very important part of the Android application, so I'm going to gather all the information and experience I have to write about “The Manifest”.

When you create a new android application in your favorite IDE (better using Eclipse for now, in other articles I will write about how to configure another IDE to work with Android), we will have the AndroidManifest.xml in our project folder. It's automatically generated by Eclipse, so we don't have to bother about creating it by ourselves. Let's have a look at the file, inside of it, you will find something that looks like this:

AndroidManifest
click to enlarge

As the main element we have the “manifest” tag, then, inside of it we have other elements, like “application”, “uses-sdk” and “uses-permission”.

This is the most simple AndroidManifest file you will find, in larger applications, this file could have lots of code lines, we will see why.

The AndroidManifest file is the configuration file of our application, here we set the Activities we are going to use (and how are they going to be used), the services we are going to set up in the Application, the version of the SDK we are using (this is a new feature in the 1.5 Cupcake version), and which permissions the application needs to make it work.

These are the most important elements, from my point of view, of the AndroidManifest file. There are lots more, but for now, we will focus on these 3:

Application, Permissions and Version

Application

The tag <application> is contained inside the “root” xml element: <manifest>. Here, using some attributes, we can define some parameters of the Android application. Let's have a look at some of them:

android:icon="drawable resource" → We can set the icon of the application. This will be shown when you install it in your Android device.

android:name="string" → This attribute is to name our Android application, this string, will appear with the icon above when you install it on a device.

android:theme="resource or theme" → We can create a general theme, and use it in all applications. In other articles we will see how to create themes.

There are more attributes inside of this element, if you are interested you can check Google Android Manifest information. Inside the <application> tag, we can have more elements like:

activity, service, provider...

I would like to explain a bit deeper what attributes can be used in these elements, but it will be done in the next article. For now, just keep in mind that every new Activity, Service or Content Provider we create in our application, has to be put here. If not, the application won't recognize it.

Permissions

Inside the <manifest> tag we can have the <users-permission> tag. This is used to define the features the application needs to access and the user needs to grant:

-Recieve SMS

-Take pictures from the camera

-Making calls

-Accessing internet...

When you install an app from the market, some of them have a “Permissions” list, where the user, has to “grant” or accept them all if they want the application installed on their device.

About the tag <permission>, I will write about it in further articles.

Version

In the <uses-sdk> tag, we are defining with which SDK the application is created, so, we can set a backward compatibility. Remember that the API “levels” are:

1.5 → API Level 3

1.1 → API Level 2

1.0 → API Level 1

Here we define the “minimum API level defined to make the app work properly”. A level 2 API Application will work in a 1.5 device but not in a 1.0 device (Obvious!)

Want more?

Those are some of the introductory features of the manifest. In further articles I will write more about this interesting element. This was just intended as a little introduction. Any question or doubts? Feel free to ask me questions.


Comments

Showing all 20 comments
 
Jbeerdev Sep 19, 2011 7:15 AM
Hard Reset
Buenas Mar Luke.

Bueno, ese problema que tienes es de tu teléfono, poco tiene que ver con la programación en Android. Aún así, si ves que las aplicaciones dejan de funcionarte, podrías resetear el teléfono de forma que se te quede "como viene de fábrica". Aquí tienes cómo hacerlo. http://www.butterscotch.com/tutorial/How-To-Factory-Reset-Your-Android

Mucho ojo pq si no haces backups de tus aplicaciones y datos se te borrarán todas las que te hayas instalado (te dejará el teléfono tal cual te lo compraste).
Mar Luke Sep 19, 2011 6:37 AM
camara dejo de funcionar
hola!! tengo htc de google. la camara dejo de funcionar y la aplicacion adobe forzo cierre. como tener de nuevo aplicacion de android market?? gracias
atentamente
Mar Luke
Jbeerdev Feb 24, 2011 6:00 AM
RE: Guide to the Android Manifest
Hi Peter.

I have never worked with App Inventor, I write the code by myself. Maybe this can help you:

http://www.androidworld.it/forum/app-inventor-91/%5Bhow-%5D-publish-app-created-app-inventor-android-market-4597/

I have not tried it so I don't know if it works.

Good luck
Peter Milko Feb 23, 2011 2:31 PM
AppInventor
You can make apps in AppInventor and export an .apk file but you cant upload it to the market because it doesnt have the AndroidManifest.xml file

how can i add this file?
App inventor doesn't let you see a root folder.

please reply
yalini Jan 13, 2011 4:00 AM
android manifestfile
Hai, im new for android i have one doubt pls help me, when i upload my app in android market i get following err,
java.lang.RuntimeException: Unable to create service com..taxorg.activity.PutService: java.lang.NullPointerException
at android.app.ActivityThread.handleCreateService(ActivityThread.java:2969)
at android.app.ActivityThread.access$3300(ActivityThread.java:125)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2087)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.taxorg.activity.PutService.onCreate(PutService.java:33)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:2959)
Jbeerdev Sep 24, 2010 7:36 AM
RE: Guide to the Android Manifest
Hi venkat

Well... Thats a odd question... it's difficult to say what packages to use...It's like using Swing in java, What packages do you use most and what are they for?

for example:

If you are using databases,

android.database is mandatory :)

In the UI we always use:

android.widget
android.view

Is this in any way useful to you? I mean, I place here some packages, and now what? watch what are inside? The best way to do this is programming and going to the API just when you are looking for something you don't know how to do.

That's my advice :)

I will write more about the Manifest. More attributes and parameters we can use here.
venkat Sep 24, 2010 7:25 AM
Jbeer
Dear!
I am a Java developer and started learning android.
I found the article to be very useful and interesting.
Can you please let me know what all packages (eg: android.app,android.app.admin) we use mostly in app development..
Thanks in advance and looking forward for the reply.
Girija Sep 17, 2010 6:53 AM
Android Manifest file
Nice Article. Could you please explain other attributes?

thanks
arindam Aug 20, 2010 6:37 AM
how to draw a background pic using open gl.
Sir i have solved that problem The name of the main activity was different thats why the error was giving.

anyway now the problem is i draw a background image in android using openGL the steps i followed :-
1) create OpenGL(main activity)
2) created another class "GLView.java"( to see something on the frame
3) created another class "ThreeDFormatLikeCube.java" (here i have drawn a cube)
4) last class is "renderer.java"(here i put the image)

Now my question is for drawing a simple background image why i have to do so many things?
ALL I WANT IS TO DRAW A SIMPLE BACKGROUND IMAGE & ON IT A SIMPLE SMALL IMAGE using openGL.
plzz help if u can plzz pass me your mail id or if possible send me some sample project like this.
arindam2047@gmail.com is my mail id plzz help im just 4 days on Android.
Jbeerdev Aug 19, 2010 9:09 AM
RE: Guide to the Android Manifest
@Karan - Doing HTTP request using Get in Android is the same as in Java. I have not any full-code example but I'm sure that you can fin a lot on info in the web :)

@arindam Really strange error. Need more info. Waht info can you post about the Activity?
arindam Aug 19, 2010 8:36 AM
SIR PLZZ HELP
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.biswas.DrawBGOpenGL"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon"
android:label="@string/app_name">
ERROR---> <activity android:name=".DrawBGOpenGL"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

</application>
<uses-sdk android:minSdkVersion="4" />
<uses-permission android:name="android.permission.INTERNET"/>

</manifest>

& The error msg is like:-
DrawOpenGL(my main activity) must be public or the system will not be able to instantiate it.
Sir what to do now?
plzz pass me ur mail id.
Description Resource Path Location Type
com.biswas.DrawBGOpenGL.DrawBGOpenGL must be public, or the system will not be able to instantiate it. AndroidManifest.xml /DrawBGOpenGL line 9 Android XML Content Problem
Karan Aug 19, 2010 6:44 AM
Need Help For Http Connection Using Get Method
Sir,

I want help for http connection using get method. I want full code including manifest.xml file. I hope you'll send as soon as possible.

Thank You,
Karan
khushi Jul 31, 2010 3:17 AM
related to android.manifest
sir ,
firstly i would like to thank you for all your articles,they are really educative,easy and useful even for beginners like me. i request you to kindly explain how to make appropriate changes in the android manifest according to our code written in java or xml . i am getting an error when i run my code .........." ButtonImageDemo1 does not specify a android.test.InstrumentationTestRunner instrumentation or does not declare uses-library android.test.runner in its AndroidManifest.xml ". though there is no error in any of the files main.xml or java ...and im not able to figure what this actually means..... i guess there is some conceptual error and i request you again to kindly guide.
thank you
Anonymous Jul 22, 2010 1:41 AM
Need clear picture about the understanding of the xml files
Hi,

I still do not have a clear picture about the understanding of the xml files in Android. I know it is very beneficial but how to understand the code written in it. Please kindly help.

Thanks,
Shaista
Jbeerdev Jun 7, 2010 6:08 AM
Classed in Android
Hi Dinh Linh

Of course you are allowed to use other classes different from Activities. You don't have to declare them in the Android Manifest.

Just create your class:

public myClass(){

}

and from the place you want to call this class, just create objects from it.

---- Piece of code inside an Activity, for example---

MyClass myC = new MyClass();

and you can work with it as usual. (Java like)
Dinh Linh Jun 5, 2010 4:29 PM
hi
I have question about active, i have config file like here :
<application android:icon="@drawable/icon"
...............................................................
<activity android:name=".IcMain" ..............
</activity>

</application>
then i know that when application run it invoke IcMain class which inherits from Activity.
Now i want to invoke other class like MyClass and it is not inherit from Active class,

My question:
- Can i do it ?
- If yes how can i do ?

Thank you so much
Jbeerdev Feb 25, 2010 3:23 AM
RE: Guide to the Android Manifest
Hi Zahira

The AndroidManifest.xml file is in the project root directory. Its not hard to find...
Zahira Feb 24, 2010 2:53 PM
Where is
The AndroidManifest.xml file? Which directory?
Thanks.
Jbeerdev Feb 10, 2010 2:38 AM
RE: Guide to the Android Manifest
Hi Sarita

You mean in the "style.xml" file? I'm going to write about this today. In few hours I will have an article explaining this.
sarita kumari Feb 10, 2010 1:53 AM
Related to XML file in android
Sir,

I want to know that how we will add style.java files in values. Values which are present in the res folder of Eclipse. Help me out sir.
 
blog comments powered by Disqus
Email to a friend