Android App is too large and Linking disables func

2019-04-07 01:36发布

问题:

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