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 piersb · Jun 12, 2020 at 03:54 PM · iosandroid buildil2cppcompiler

How do I prevent IL2CPP from Erroring on managed plugin code designed for iOS when I attempt to build for Android?

I’ve been banging my head against a C# coding problem for the last few days.

The problem is this - we're developing a Unity plugin and issuing the code as DLLs for use by game developers. The developers would then plumb code from our DLLs into their Unity programmes by drag-and drop.

So far so good.

Unfortunately one of the compilers that some developers use to build for Android (IL2CPP) breaks if it encounters managed iOS code, and we use some plugin code on iOS and Android to detect hardware capabilites.
Specifically, "IL2CPP requires that all native methods used in managed code be present at link time, where Mono does not,” as quoted in https://forum.unity.com/threads/build-fails-with-il2cpp.523955/ - the native methods in managed code being our iOS plugin in this case.

Now, normally we’d just wrap the code in an #if UNITY_IOS preprocessor directive, job done. But because we’re compiling the code into DLLs to ship, we’d need to make the choice at compile time. Which means that we can either compile a version that works on Android, or a version that works on iOS, but not both.

I’ve tried several routes to get around this, none of which has worked as yet. As soon as there’s a reference to the iOS code (eg in a switch statement to only use it at runtime) the Android compiler will follow the path to the native iOS methods, be unable to parse them, and Error. But if I try stripping out the code with a preprocessor directive, it no longer works on iPhone, because we’ve stripped the code out of the DLL.

I know there must be a solution to this, presumably involving loading the class at runtime, as otherwise how could you create a single package in C# for anything that ran on different types of hardware? But at the moment I still don’t know how to crack it.

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
0

Answer by Bunny83 · Jun 13, 2020 at 01:13 PM

Uhm every DLL or library (managed or native) has plugin import settings when you select it in the editor. You can choose which platforms a library should be used for. You generally should have seperate libraries for different platforms and set the import settings on them properly.


However apart from the import settings you should still be able to use the proper platform subfolders in the plugins folder to automatically choose the correct import settings.

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

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

165 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

Related Questions

How to ad mysql.data.dll to Android and iOS build?,How to add mysql.data.dll to Android and iOS build? 0 Answers

IL2CPP Build errors on xCode 0 Answers

Android build failing on 2017.2.0f3 2 Answers

IL2CPP compatibility in iOS 1 Answer

Android build crash - stack corruption detected Unity 2018.3.8f1 2 Answers


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