Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android multiple <application> in one androidmanifest

I am using Android global variable example.

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

like image 638
user1143989 Avatar asked Dec 13 '22 05:12

user1143989


2 Answers

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.

like image 58
Jean-Philippe Roy Avatar answered Jan 09 '23 22:01

Jean-Philippe Roy


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>
like image 33
AverageMoss1123 Avatar answered Jan 09 '23 23:01

AverageMoss1123