简单的Xamarin Android应用程序在VS中起作用,但在电话上失败



我有 samsung a8 电话。 Android 版本-7.1.1

尝试使用 Xamarin Visual Studio 2017 上创建简单的应用程序。在 project属性 ->应用程序我已经设置了" 使用最新paltform(android 7.1(nougat(("。

这是我的源代码。

main.axml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <TextView
        android:text="text1"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/textLizaMath" />
    <Button
        android:text="Click"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/btnLizaMath" />
</LinearLayout>

btnclick.cs:

namespace Core
{
    public static class BtnClick
    {
        public static string GenerateText(string text)
        {
            if (text.Equals("text1")) return "text2";
            return "text1";
        }
    }
}

mainActivity.cs

using Android.App;
using Android.Widget;
using Android.OS;
namespace Mobile
{
    [Activity(Label = "LizaN", MainLauncher = true)]
    public class MainActivity : Activity
    {
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.Main);
            var btn = FindViewById<Button>(Resource.Id.btnLizaMath);
            var lizaText = FindViewById<TextView>(Resource.Id.textLizaMath);
            btn.Click += (sender, e) =>
            {
                var tmpText = Core.BtnClick.GenerateText(lizaText.Text);
                lizaText.Text = tmpText;
            };
        }
    }
}

当我在 vs 中启动它时,它可以按预期工作。然后,我转到 bin/debug 文件夹,然后复制 mobile.mobile.apk mobile.mobile-signed.apk 到我的手机。 Mobile.mobile.apk 根本没有安装它已被损坏。我可以安装 mobile.mobile-signed.apk ,但是当我尝试运行它时,它会崩溃而没有任何有意义的错误消息。

我该怎么办?

更新:

我尝试执行"存档",然后由于错误消息而失败:"共享的单运行时已启用",我去了 project properties -> android选项禁用的" 使用共享运行时"。之后,我能够归档它。应用的大小增加了10倍。我已经复制了所有文件(不仅.apk(,但是当我尝试安装它时,说" package已损坏"(我不知道完全的英语错误消息文本,但它是类似的那(

尝试恢复您的Nuget软件包。更新Xamarin.Forms Nuget。

最新更新