Pradeep Vairamani
Pradeep Vairamani

Reputation: 4302

system.entrypointnotfoundexception in <Filename unknown> in Unity3d

I am trying to call a simple native function (C++) from Unity3D. I have done the following:

  1. Placed the libMSDKWrapper.so in Assets->Plugins->Android

  2. This is my C# code

    using UnityEngine;
    using System.Collections;
    using System.Runtime.InteropServices;
    
    public class facebooktest : MonoBehaviour {
    
        [DllImport ("MSDKWrapper")]
        private static extern long getContextNative();
    
        void Start () {
            Debug.Log("Hello, World!");
            long context = getContextNative(); // <-- Exception thrown here
            Debug.Log(context);
            }
    }
    

I am getting the following exception:

system.entrypointnotfoundexception at [0x00000] in Filename unknown:0

I used the same libMSDKWrapper.so using java using the command

System.loadLibrary("MSDKWrapper");

and I was able to access and use the getContextNative() method.

Edit 1: I unzipped the contents of the apk and found that libMSDKWrapper.so file is present in test.apk/lib/armeabi-v7a

Edit 2: Here are the logcat logs. 03-25 11:40:17.543: D/dalvikvm(26176): Trying to load lib /data/data/com.disney.citygirl.goo/lib/libMSDKWrapper.so 0x41566348 03-25 11:40:17.568: D/MSDK(26176): Register Provider: SN_COMMUNITY 03-25 11:40:17.568: D/MSDK(26176): Register Provider: SN_FACEBOOK 03-25 11:40:17.568: D/dalvikvm(26176): Added shared lib /data/data/com.disney.citygirl.goo/lib/libMSDKWrapper.so 0x41566348 03-25 11:40:17.568: I/MSDK(26176): JNI_OnLoad called 03-25 11:40:17.573: D/dalvikvm(26176): Trying to load lib /data/data/com.disney.citygirl.goo/lib/libMSDKWrapper.so 0x41566348 03-25 11:40:17.573: D/dalvikvm(26176): Shared lib '/data/data/com.disney.citygirl.goo/lib/libMSDKWrapper.so' already loaded in same CL 0x41566348 03-25 11:40:17.598: I/Unity(26176): System.EntryPointNotFoundException: getContextNative 03-25 11:40:17.598: I/Unity(26176): at (wrapper managed-to-native) SocialAccess:getContextNative () 03-25 11:40:17.598: I/Unity(26176): at SocialAccess.OnClick () [0x00000] in :0 03-25 11:40:17.598: I/Unity(26176):
03-25 11:40:17.598: I/Unity(26176): (Filename: ./Runtime/ExportGenerated/AndroidManaged/UnityEngineDebug.cpp Line: 43)

Upvotes: 3

Views: 2579

Answers (2)

Nicholas Terry
Nicholas Terry

Reputation: 1920

Make sure you are using the extern 'c' directive to avoid name-mangling issues. If you don't 'wrap' your calls in 'c' method names, you'll get this exact behavior because the c++ compiler 'mangles' or adds additional architecture-specific 'junk' to the method names. If you have questions, you can refer to my github project HERE

Focus on the main.cpp (the entry point which is the same in android-src/ as in the root). That is the pattern you will need to model your c++ dll after. This project will also show you how to build a c++ dll for android. Look at the README for full build instructions for both Ubuntu (and other Debian-like operating systems) and android.

@Virtlink I know its a pro-only feature, but it appears that Unity will just give a warning when using p/invokes. I'm not use if Unity fixed that in V4, but V3 allows you to use them anyways. The trial will also suffice.

Just as another note, is there a specific reason you NEED to use a C++ dll? In almost all cases, you can do what you want in managed C# code. Be absolutely sure you need this DLL as it will break cross-compatibility with a single codebase. With my dll, i decided to scrap my use-case for it and re-wrote the whole thing in c#.

Upvotes: 0

Daniel A.A. Pelsmaeker
Daniel A.A. Pelsmaeker

Reputation: 50306

You are using a C++ plugin, but maybe your Unity3D version does not support it? I recall you need Pro to do that.

This page might provide a solution.

Upvotes: 2

Related Questions