我使用Xamarin和Android Studio创建了一个Hello World应用程序。当我进入 App Manager 时,使用Xamarin构建的应用程序的大小为47 Mb,而使用Android Studio的应用程序的大小为12 Mb。我知道跨平台必须更大,但为什么它这么大?是否有任何导出设置可以缩小它?
答案 0 :(得分:10)
It is large because it most contain a package that includes the application, the libraries, the Mono runtime and so on such as the BCL libraries (Base class libraries). Below, you can find how the size of the packages for a a basic release package
For debug, it's a bit different. At first, when debugging on an Android device, it's required to copy 2 larges packages (Shared Runtime & Platform). The first contains the BCL and the mono runtime and the other one contains the specific droid API level that your app would be targeting.
In order to reduce the app size while debugging, you can use fast assembly deployment option. This option enables you to install directly the packages you require on your testing device. Doing so, the app package size is greatly reduced. To do so, find the Options inside of Xamarin Studio. Then, you're going to find the Build section and click on Android Build. Finally, click on both Use shared Mono runtime and the Fast assembly deployment checkboxes. Save your changes and build your app with your device connected and you should be good to go :)
UPDATE 1
After talking about it for a while in the comments, I found that it would be best to have all the relevant information in here instead of forcing the reader to go downs in the commentary section and find out more about what he/she came here to find. So I was ask about about the way one would be able to reduce the app size in Release mode. In the release mode, you're going to have to use the post of the @kent.green concerning Linking. A quick overview of the post: Linking enables you to moves from an app with a size of 14.0 Mb to 4.4 Mb by using static analysis and removing assemblies that aren't use by the app in any way possible. For people looking for something similar for iOS, take a look at this post.
Also, the OP was concerned about the debug mode of his/her app. The OP wanted to know if by enabling fast assemblies deployment if one would lose functionalities such as resources monitoring or crash reports. I responded by saying that, from on a technical point of view, the fact remains that the same functionality is there. Instead of having an app package of size X, the size of the package is being reduced by using the your testing device and put "unnecessary" stuff there to make the package smaller. I do not think that both Shared libraries are being affected by this.