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
1
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
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 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 LLV$$anonymous$$ bitcode. So just like the iOS export I'd like the Android one to have embedded bitcode. Since r16 ND$$anonymous$$ 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
2
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
Add comment · 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/ND$$anonymous$$/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="AR$$anonymous$$64" 
 --configuration="Release" 
 --outputpath="/me/$$anonymous$$obilePlaceHolder/Temp/StagingArea/assets/bin/Data/Native/arm64-v8a/libil2cpp.so" 
 --cachedirectory="/me/$$anonymous$$obilePlaceHolder/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/ND$$anonymous$$" 
 --profiler-report 
 --map-file-parser="/Applications/Unity/Hub/Editor/2019.1.0b5/Unity.app/Contents/Tools/$$anonymous$$apFileParser/$$anonymous$$apFileParser" 
 --compiler-flags='-fembed-bitcode'  
 --directory="/me/$$anonymous$$obilePlaceHolder/Temp/StagingArea/assets/bin/Data/$$anonymous$$anaged" 
 --generatedcppdir="/me/$$anonymous$$obilePlaceHolder/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
0

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

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
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

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

Unity Android IL2CPP Build Error 1 Answer

IL2CPP Android Development Build not detected 0 Answers

HELP!! Failed running il2cpp.exe, can't build apk for google play 3 Answers

Unity 2019.2.2f1 android il2cpp build error 0 Answers

Android build reports "Wrong task initialization" 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