• 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
Question by dznn · Mar 07, 2019 at 08:17 PM · androidandroid buildexportil2cppflag

How to add compiler or linker flags for il2cpp invocation.

Hi,

is there any way to affect the il2cpp invocation when building a project? In this particular case it would be for Android but the question probably applies to all players supporting the il2cpp backend.

I basically want to add additional compiler and linker flags:

 me@machine /A/U/U/C/i/build> mono ./il2cpp.exe
 Options:
 ...
   --compiler-flags=<value>                Additional flags to pass to the C++ compiler
   --linker-flags=<value>                  Additional flags to pass to the linker
  

I was hoping for just a setting somewhere but couldn't find anything. Maybe something with the Scriptable Build Pipeline? I can find several answers on how to add flags to a generated Xcode project but in the Android case it seems that even if you export to a Gradle project to build in e.g. Android Studio the export contains compiled version of the il2cpp generated code and not ndk scripts to build them over again.

Comment
Petr777

People who like this

1 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 JoshPeterson · Mar 08, 2019 at 01:10 PM 0
Share

Can you elaborate on what additional flags you would like to pass? Those two arguments are generally used internal by the Unity editor. For the most part we don't support users passing additional C++ compiler arguments, as the current set of arguments should be correct. But I'm interested to learn move about your use case.

avatar image dznn JoshPeterson · Mar 09, 2019 at 05:34 PM 0
Share

@JoshPeterson I'm trying to integrate a tool that does some post-processing based on LLVM bitcode. So just like the iOS export I'd like the Android one to have embedded bitcode. Since r16 NDK this is possible with the -fembed-bitcode flag.

avatar image JoshPeterson dznn · Mar 11, 2019 at 12:25 PM 0
Share

Thanks! I don't expect this compiler option to have a negative impact, and we don't currently have a built-in way to provide it. See my answer below for details.

avatar image Petr777 · Nov 23, 2020 at 02:52 PM 0
Share

@dznn can you tell please, did you solve this?

3 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by JoshPeterson · Mar 11, 2019 at 12:24 PM

We do have a "backdoor" (i.e. not documented) ability to pass additional arguments to il2cpp.exe. You can either run the Unity editor with an environment variable set: IL2CPP_ADDITIONAL_ARGS or you can use an editor script to call PlayerSettings.SetAdditionalIl2CppArgs. Either option will allow you to pass the command line options you have mentioned.

We don't test with all of possible compiler and linker arguments available, so your mileage may vary, but this should work.

Comment
Petr777
Pangamini

People who like this

2 Show 6 · 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 dznn · Mar 12, 2019 at 04:44 PM 0
Share

Thanks, both suggestions work. However the flag I pass seems completely ignored without causing any error. The output does not have the desired bitcode sections.

From the editor log I see that it gets to il2cpp but the ELF's don't have the required section.

I wrapped /Applications/Unity/Hub/Editor/2019.1.0b5/PlaybackEngines/AndroidPlayer/NDK/toolchains/llvm/prebuilt/darwin-x86_64/bin/{clang,clang++} to inspect the invocations but they are never called. Is il2cpp integrating with clang in a different way? It probably just links agains it and skips the driver? If that's true do you know how the flags are passed?

avatar image JoshPeterson dznn · Mar 12, 2019 at 06:04 PM 0
Share

Can you have a look at the Unity editor log file? It should disable the entire command line passed to il2cpp.exe (search the log file for "il2cpp with"). That should let us know if the command line arguments are getting to il2cpp.exe properly.

avatar image dznn JoshPeterson · Mar 12, 2019 at 06:53 PM 0
Share

@JoshPeterson The flags are passed correctly, I didn't want to paste the whole line here but if it helps:

 Invoking il2cpp with arguments: 
 --convert-to-cpp 
 --emit-null-checks 
 --enable-array-bounds-check 
 --dotnetprofile="legacyunity" 
 --compile-cpp 
 --libil2cpp-static 
 --platform="Android" 
 --architecture="ARM64" 
 --configuration="Release" 
 --outputpath="/me/MobilePlaceHolder/Temp/StagingArea/assets/bin/Data/Native/arm64-v8a/libil2cpp.so" 
 --cachedirectory="/me/MobilePlaceHolder/Assets/../Library/il2cpp_android_arm64-v8a/il2cpp_cache" 
 --additional-include-directories="/Applications/Unity/Hub/Editor/2019.1.0b5/PlaybackEngines/AndroidPlayer/Tools/bdwgc/include" 
 --additional-include-directories="/Applications/Unity/Hub/Editor/2019.1.0b5/PlaybackEngines/AndroidPlayer/Tools/libil2cpp/include" 
 --tool-chain-path="/Applications/Unity/Hub/Editor/2019.1.0b5/PlaybackEngines/AndroidPlayer/NDK" 
 --profiler-report 
 --map-file-parser="/Applications/Unity/Hub/Editor/2019.1.0b5/Unity.app/Contents/Tools/MapFileParser/MapFileParser" 
 --compiler-flags='-fembed-bitcode'  
 --directory="/me/MobilePlaceHolder/Temp/StagingArea/assets/bin/Data/Managed" 
 --generatedcppdir="/me/MobilePlaceHolder/Temp/StagingArea/Il2Cpp/il2cppOutput" 

I've also tried doing this manually with il2cpp on the cmdline but I can't get it to do a simple HelloWorld.cs file. Is there a blog somewhere that shows how to use it like that?

Show more comments
avatar image

Answer by Warena · Nov 11, 2021 at 02:09 PM

 using UnityEditor;
 using UnityEngine;
 
     public class BuildHacks {
 
         /// <summary>
         /// https://forum.unity.com/threads/android-builds-failing-when-script-debugging-is-enabled.1027357/
         /// Android builds failing when 'Script Debugging' is enabled
         /// </summary>
         [InitializeOnLoadMethod]
         static void FixScriptDebuggingBuildFail()
         {
             Debug.Log("[Build Patch] Android builds failing when 'Script Debugging' is enabled");
             PlayerSettings.SetAdditionalIl2CppArgs("--linker-flags=\"-Wl,--stub-group-size=11534360\"");
         }
     }
 

put script into "Editor" directory like this.

Comment

People who like this

0 Show 0 · 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

Answer by morgoth990 · Nov 19, 2021 at 10:17 AM

Just tested it, you have to use double quotes, with single quotes il2cpp ignore the argument: --compiler-flags="-fembed-bitcode"

Comment

People who like this

0 Show 0 · 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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

228 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

No Line numbers in stack trace for debug android build using IL2CPP 1 Answer

Unity Android IL2CPP Build Error 1 Answer

Can't build for Android with IL2CPP 1 Answer

How to post process Unity-built dll before il2cpp kicks in? 1 Answer

Build problem when Making an IL2CPP build to support 64 android architecture 0 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