Search Unity

  1. We would like to hear your feedback about Unity and our products. Click here for more information.
    Dismiss Notice

Android code stripping problem in very old unity verion(4.7.2)

Discussion in 'Scripting' started by wxlbupt1988, Jan 12, 2019.

  1. wxlbupt1988


    Jan 10, 2019
    For some reason, My project are still using Unity4.7.2

    A fews days ago, we have refactor our game project. After that, our Android build have experience this error:

    01-08 15:20:33.732: E/Unity(6807): Assert failed! ConsoleViewMobile Exception: Method not found: 'Default constructor not found...ctor() of System.ComponentModel.Int32Converter'. , Stack: at System.Activator.CreateInstance (System.Type type, Boolean nonPublic) [0x00000] in <filename unknown>:0
    01-08 15:20:33.732: E/Unity(6807): at System.Activator.CreateInstance (System.Type type) [0x00000] in <filename unknown>:0
    01-08 15:20:33.732: E/Unity(6807): at System.ComponentModel.TypeDescriptor.GetConverter (System.Type type) [0x00000] in <filename unknown>:0

    Code (CSharp):
    1.    public static T SmartConvert<T>(string InArgument)
    2.     {
    3.         var TypeConverter = TypeDescriptor.GetConverter(typeof(T));
    5.         if (TypeConverter != null)
    6.         {
    7.             DebugHelper.Assert(TypeConverter.CanConvertFrom(typeof(string)));
    9.             return (T)TypeConverter.ConvertFrom(InArgument);
    10.         }
    12.         return default(T);
    13.     }
    And meantime, same code runs fine in iOS build.
    My suspicion: Unity strip some unused code. Before our refactoring, we may have reference those code somewhere, so everything runs fine. Then we remove those references during refactoring, so error happens.
    We finally reslove this problem by adding reference manully like this:
    Code (CSharp):
    1.     private static System.ComponentModel.Int64Converter _unused = new System.ComponentModel.Int64Converter();
    2.     private static System.ComponentModel.DecimalConverter _unused2 = new System.ComponentModel.DecimalConverter();
    3.     private static System.ComponentModel.ByteConverter _unused3 = new System.ComponentModel.ByteConverter();
    4.     private static System.ComponentModel.CollectionConverter _unused4 = new System.ComponentModel.CollectionConverter();
    And it works.

    So my question is:How does Unity strip code in Android in early version(4.7.2)? Or could someone give me some documents about that? there is no il2cpp included. and i cannot find any documents for that version :( unity old version link seems all dead.
  2. SparrowsNest


    Apr 6, 2017
    I don't have any help to offer as I'm a PC dev and I have basically zero experience with unity 4, but why are you on such an old version?
  3. wxlbupt1988


    Jan 10, 2019
    because its a huge project start like 4 or 5 year ago and aleady online for a long time. we didnt upgrade it for stability concerns
  4. Kurt-Dekker


    Mar 16, 2013
    It's been so many years of Unity5 and then Unity201x, I couldn't even tell you anymore. I seem to recall you could put in some kind of xml file listing what you didn't want it to strip.

    But honestly, I never used that xml file because it was "out of sight." I always just put in references like what you did. There's nothing wrong with that approach.

    Keep in mind as you encounter more and more odd Unity4 errors, the time you spend fixing those is completely wasted, whereas if you consider an exploratory upgrade to a more modern version, you might find a lot of stuff just works fine, and at least you'll be "with the herd," learning and improving your skills and your codebase.

    WARNING: do not upgrade unless you have your entire project safely in source control, and only do an upgrade in an experimental way, like take a few days to try it out on modern devices with modern Unity!!!
    Ryiah likes this.
  5. wxlbupt1988


    Jan 10, 2019
    thanks for you reply. yes, there is a link.xml way to tell unity to keep code for reflection. in Unity playersettings, there is a Stripping Level option. and I turn it off in Android. but when save settings to ProjectSettings.asset, it name became iPhoneStrippingLevel. i dont know its bug or this option only works on IOS. damn 4.7.2
  6. doctorpangloss


    Feb 20, 2013
    Kurt-Dekker likes this.