yasirkula / UnityNativeShare

A Unity plugin to natively share files (images, videos, documents, etc.) and/or plain text on Android & iOS
MIT License
891 stars 131 forks source link

java.lang.ClassNotFoundException: com.unity3d.player.UnityPlayerNativeActivity #109

Closed dlunhor closed 3 years ago

dlunhor commented 3 years ago

Description of the bug

Just cannot share the file. Use it like this.

new NativeShare().AddFile(pathToAttachment).Share();

Works on every android version except 11.

Reproduction steps

  1. Build app.
  2. Run it.
  3. Press button with sharing.

Platform specs

Additional info

2021.04.22 12:36:12.711 20400 20427 Error Unity AndroidJavaException: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/unity3d/player/UnityPlayerNativeActivity; 2021.04.22 12:36:12.711 20400 20427 Error Unity java.lang.NoClassDefFoundError: Failed resolution of: Lcom/unity3d/player/UnityPlayerNativeActivity; 2021.04.22 12:36:12.711 20400 20427 Error Unity at com.unity3d.player.UnityPlayer.nativeRender(Native Method) 2021.04.22 12:36:12.711 20400 20427 Error Unity at com.unity3d.player.UnityPlayer.access$300(Unknown Source:0) 2021.04.22 12:36:12.711 20400 20427 Error Unity at com.unity3d.player.UnityPlayer$e$1.handleMessage(Unknown Source:95) 2021.04.22 12:36:12.711 20400 20427 Error Unity at android.os.Handler.dispatchMessage(Handler.java:102) 2021.04.22 12:36:12.711 20400 20427 Error Unity at android.os.Looper.loop(Looper.java:236) 2021.04.22 12:36:12.711 20400 20427 Error Unity at com.unity3d.player.UnityPlayer$e.run(Unknown Source:20) 2021.04.22 12:36:12.711 20400 20427 Error Unity Caused by: java.lang.ClassNotFoundException: com.unity3d.player.UnityPlayerNativeActivity 2021.04.22 12:36:12.711 20400 20427 Error Unity ... 6 more 2021.04.22 12:36:12.711 20400 20427 Error Unity at UnityEngine.AndroidJNISafe.CheckException () [0x00000] in <00000000000000000000000000000000>:0 2021.04.22 12:36:12.711 20400 20427 Error Unity at UnityEngine.AndroidJNISafe.FindClass (System.String name) [0x00000] in <00000000000000000000000000000000>:0 2021.04.22 12:36:12.711 20400 20427 Error Unity at UnityEngine.AndroidJavaClass._AndroidJavaClass (System.String className) [0x00000] in <000000000000000000000000000000

Android manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="com.unity3d.player" android:installLocation="preferExternal" android:versionCode="1" android:versionName="1.0">
  <supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:xlargeScreens="true" android:anyDensity="true" />
  <application android:usesCleartextTraffic="true" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" android:icon="@drawable/app_icon" android:label="@string/app_name" android:debuggable="false">
    <activity android:name="com.unity3d.player.UnityPlayerActivity" android:label="@string/app_name">
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
      <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
    </activity>
  </application>

  <uses-permission android:name="android.permission.INTERNET" />
  <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
  <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
</manifest>

Custom Proguard option is enabled and line added in the file

yasirkula commented 3 years ago

Does this issue occur when you call NativeShare.Share? Because I can't see NativeShare in the stacktrace. If it does, then can you build with Development Build and see if NativeShare appears in the stacktrace?

dlunhor commented 3 years ago

Code of EtceteraMailWriter:SendMail where we call new NativeShare().AddFile(pathToAttachment).Share();

public static void SendEmail(string to, string subject, string body, string pathToAttachment = "", string mimeType = "", string cc = "", string bcc = "")
    {
#if UNITY_IOS
        if (string.IsNullOrEmpty(to))
        {
            new NativeShare().AddFile( pathToAttachment ).Share();
        }
        else
        {
            if (Application.platform == RuntimePlatform.IPhonePlayer)
                sendEmail(to, cc, bcc, subject, body, pathToAttachment, mimeType);
        }
#elif UNITY_ANDROID
        if (string.IsNullOrEmpty(to))
        {
            new NativeShare().AddFile(pathToAttachment).Share();
        }
        else
        {

            if (Application.platform == RuntimePlatform.Android)
                Obj.CallStatic("sendEmail", new object[] { to, cc, bcc, subject, body, pathToAttachment });
        }
#endif
    }

2021.04.22 15:11:12.211 27192 27249 Info Unity 684901a8-5c93-4b7d-97b5-1e268531084f.package 2021.04.22 15:11:12.211 27192 27249 Info Unity EtceteraMailWriter:SendMail(String, String, String, String) 2021.04.22 15:11:12.211 27192 27249 Info Unity AppLog:SendToEmail(Boolean) 2021.04.22 15:11:12.211 27192 27249 Info Unity UnityEngine.Events.UnityAction:Invoke() 2021.04.22 15:11:12.211 27192 27249 Info Unity UnityEngine.Events.UnityEvent:Invoke() 2021.04.22 15:11:12.211 27192 27249 Info Unity UnityEngine.EventSystems.EventFunction1:Invoke(T1, BaseEventData) 2021.04.22 15:11:12.211 27192 27249 Info Unity UnityEngine.EventSystems.ExecuteEvents:Execute(GameObject, BaseEventData, EventFunction1) 2021.04.22 15:11:12.211 27192 27249 Info Unity UnityEngine.EventSystems.StandaloneInputModule:ProcessTouchPress(PointerEventData, Boolean, Boolean) 2021.04.22 15:11:12.211 27192 27249 Info Unity UnityEngine.EventSystems.StandaloneInputModule:ProcessTouchEvents() 2021.04.22 15:11:12.211 27192 27249 Info Unity UnityEngine.EventSystems.StandaloneInputModule:Process() 2021.04.22 15:11:12.211 27192 27249 Info Unity 2021.04.22 15:11:12.220 27192 27249 Error Unity UNCAUGHT EXCEPTION: AndroidJavaException: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/unity3d/player/UnityPlayerNativeActivity; 2021.04.22 15:11:12.220 27192 27249 Error Unity STACK_TRACE: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/unity3d/player/UnityPlayerNativeActivity; 2021.04.22 15:11:12.220 27192 27249 Error Unity com.unity3d.player.UnityPlayer.nativeRender(Native Method) 2021.04.22 15:11:12.220 27192 27249 Error Unity com.unity3d.player.UnityPlayer.access$300(Unknown Source:0) 2021.04.22 15:11:12.220 27192 27249 Error Unity com.unity3d.player.UnityPlayer$e$1.handleMessage(Unknown Source:95) 2021.04.22 15:11:12.220 27192 27249 Error Unity android.os.Handler.dispatchMessage(Handler.java:102) 2021.04.22 15:11:12.220 27192 27249 Error Unity android.os.Looper.loop(Looper.java:236) 2021.04.22 15:11:12.220 27192 27249 Error Unity com.unity3d.player.UnityPlayer$e.run(Unknown Source:20) 2021.04.22 15:11:12.220 27192 27249 Error Unity Caused by: java.lang.ClassNotFoundException: Didn't find class "com.unity3d.player.UnityPlayerNativeActivity" on path: DexPathList[[zip file "/data/app/KygqrNh-A0x0I6xRByCSuw==/com.SkyTrak.SkyTrak-kPex8CiJmpxQXc0a7xEJog==/base.apk"],nativeLibraryDirectories=[/data/app/KygqrNh-A0x0I6xRByCSuw==/com.SkyTrak.SkyTrak-kPex8CiJmpxQXc0a7xEJog==/lib/arm64, /data/app/~~KygqrNh-A0x0I6xRByCSuw==/com.SkyTrak.SkyTrak-kPex8CiJmpxQXc0a7xE 2021.04.22 15:11:12.220 27192 27249 Error Unity AndroidJavaException: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/unity3d/player/UnityPlayerNativeActivity; 2021.04.22 15:11:12.220 27192 27249 Error Unity java.lang.NoClassDefFoundError: Failed resolution of: Lcom/unity3d/player/UnityPlayerNativeActivity; 2021.04.22 15:11:12.220 27192 27249 Error Unity at com.unity3d.player.UnityPlayer.nativeRender(Native Method) 2021.04.22 15:11:12.220 27192 27249 Error Unity at com.unity3d.player.UnityPlayer.access$300(Unknown Source:0) 2021.04.22 15:11:12.220 27192 27249 Error Unity at com.unity3d.player.UnityPlayer$e$1.handleMessage(Unknown Source:95) 2021.04.22 15:11:12.220 27192 27249 Error Unity at android.os.Handler.dispatchMessage(Handler.java:102) 2021.04.22 15:11:12.220 27192 27249 Error Unity at android.os.Looper.loop(Looper.java:236) 2021.04.22 15:11:12.220 27192 27249 Error Unity at com.unity3d.player.UnityPlayer$e.run(Unknown Source:20) 2021.04.22 15:11:12.220 27192 27249 Error Unity Caused by: java.lang.ClassNotFoundException: Didn't find class "com.unity3d.player.UnityPlayerNativeActivity" on path: DexPathList[[zip file "/data/app/KygqrNh-A0x0I6xRByCSuw==/com.SkyTrak.SkyTrak-kPex8CiJmpxQXc0a7xEJog==/base.apk"],nativeLibraryDirectories=[/data/app/KygqrNh-A0x0I6xRByCSuw==/com.SkyTrak.SkyTrak-kPex8CiJmpxQXc0a7xEJog==/lib/arm64, /data/app/~~KygqrNh-A0x0I6xRByCSuw==/com.SkyTrak.SkyTrak-kPex8CiJmpxQXc0a7xEJog==/bas

dlunhor commented 3 years ago

We always have to. So yes, I call NativeShare.

yasirkula commented 3 years ago

And if you make the following change, you can see "Before NativeShare" line and the app crashes? I'm skeptical because I still can't see NativeShare anywhere in the stacktrace 🤷‍♂️

#elif UNITY_ANDROID
Debug.Log("Before NativeShare");
new NativeShare().AddFile(pathToAttachment).Share();
Debug.Log("After NativeShare");
#endif
dlunhor commented 3 years ago

Ok. My problem. Good. Thank you ;)