Skip to content
Advertisement

Kivy on Android, JVM exception occurred: Attempt to invoke virtual method … on a null object reference

We’re trying to access the Android camera in the Kivy app we’re building. We first opted to use plyer but we were getting a ClipData.Item.getUri() error. We ended up trying to follow the details described here: https://github.com/kivy/plyer/issues/500#issuecomment-565532048

Now there seems to be a problem in getting the URI for a file.

We have added this in AndroidManifest.tmpl.xml:

<manifest>
    <application>
    ...

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

    </application>
</manifest>

and this in the file_paths.xml as well:

<?xml version="1.0" encoding="utf-8"?>
<paths  xmlns:android="http://schemas.android.com/apk/res/android">
    <external-path  name="external_files"  path="Android/data/org.our.appnamehere/files/Pictures"  />
</paths>

We’ve tried changing the android:authorities line into org.our.appnamehere.provider and org.our.appnamehere.fileprovideras well as changing the corresponding getUriForFile in the given file from the link above

...

photo_file = self._create_image_file()

if photo_file is not None:
    photo_uri = FileProvider.getUriForFile(
                    self.currentActivity.getApplicationContext(),
                    self.currentActivity.getApplicationContext().getPackageName(),
                    photo_file
                )

...

into either self.currentActivity.getApplicationContext().getPackageName() + '.provider' or self.currentActivity.getApplicationContext().getPackageName() + '.fileprovider'.

The app seems to be successful in creating the file that photo_file links to, as we can access them under Android/data/org.our.appnamehere/files/Pictures. We always get the following error, presumably from the photo_uri line:

JavaException("JVM Exception occurred: 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")

The smartphone on which we are running the compiled app is on Android Pie, Version 9.

Nearly all solutions to this error just looks like the ones we have added into the manifest and the file_paths.xml. In addition to the several variations of android:authorities, we also tried the following lines from this link: https://github.com/jkwiecien/EasyImage/issues/103#issuecomment-304304045

        <provider
            ...
            tools:replace="android:authorities">
            <meta-data
                ...
                tools:replace="android:resource"/>
        </provider>

They do not really work and we still can’t access the camera. We might just be missing something obvious…

Any help would be greatly appreciated. Thank you very much.

Advertisement

Answer

We were in fact just missing something obvious.

Running

buildozer android clean

and rebuilding the .apk did the trick. The hint was that the <provider> tags are not included in the .apk’s manifest despite being in the template.

We can now take pictures and save files with the camera.

What happens now is that the app does not seem to resume by itself after taking a capture, but that is a separate issue altogether.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement