Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android App is too large and Linking disables functionality

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>

like image 910
eMi Avatar asked Mar 25 '13 11:03

eMi


1 Answers

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.

like image 181
Stuart Avatar answered Nov 02 '22 21:11

Stuart