在启用链接的情况下部署发布版本的应用程序时出现问

时间:2013-11-26 14:10:52

标签: android xamarin mvvmcross

我们希望在启用链接时使用发布版本不起作用的项目。因此,我们在一个最小的项目设置中用2个项目隔离了问题:

  • PCL项目:dvit.appfwk.core
  • Android项目:dvit.appfwk.droid

Android项目:dvit.appfwk.droid

PCL项目具有以下概况:

appProfile

在PCL项目中,我们定义了一个接口:

using System;
using System.Collections.Generic;

namespace dvit.appfwk.core
{
    public interface IAzureService
    {
        MobApp MobAppGetItem (int id);
    }
}

在droid项目中,我们将实现:

public MobApp MobAppGetItem (int id)
{
    IMobileServiceTable<MobApp> mobAppTable = MobileService.GetTable<MobApp> ();

    var mobAppQry = mobAppTable.Where (x => x.Id == id);

    var mobApps = mobAppQry.ToListAsync ().Result;

    if (mobApps.Count > 0)
        return mobApps [0];
    else
        return null;
}

我们在“FirstViewModel”类中的PCL中使用此方法(具有所有IOC魔法)。此实现在调试模式和发布模式下完美运行(无链接)。但我们的应用程序需要太多的空间和RAM,所以我们想要启用链接,但随后应用程序不再工作,问题似乎是代码行: var mobApps = mobAppQry.ToListAsync().Result;

问题以某种方式与异步功能的使用相关联。 我在帖子的底部添加了“adb logcat -s”命令的输出。  我们还没有找到一篇很好的文章来解释如何解决MvvMCross中的链接问题,我真的希望有人能够把我们推向正确的方向。

E/appfwk  ( 2202):   0.23 Loading new ViewModel from Intent with Extras
E/appfwk  ( 2202):   0.36 Problem creating viewModel of type FirstViewModel - problem TargetInvocationException: Exception has been thrown by the target of an invocation.
E/appfwk  ( 2202):        at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[] parameters) [0x00000] in <filename unknown>:0
E/appfwk  ( 2202):   at System.Reflection.MonoCMethod.DoInvoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization
o culture) [0x00000] in <filename unknown>:0
E/appfwk  ( 2202):   at System.Reflection.MonoCMethod.Invoke (BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture)
in <filename unknown>:0
E/appfwk  ( 2202):   at System.Reflection.ConstructorInfo.Invoke (System.Object[] parameters) [0x00000] in <filename unknown>:0
E/appfwk  ( 2202):   at Cirrious.CrossCore.IoC.MvxSimpleIoCContainer.IoCConstruct (System.Type type) [0x00000] in <filename unknown>:0
E/appfwk  ( 2202):   at Cirrious.CrossCore.Mvx.IocConstruct (System.Type t) [0x00000] in <filename unknown>:0
E/appfwk  ( 2202):   at Cirrious.MvvmCross.ViewModels.MvxDefaultViewModelLocator.TryLoad (System.Type viewModelType, IMvxBundle parameterValues, IMvxBundle savedState, IMvxViewModel& viewMo
00] in <filename unknown>:0
E/appfwk  ( 2202): InnerException was ArgumentNullException: Argument cannot be null.
E/appfwk  ( 2202): Parameter name: method
E/appfwk  ( 2202):        at System.Delegate.CreateDelegate (System.Type type, System.Object firstArgument, System.Reflection.MethodInfo method, Boolean throwOnBindFailure, Boolean allowClo
00] in <filename unknown>:0
E/appfwk  ( 2202):   at System.Delegate.CreateDelegate (System.Type type, System.Reflection.MethodInfo method, Boolean throwOnBindFailure) [0x00000] in <filename unknown>:0
E/appfwk  ( 2202):   at System.Delegate.CreateDelegate (System.Type type, System.Reflection.MethodInfo method) [0x00000] in <filename unknown>:0
E/appfwk  ( 2202):   at System.Linq.Expressions.Expression.CreateLambda (System.Type delegateType, System.Linq.Expressions.Expression body, System.String name, Boolean tailCall, System.Coll
ectModel.ReadOnlyCollection`1 parameters) [0x00000] in <filename unknown>:0
E/appfwk  ( 2202):   at System.Linq.Expressions.Expression.Lambda (System.Linq.Expressions.Expression body, System.String name, Boolean tailCall, IEnumerable`1 parameters) [0x00000] in <fil
wn>:0
E/appfwk  ( 2202):   at System.Linq.Expressions.Expression.Lambda (System.Linq.Expressions.Expression body, Boolean tailCall, IEnumerable`1 parameters) [0x00000] in <filename unknown>:0
E/appfwk  ( 2202):   at System.Linq.Expressions.Expression.Lambda (System.Linq.Expressions.Expression body, System.Linq.Expressions.ParameterExpression[] parameters) [0x00000] in <filename

E/appfwk  ( 2202):   at Microsoft.WindowsAzure.MobileServices.PartialEvaulator+<EvaluateIndependentSubtrees>c__AnonStorey5.<>m__7 (System.Linq.Expressions.Expression expr, System.Func`2 rec
0] in <filename unknown>:0
E/appfwk  ( 2202):   at Microsoft.WindowsAzure.MobileServices.VisitorHelper.Visit (System.Linq.Expressions.Expression expression) [0x00000] in <filename unknown>:0
E/appfwk  ( 2202):   at System.Linq.Expressions.ExpressionVisitor.VisitBinary (System.Linq.Expressions.BinaryExpression node) [0x00000] in <filename unknown>:0
E/appfwk  ( 2202):   at System.Linq.Expressions.BinaryExpression.Accept (System.Linq.Expressions.ExpressionVisitor visitor) [0x00000] in <filename unknown>:0
E/appfwk  ( 2202):   at System.Linq.Expressions.ExpressionVisitor.Visit (System.Linq.Expressions.Expression node) [0x00000] in <filename unknown>:0
E/appfwk  ( 2202):   at Microsoft.WindowsAzure.MobileServices.VisitorHelper.<Visit>__BaseCallProxy0 (System.Linq.Expressions.Expression node) [0x00000] in <filename unknown>:0
E/appfwk  ( 2202):   at Microsoft.WindowsAzure.MobileServices.VisitorHelper.<Visit>m__8 (System.Linq.Expressions.Expression e) [0x00000] in <filename unknown>:0
E/appfwk  ( 2202):   at Microsoft.WindowsAzure.MobileServices.PartialEvaulator+<EvaluateIndependentSubtrees>c__AnonStorey5.<>m__7 (System.Linq.Expressions.Expression expr, System.Func`2 rec
0] in <filename unknown>:0
E/appfwk  ( 2202):   at Microsoft.WindowsAzure.MobileServices.VisitorHelper.Visit (System.Linq.Expressions.Expression expression) [0x00000] in <filename unknown>:0
E/appfwk  ( 2202):   at System.Linq.Expre
E/appfwk  ( 2219):   0.00 Setup: PlatformServices start

1 个答案:

答案 0 :(得分:1)

只需将Preserve属性添加到您希望链接器不要触摸的类型/成员。

public class Example {
    [Android.Runtime.Preserve]
    public Example ()
    {
    }
}

[Android.Runtime.Preserve(AllMembers=true)]
class Example {
    // Compiler provides default constructor...
}

Linker指南(iOS和Android都有)非常好。

编辑:阿列克谢所说的是正确的。

将类似于下面的XML文件添加到项目中,并将其Build Action设置为 LinkDescription

<linker>
        <assembly fullname="My.Own.Assembly">
                <type fullname="Foo" preserve="fields" />
                        <method name=".ctor" />
                </type>
                <type fullname="Bar" />
                        <method signature="System.Void .ctor(System.String)" />
                        <field signature="System.String _blah" />
                </type>
        </assembly>
</linker>