1

Yesterday I've downloaded the new version of Xamarin.Android which was 4.6.2. When I tried to build my project which correctly worked in previous versions (<4.6) now I get the following error:

(sorry it's in Russian)

Ошибка  1   непредвиденная ошибка при выполнении задачи "LinkAssemblies".
System.ArgumentOutOfRangeException: Заданный аргумент находится вне диапазона допустимых значений.
в Mono.Collections.Generic.Collection`1.get_Item(Int32 index)
в Mono.Cecil.Mdb.MdbReader.ReadLocalVariables(MethodEntry entry, MethodBody body, Scope[] scopes)
в Mono.Cecil.Mdb.MdbReader.Read(MethodBody body, InstructionMapper mapper)
в Mono.Cecil.Cil.CodeReader.ReadMethodBody()
в Mono.Cecil.Cil.CodeReader.ReadMethodBody(MethodDefinition method)
в Mono.Cecil.MethodDefinition.<get_Body>b__2(MethodDefinition method, MetadataReader reader)
в Mono.Cecil.ModuleDefinition.Read[TItem,TRet](TItem item, Func`3 read)
в Mono.Cecil.MethodDefinition.get_Body()
в Mono.Linker.Steps.MarkStep.ProcessMethod(MethodDefinition method)
в Mono.Linker.Steps.MarkStep.ProcessQueue()
в Mono.Linker.Steps.MarkStep.Process()
в Mono.Linker.Steps.MarkStep.Process(LinkContext context)
в Mono.Linker.Pipeline.Process(LinkContext context)
в MonoDroid.Tuner.Linker.Process(LinkerOptions options, LinkContext& context)
в Xamarin.Android.Tasks.LinkAssemblies.Execute()
в Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
в Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__20.MoveNext() AndroidApplication7

Text in russian means:

Error 1 Unexpected error while trying to execute task "LinkAssemblies".
System.ArgumentOutOfRangeException: Provided argument is out off range

I've spent a lot of time trying to understand this bug and found that the bug appears when (both):

  1. using Android.Support.V4 lib
  2. building with linking mode set to Full

So, I think this is the Linker bug connected with the Support Library. No matter what class or namespace of Android.Support.V4 is used the bug appears instantly.

Trying to make things clear I've made a sample project with one FragmentActivity and one DialogFragment nothing else. And I've reproduced this issue on it!

I want to know is there whether the temporary or instant solution to this breaking issue? This is very important, cause this freezes our development process. Yes, I know that this issue was posted to bug-tacker https://bugzilla.xamarin.com/show_bug.cgi?id=7946

Here is how I made my Sample Project.

  1. Pressed "New project" in Visual Studio 2012 and selected "Android Application"
  2. Changed "Minimum Android to target" to 1.6
  3. Set "Configuration properties" "Linking" to "Sdk and User Assemblies"
  4. Added reference to Android.Mono.Support.V4
  5. Added\Changed two source files

Activity1:

public class Activity1 : FragmentActivity
{
    int count = 1;

    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        // Set our view from the "main" layout resource
        SetContentView(Resource.Layout.Main);

        // Get our button from the layout resource,
        // and attach an event to it
        Button button = FindViewById<Button>(Resource.Id.MyButton);

        button.Click += delegate { button.Text = string.Format("{0} clicks!", count++);
                                     DialogFragment messageFragment = MyDialogFragment.GetInstance();
                                     messageFragment.Show(SupportFragmentManager, "MessageDialog");
        };
    }
}

MyDialogFragment:

 public class MyDialogFragment : DialogFragment
 {
    public override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
    }

    public static MyDialogFragment GetInstance()
    {
        return new MyDialogFragment();
    }

    public override Dialog OnCreateDialog(Bundle savedInstanceState)
    {
        var builder = new AlertDialog.Builder(Activity);
        builder.SetMessage("Message");
        builder.SetPositiveButton("Ok", (sender, args) => { });

        return builder.Create();
    }

}

I think anyone can reproduce it. If not please comment on what you've done.

4

1 回答 1

0

Xamarin.Android 4.6.2 存在链接器问题,解决方法是执行以下操作:

备份和编辑 /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets

删除对 CopyMdbFiles 的所有引用

该信息来自 Xamarin 工程师 Jon P

如果您不想这样做,您可以暂时降级到 4.6,直到发布修复程序(应该在接下来的几天内)。我已经验证 4.6 没有这个问题(好吧,我的应用程序至少在使用 4.6 构建时是使用 Release 配置构建的)。

希望有帮助。

于 2013-04-13T05:11:21.490 回答