8

guys, I am working on an android application for which I need external application dependency(.aar file) library application has its own file provider and my application have its own.

library work well when I run it as a separate app but when I include it my application then camera functionality not working. I get the following error

java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.XmlResourceParser android.content.pm.ProviderInfo.loadXmlMetaData(android.content.pm.PackageManager, java.lang.String)' on a null object reference

following the manifest file of the application

<provider
            android:name="android.support.v4.content.FileProvider"
            android:authorities="${applicationId}.provider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/file_paths" />
        </provider>

and the following is a manifest file of the lib module

<provider
            android:name="android.support.v4.content.FileProvider"
            android:authorities="com.ma.bot.provider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/file_paths" />
        </provider>

both application and lib module have different package name how I add this 2 file providers into the application I also try including multiple file providers using, but I get XML parse error on app compilation.

android:authorities="${applicationId}.provider;com.ma.bot.provider"

how to solve this.

1 Answer 1

37

Guys I found solution on this link Possible to use multiple authorities with FileProvider?

Basically problem is my library and application have same name android.support.v4.content.FileProvider so it colliding in manifest merger, to avoid this I need to defile empty class extending File provider and use it provider name

<provider
            android:name="com.MAG.MAGFileProvider"
            android:authorities="${applicationId}.provider;"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/file_paths" />
        </provider>

and declare class like this

import android.support.v4.content.FileProvider;
public class MAGFileProvider extends FileProvider
{
    //we extend fileprovider to stop collision with chatbot library file provider
    //this class is empty and used in manifest
}
Sign up to request clarification or add additional context in comments.

3 Comments

it worked for me. when I am using this for library android:name="android.support.v4.content.FileProvider" android:authorities="com.library.provider" and this in main app manifest android:name="com.MAG.MAGFileProvider" android:authorities="${applicationId}.provider;"
where does the class file get created?
best answer ever!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.