Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 KaiserJohan · Apr 02, 2012 at 12:18 PM · androidiosdllimport

Catching DLLImport errors

Hello,

I have a Android and a IOS C# wrapper I use to import my native libraries. I have set them up according to the plugin guides and it works fine.

However, due to the nature of unity I have to reference them both when I build, since I cannot load them at runtime with Reflection on android/IOS unless I manually copy them every time I build and thats not good. This means the C# wrapper for iOS also gets included in Android and vice versa, but I use Application.RuntimePlatform to determine which C# wrapper to use. So it works.

The problem is the declaration in the C# wrappers have to look like this:

   [DllImport("__Internal")]
   internal static extern void IOS_TestMe();

And if I build on Android, it will throw errors in my log for each and every DllImport used in the iOS wrapper. Is there any way to suppress these errors? I can't use try/catch since its in the class declaration.

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by by0log1c · Apr 02, 2012 at 12:39 PM

If I understand your problem correctly, Platform Dependant Compilation might be what you need. It tells the compiler to completely ignore a block of code if its condition is not met, it would not get included in the build.

Comment
Add comment · Show 2 · Share
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 KaiserJohan · Apr 02, 2012 at 12:40 PM 0
Share

But I build these C# wrappers in Visual Studio - it's not "free code" lying around in Unity editor, so all pre-processor macros like UNITY_IPHONE_PLAYER gets removed when I build it in VS no?

avatar image Bunny83 · Apr 02, 2012 at 12:52 PM 0
Share

Sure, when you use precompiled assemblies there's no way to exclude them beside moving them out of your assets folder. If you want to keep your setup, you could move them to an external folder via some editor script.

The other alternative is to wrap the native code functions in a Unity script. If you want a seperate assembly (i'm not sure for what reason) you could also implement a strategy pattern so the external dll get initialized with a concrete interface object that is generated in a script inside Unity.

That's actually a bit strange since every .NET / $$anonymous$$ono assembly as well as all scripts in your project can easily be reflected (disassembled) and viewed with any .NET / CIL reflector. Your code will never be safe. The only reason to use seperate assemblies is to clean up the project a bit and provide a common source which can be used be other external assemblies.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

A node in a childnode? 1 Answer

How hard it is to upgrade to pro, add android/ios support? 1 Answer

How to open Device camera in full view in unity 3d. 1 Answer

Adding features, eg online multiplayer android/ios 1 Answer

Unity Pro with free iOS and Android? 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