Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Crash at app startup: FATAL EXCEPTION: main

Discussion in 'Android' started by Flarup, Aug 12, 2019.

  1. Flarup

    Flarup

    Joined:
    Jan 7, 2010
    Posts:
    112
    I have a project in which I have several native Android plugins. Keeping them uptodate is a bit tricky, since some Unity plugins from the Asset Store depends on the same native Android plugins. Typically I would get problems while building the Gradle project, in case I had two Unity plugins that included the same native Android plugins.

    However, now I'm running into a new problem with native Android plugins. The entire build process succeeds, but when I run the apk on an Android device it instantly crashes due to some missing code. The error log I get is the following:

    08-12 20:14:25.322 1681 1681 E AndroidRuntime: FATAL EXCEPTION: main
    08-12 20:14:25.322 1681 1681 E AndroidRuntime: Process: com.arblox.v2, PID: 1681
    08-12 20:14:25.322 1681 1681 E AndroidRuntime: java.lang.RuntimeException: Unable to get provider android.support.v4.content.FileProvider: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.content.FileProvider" on path: DexPathList[[zip file "/data/app/com.arblox.v2-I2bYWJsC3kLY-jqkbMlUog==/base.apk"],nativeLibraryDirectories=[/data/app/com.arblox.v2-I2bYWJsC3kLY-jqkbMlUog==/lib/arm64, /data/app/com.arblox.v2-I2bYWJsC3kLY-jqkbMlUog==/base.apk!/lib/arm64-v8a, /system/lib64, /system/vendor/lib64]]
    08-12 20:14:25.322 1681 1681 E AndroidRuntime: at android.app.ActivityThread.installProvider(ActivityThread.java:6747)
    08-12 20:14:25.322 1681 1681 E AndroidRuntime: at android.app.ActivityThread.installContentProviders(ActivityThread.java:6289)
    08-12 20:14:25.322 1681 1681 E AndroidRuntime: at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6204)
    08-12 20:14:25.322 1681 1681 E AndroidRuntime: at android.app.ActivityThread.access$1200(ActivityThread.java:237)
    08-12 20:14:25.322 1681 1681 E AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1785)
    08-12 20:14:25.322 1681 1681 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:106)
    08-12 20:14:25.322 1681 1681 E AndroidRuntime: at android.os.Looper.loop(Looper.java:214)
    08-12 20:14:25.322 1681 1681 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:7050)
    08-12 20:14:25.322 1681 1681 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
    08-12 20:14:25.322 1681 1681 E AndroidRuntime: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    08-12 20:14:25.322 1681 1681 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)
    08-12 20:14:25.322 1681 1681 E AndroidRuntime: Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.content.FileProvider" on path: DexPathList[[zip file "/data/app/com.arblox.v2-I2bYWJsC3kLY-jqkbMlUog==/base.apk"],nativeLibraryDirectories=[/data/app/com.arblox.v2-I2bYWJsC3kLY-jqkbMlUog==/lib/arm64, /data/app/com.arblox.v2-I2bYWJsC3kLY-jqkbMlUog==/base.apk!/lib/arm64-v8a, /system/lib64, /system/vendor/lib64]]
    08-12 20:14:25.322 1681 1681 E AndroidRuntime: at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
    08-12 20:14:25.322 1681 1681 E AndroidRuntime: at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
    08-12 20:14:25.322 1681 1681 E AndroidRuntime: at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
    08-12 20:14:25.322 1681 1681 E AndroidRuntime: at android.app.AppComponentFactory.instantiateProvider(AppComponentFactory.java:121)
    08-12 20:14:25.322 1681 1681 E AndroidRuntime: at androidx.core.app.CoreComponentFactory.instantiateProvider(CoreComponentFactory.java:62)
    08-12 20:14:25.322 1681 1681 E AndroidRuntime: at android.app.ActivityThread.installProvider(ActivityThread.java:6731)
    08-12 20:14:25.322 1681 1681 E AndroidRuntime: ... 10 more



    To me it looks like some native Android code is missing from the apk, but I have no idea about how to fix it.

    Among the list if things I already have tried are the following:

    - Using both "Resolve" and "Force Resolve" in the Android Resolver menu.
    - Restarting Unity before building the apk.
    - "Delete Resolved Libraries" in the Android Resolver menu.
    - Enabling and disabling automatic resolving of Android libraries.


    My question is: How do I "tell" Unity that this missing Android native code must be included in my apk?

    Thank you all VERY much in advance for all your help!


    Kind regards,
    Uffe Flarup
     
  2. weiping-toh

    weiping-toh

    Joined:
    Sep 8, 2015
    Posts:
    44
  3. Voxel-Busters

    Voxel-Busters

    Joined:
    Feb 25, 2015
    Posts:
    810
    If you are having androidX libraries, make sure you don't refer android.support.* from your manifest file. Use the corresponding androidX updated path for file proivder reference ->
    androidx.core.content.FileProvider
     
    Flarup likes this.
  4. Flarup

    Flarup

    Joined:
    Jan 7, 2010
    Posts:
    112
    Hi @Voxel-Busters. Thanks for bringing my attention to the androidX libraries. As you suggest, a bunch of dependencies to androidX libraries was added as a part of the update I'm working on.

    Also, I managed to find the manifest file that references the fileprovider, and I changed the value to be "androidx.core.content.FileProvider" instead. My apk will now start on the device (progress, hooray!), and I no longer get the crash I originally had. Unfortunately, the "old" plugin that used the "old" fileprovider now crashes, and I get the following error a bit later in the app:

    08-13 11:18:02.928 29422 29604 E Unity : AndroidJavaException: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/content/ContextCompat;
    08-13 11:18:02.928 29422 29604 E Unity : java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/content/ContextCompat;
    08-13 11:18:02.928 29422 29604 E Unity : at com.partagames.unity.permissiongranter.PermissionGranter.isPermissionGranted(PermissionGranter.java:33)
    08-13 11:18:02.928 29422 29604 E Unity : at com.partagames.unity.permissiongranter.unity.PermissionGranterUnity.isPermissionGranted(PermissionGranterUnity.java:27)


    This plugin have worked perfectly for a long time, but now breaks after the androidX libraries was added to the project.

    Is the usage of androidX libraries "incompatible" with "old" android libraries? Or is there some way to have them co-exist in the same project?

    Thanks a lot for all your help.
     
    Qbit86 likes this.
  5. Voxel-Busters

    Voxel-Busters

    Joined:
    Feb 25, 2015
    Posts:
    810
    Its possible to have both old and new androidX packages exist in same project. Thanks to Jetifier which makes it possible.

    All our plugins as of now not yet upgraded to androidX but uses Jetifier because we do find other many plugins haven't updated to androidX. So, this scenario will be quite common for some more time until we find the right time.


    Coming to your solution, Please check our previous posts where you can automate the process of Jetifier with a script. Adding the gradle patch script should make it work with old android support libraries.

    Do let me know if you can't find it.
     
    Flarup likes this.
  6. Flarup

    Flarup

    Joined:
    Jan 7, 2010
    Posts:
    112
    I can see you're very active in the forums here, @Voxel-Busters. Can you please give me a link to the post you suggest I should take a further look at?

    Also (and I'm probably wrong here, since I haven't done much native Android development), I can't help but thinking that Jetifier is CAUSING problems here, rather than solving them. Basically, I had some native Android plugins that worked perfectly fine, but then I upgraded some other plugins which was using Jetifier, and then the usage of Jetifier caused my old plugins to no longer work. And now I can't move forward until the old plugins I have, have been updated to support Jetifier.

    As mentioned earlier, I may be misunderstanding something here. But what exactly is the root cause of the sudden crash I'm getting?

    Thank you VERY much for your help.


    Kind regards,
    Uffe Flarup
     
  7. Voxel-Busters

    Voxel-Busters

    Joined:
    Feb 25, 2015
    Posts:
    810
    ok, no worries. I was a bit lazy to dig through :p

    In this post, grab the second script and keep in Editor folder. Also, you need to have the following checked.
    1. Have at-least 1.2.119 Play Services Resolver. You can download the latest one from here.
    2. In Play Services Resolver, under Android Settings (from Assets -> Play Services Resolver -> Android -> Settings), enable "Uses Jetifier" if not enabled.
    3. Force resolve from the menu again

    Coming to other plugins, they need to set the required flags to consider them for Jetifier process. The shared script will do that job. I'm assuming this could be the problem but if you still see the issue, i need to look into more details.

    Thanks,
    VB Team
     
    Flarup likes this.
  8. Flarup

    Flarup

    Joined:
    Jan 7, 2010
    Posts:
    112
    Thanks a lot for the script. Adding that script and manually changing my manifest files seems to fix the problem.

    Needs to test a bit more, and see if everything still works as expected. But at first glance everything seems good.

    Thanks you very much for the help!
     
  9. Voxel-Busters

    Voxel-Busters

    Joined:
    Feb 25, 2015
    Posts:
    810
    It should work as it enables the jetifier automatically on export :)