I have an obfuscated application in Monodroid and my problem is that the mscorlib assembly included in apk doesn’t implements the method System.String.Intern() and my application doesn’t work.
My obfuscator calls this method to obfuscate strings and I get a MissingMethodException. This method doesn’t exists in the assembly included in apk but strangely it does exists in myproject/obj/release/assemblies/mscorlib.dll
These files are quite different. If I put the file myproject/obj/release/assemblies/mscorlib.dll in apk it works but this solution is a bad solution because the app fails in other point causing TypeLoadException because of the change of the dll.
Can anyone tell me why monodroid uses the mscorlib reduced file and an alternative solution?
Thanks.
The smaller file is used to reduce application size by linking the assemblies. Linking can be brittle, as the linker doesn’t trace runtime behavior. For example, using
Type.GetType("Foo")will not preserve the typeFoo, and thus the linker may remove it if it’s not otherwise referenced.obj\Release\assemblies\mscorlib.dllis the source assembly.obj\Release\android/assets/mscorlib.dllis the linked (smaller) assembly, which is included in the.apk.If your obfuscator is directly using
String.Intern(), this may suggest a bug in the linker. However, if your obfuscator is using Reflection (e.g.Type.GetMethod()), then this would be expected behavior. To fix it, you explicitly useString.Intern()within a falseflag block so that the method is preserved.