199

I have one Application class to keep the global state of my application. But I'm unable to register it in Manifest file? Any idea how to do this?

Rich Schuler
  • 40,748
  • 6
  • 68
  • 58
Sharj
  • 14,733
  • 12
  • 55
  • 87

4 Answers4

368

If it derives from Application, add the fully qualified (namespace + class name) as the android:name parameter of the application element in your manifest.

<application
        android:name="com.you.yourapp.ApplicationEx"

Or if the class' package can be described as relative to the package in the manifest tag, then just start with a .:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.you.yourapp">

    <application
        android:name=".ApplicationEx"
weston
  • 51,132
  • 20
  • 132
  • 192
Rich
  • 34,878
  • 31
  • 108
  • 151
  • 2
    The documentation says "fully qualified name". I have one time experienced a 3rd party tool interpreting this literally, and not working when trying to find the application class, if specified relatively. Just a warning. – Jens Vesti Jan 31 '19 at 14:34
13

but in case you are already using some library like branch.io's library then most probably your manifest

<application name="">

property will already have some name like

`<application name="io.referral.BranchApp">

in that case you need to first extend your application class, like below:

public class Application extends BranchApp

and then register your application in manifest as:

android:name="absdevelopers.com.brankreferal.Application"

this works perfectly for me :) i hope it helps someone in trouble :)

Bawa
  • 856
  • 9
  • 25
  • its been a while you wrote this answer but what if i want to add branch.io and clevertap at the same time. Im getting confused how to deal with name tag in manifest. please help me out. – jitendra purohit Mar 03 '18 at 07:45
7

If you are using a MultiDex application you will already have "android:name" in use so instead extend android.support.multidex.MultiDexApplication:

public class MyApplication extends MultiDexApplication {...}

And add it to the Android manifest:

android:name="app.package.MyApplication"
Anos K. Mhazo
  • 320
  • 2
  • 9
0

If the activity is included as a dependency that you can lauch a class this should solve it in 2021.

Add tools:ignore="MissingClass" to your activity element in the Android manfifest file

example

<activity
            android:name="com.google.android.gms.oss.licenses.OssLicensesActivity"
            android:screenOrientation="portrait"
            android:theme="@style/LicensesTheme"
            tools:ignore="MissingClass"/>

Jimmy Kane
  • 14,040
  • 9
  • 73
  • 109