4

I am using Android global variable example.

How do I add another "application" tag in AndroidManifest.xml ?

Community
  • 1
  • 1
user1143989
  • 163
  • 1
  • 3
  • 18

3 Answers3

8

According to the documentation, only one application tag can be inserted in the manifest.

Quote from doc:

"Only the manifest and application elements are required, they each must be present and can occur only once."

If you're following the example at the given link, just add the android:name and android:label XML element to your current application tag and it'll work just fine.

Example of my application tag in an application I'm developing at the moment:

<application
    android:name=".Globals"
    android:debuggable="true"
    android:icon="@drawable/icon"
    android:label="@string/app_name" >

Globals is my application class.

Aniket Thakur
  • 66,731
  • 38
  • 279
  • 289
Jean-Philippe Roy
  • 4,752
  • 3
  • 27
  • 41
  • OK. Thanks. So what will be the solution if I have to add a class extends from Application to add application global variables? – user1143989 Feb 23 '12 at 19:44
4

I know this question was asked a long time ago but using Android Studio 3.0 and higher, I came across the same problem and did not find anything online that helped.

After a lot of research and my own testing, I found out how to successfully implement two or more classes that both extend android.app.Application into the Manifest's <Application/>.

First Class File:

public abstract class MyClass1 extends Application {

    // ...
}

Second Class File:

public class MyClass2 extends MyClass1 {

    // ...
}

Manifest File:

<application

    android:name="com.mydomain.myapp.MyClass2">

    <!-- Rest of code here... -->

</application>
  • This worked for me, also had to add on highest priority manifest the following tag. tools:node="merge". In my use-case, I was including a library created by be with dependency injection, that needed an Application. Then on main App, I extended the lib Application as mentioned here. – Kunami May 17 '19 at 08:41
1

how to handle multiple application classes in android

When a library is already extending the "Applicaton" class just do the following

class lib1 extend Application {
...
}

class lib2 extend lib1{
...
}

in the manifest -> <application android:name = "package.lib2".....

Community
  • 1
  • 1
vuhung3990
  • 6,353
  • 1
  • 45
  • 44