Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by WillG5677 · Dec 14, 2018 at 06:38 AM · androidpluginsc++

Unity Native C++ Plug-in for Android

I am making a native plug-in for Android written in C++ and packaged in a shared library. However, I'm getting an EntryPointNotFoundException with even the default native-lib.cpp generated by Android Studio.

 #include <jni.h>
 #include <string>

 extern "C" JNIEXPORT jstring JNICALL Java_com_example_willgauthier_stublibrary_MainActivity_stringFromJNI(
     JNIEnv *env,
     jobject /* this */) {
 std::string hello = "Hello from C++";
 return env->NewStringUTF(hello.c_str());
 }

In Android Studio I built the project. Then in Unity I made the folder structure Assets/Plugins/Android/libs and copied over the shared libnative-lib.so libraries armeabi-v7a and x86.

I attached this script to an empty game object:

 using System;
 using System.Runtime.InteropServices;
 using UnityEngine;
 using UnityEngine.UI;

 public class LibLoadTest : MonoBehaviour
 {
     public Text debugText;

     [DllImport("native-lib")]
     private static extern string stringFromJNI();

     private void Start()
     {
         try
         {
              debugText.text = stringFromJNI();
         }
         catch(Exception exception)
         {
             debugText.text = exception.ToString();
         }
     }
 }

My debugText shows "System.EntryPointNotFoundException: stringFromJNI at (wrapper managed-to-native) LibLoadTest::stringFromJNI() at LibLoadTest.Start() [0x00000] in :0" instead of "Hello from C++".

Does anyone know how to successfully use a native plug-in shared library for Android in Unity and where I'm going wrong in my process? Thanks.

Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image hexagonius · Dec 14, 2018 at 07:16 AM 0
Share

nope, but reading the documentation is what I would do:
https://docs.unity3d.com/$$anonymous$$anual/AndroidNativePlugins.html

avatar image WillG5677 hexagonius · Dec 14, 2018 at 08:44 AM 0
Share

That's the thing: I downloaded the zip archive example linked at the bottom of that documentation page, and I got the same EntryPointNotFoundException from their code. Would you $$anonymous$$d seeing if the sample works for you?

avatar image Bonfire-Boy · Dec 14, 2018 at 11:22 AM 0
Share

The function names don't match, is that intentional?

I would expect it not to find the function if the names don't match, but I'm not sure what all the other stuff in the C++ declaration is for. i.e not sure why it doesn't just look like this...

extern "C" stringFromJNI(... ){...}

avatar image WillG5677 Bonfire-Boy · Dec 14, 2018 at 10:50 PM 0
Share

That was it - thanks Bonfire-Boy! I didn't really know what all the Android/Java package name stuff in the C++ declaration was for either. I thought because it was auto-generated it had to be there and didn't count as part of the function name. Taking it out worked like a charm, though.

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

218 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to write an AndroidManifest.xml combining different plugins? 3 Answers

Android Java Plugin For Unity Object with null ptr! 0 Answers

Xamarin Android Plugins for Unity 0 Answers

Using AndroidJavaClass in a java Unity3d plugin 0 Answers

Launching an Android application from within unity without extending UnityPlayerActivity? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges