Android App is too large and Linking disables functionality

﹥>﹥吖頭↗ 提交于 2019-12-21 10:48:03

问题


I'm done with my app and now I'm trying to build the .apk and test it on my phone (without debug, in release mode).

Setting the Linking to "None" everything works fine. The Problem here is, that the App is too large - its 20MB and thats rubbish.


I read that article about Linking: Click Here

So I tried "Sdk Assemblies Only" and "Sdk and User Assemblies". The second option (Both Assemblies) failed directly, I wasn't even able to see the first screen (Login) of my App.

With Linking set to "Sdk Assemblies Only" I was able to come to the first screen (Loginscreen). The App is also 6.73MB whats much better and more eligible.

The Problem I face now is, that when I click on the Button "Log In" on the first screen, nothing happens (normally it would redirect me to the next Activity).

The Button is binded to a Command:

public IMvxCommand LoginCommand
{
    get
    {
         return new MvxRelayCommand(DoLogin);
    }
}

private void DoLogin()
{
     //Do Stuff
}

Putting a Breakpoint in DoLogin() - shows, that it never walks in.

Well, how could I solve the problem? Seems like the functionality of mvvmcross is disabled for any reason?

My main aim is to reduce the size of app.


Here if important the necessary section from the .csproj

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AndroidUseSharedRuntime>False</AndroidUseSharedRuntime>
<AndroidLinkMode>SdkOnly</AndroidLinkMode>
<AndroidLinkSkip />
<EmbedAssembliesIntoApk>True</EmbedAssembliesIntoApk>


回答1:


With MvvmCross, I generally use SDK Assemblies only.

To then workaround Linker fails for MvvmCross (and for general MonoTouch/MonoDroid issues) then I add LinkerPleaseInclude type files to trick the linker.

An example file is:

public class LinkerIncludePlease
{
    private void IncludeClick(View view)
    {
        view.Click += (s, e) => { };
    }

    private void IncludeVisibility(View view)
    {
        view.Visibility = view.Visibility + 1;
    }

    private void IncludeRelativeLayout(RelativeLayout relative)
    {
        relative.Visibility = ViewStates.Visible;
    }
}

from: https://github.com/slodge/MvvmCross/blob/vnext/Sample%20-%20TwitterSearch/TwitterSearch.UI.Droid/LinkerIncludePlease.cs

It is annoying to have to do this... but it doesn't take long - most apps don't actually bind to many different properties/events.




回答2:


I changes the progressBar include method to

    public void Include(ProgressBar progressBar)
    {
        progressBar.Visibility = progressBar.Visibility;
    }

and it worked. I removed all the others and they all started working. I'm assuming this is working as it is testing both the getter and setter of the ProgressBar Visibility property.

If this is not the correct reason for this working could someone add a comment, so we can all unsterstand how to fix these issues in the future



来源:https://stackoverflow.com/questions/15613694/android-app-is-too-large-and-linking-disables-functionality

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!