0 votes
Hello,

I installed the plugin in a completely new project (i tried both Unity 5.5.1 and 5.6.1) added SampleNewUI scene to the Build settings and when i build and run to my Samsung Galaxy S6 (Android 7.0) and click on the OpenLocal button i get the following exception in the log:

06-13 16:48:14.430 13520-13535/? I/Unity: AndroidJavaException: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.XmlResourceParser android.content.pm.PackageItemInfo.loadXmlMetaData(android.content.pm.PackageManager, java.lang.String)' on a null object reference
                                          java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.XmlResourceParser android.content.pm.PackageItemInfo.loadXmlMetaData(android.content.pm.PackageManager, java.lang.String)' on a null object reference
                                              at android.support.v4.content.FileProvider.parsePathStrategy(FileProvider.java:561)
                                              at android.support.v4.content.FileProvider.getPathStrategy(FileProvider.java:535)
                                              at android.support.v4.content.FileProvider.getUriForFile(FileProvider.java:377)
                                              at com.SlavaObninsk.pdfreader.Logic.OpenDocLocal(Logic.java:60)
                                              at com.unity3d.player.UnityPlayer.nativeRender(Native Method)
                                              at com.unity3d.player.UnityPlayer.a(Unknown Source)
                                              at com.unity3d.player.UnityPlayer$b$1.handleMessage(Unknown Source)

Do you maybe have an idea what is going wrong there?
asked Jun 13, 2017 by Phil (120 points)

1 Answer

0 votes
Add to android manifest

<provider
            android:name="android.support.v4.content.FileProvider"
            android:authorities="com.SlavaObninsk.Test.provider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/provider_paths"/>
        </provider>
answered Jun 14, 2017 by IndieYP (1,730 points)
hmmm, i checked but these lines are already present in the Android manifest file. As i said i have only imported your latest plugin in a new project and did not change anything before building and running it.

I now also had the chance to test with the following devices:

Sony xperia z5 compact with Android 7:
 -> The same exception here

Samsung Galaxy S5 mini with Android 4.4.2
-> works perfectly there.

Could it be a problem with Android 7? or maybe something else like the Android SDK version that is linked in Unity? I am using SDK build tool 26 but have to use sdk tools 25.2.3 due to a bug in Unity 5.5 and 5.6.
Yes reason android 7, they changed permission rules, i research it.
Just a info for you, i have found the following:

If i provide the bundle identifier com.SlavaObninsk.Test in the Unity PlayerSettings -> Other settings the OpenLocal example in your sample project works.

so for my project i changed the PDFReader Android manifest file to use my bundle identifier in the authorities attribute

    <provider
            android:name="android.support.v4.content.FileProvider"
            android:authorities="com.ingman.entagros.provider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/provider_paths"/>
        </provider>
       
Maybe you find a more elegant solution where the AndroidManifest.xml must not be changed, but at least this workaround works for now :-)

Anyway thanks a lot for your quick response!
Welcome to IndieYP Q&A, where you can ask questions and receive answers from other members of the community.
27 questions
23 answers
42 comments
1,529 users