I have an android library project being referenced by an application project. The library project has a custom class extending the base Application
class where I have done some initializations. Now the problem is that this class doesn't get called automatically even though I have registered it correctly in the manifest file of the library project. I even tried to call it using
MyApplication app = new MyApplication();
app.onCreate();
But this gives me a null pointer exception.
What I think is that application class does not get called in the library project automatically. If this is true then what's a better way to call it manually from with in the library project?
You can extend the library's Application class in the application project and provide any additional implementation. If you do this, you will have to use this extended Application in the manifest.
An Android library is structurally the same as an Android app module. It can include everything needed to build an app, including source code, resource files, and an Android manifest.
In addition to JAR files, Android uses a binary distribution format called Android Archive(AAR). The . aar bundle is the binary distribution of an Android Library Project. An AAR is similar to a JAR file, but it can contain resources as well as compiled byte-code.
This is a limitation of Android library projects. The AndroidManifest.xml of a library project is effectively ignored in a project that uses that library.
Thus you need to put any <activity>
, <service>
, and other such tags in the end application's manifest.
Note: While the above was true in 2013 (and is still true if you are using Ant as your build system), the Android Gradle plugin will merge manifests from AAR libraries into your manifest automatically.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With