Android 应用无法部署到虚拟设备

Android App can't deploy to virtual device

背景:
我正在使用 Xamarin.Forms 创建一个内部移动应用程序,通过网络链接分发。我已经 Android 和 iOS 以及 运行 了几天,但是请求是推送通知。我们决定与 Pushwoosh 一起提供该服务。

我已经从 pushwoosh 复制了示例代码,并使用我们的包名和密钥对其进行了修改,但由于某种原因,我得到了错误:
应用程序无法启动。确保应用程序已安装到目标设备并具有可启动的 activity (MainLauncher = true)。<br> 此外,检查 Build->Configuration Manager 以确保针对此配置将此项目设置为 Deploy。

我还应该注意到 Pushwoosh 使用 GCM,所以它也可能与此有关。

我试过的:
1. 我的第一步显然是检查配置管理器。它确实设置为 Deploy 并且设置为编译 x86(其他问题的一些其他答案提到了修复)
2. 我确认我的 MainActivity.cs 文件中的 activity 确实设置为 MainLauncher=true.
3. 根据其他question/answers的推荐,我已经从虚拟android中删除了该应用程序。 (实际上我完全重置了虚拟设备)。
4. 正如一些 GCM 特定 QA 中提到的,我已将我的包名称更改为全部小写。

我的相关代码:

[Activity(Label = "mobile", Icon = "@drawable/icon", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
[IntentFilter(new string[] { "company.MESSAGE" }, Categories = new string[] { "android.intent.category.DEFAULT" })]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsApplicationActivity
{
    LocalMessageBroadcastReceiver mMessageReceiver;
    LocalRegisterBroadcastReceiver mRegisterReceiver;

    bool mBroadcastPush = true;

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

        mMessageReceiver = new LocalMessageBroadcastReceiver();
        mMessageReceiver.activity = this;

        mRegisterReceiver = new LocalRegisterBroadcastReceiver();
        mRegisterReceiver.activity = this;
        registerReceivers();

        PushManager manager = PushManager.GetInstance(this);
        manager.OnStartup(this);

        //Register for push!
        manager.RegisterForPushNotifications();

        checkMessage(Intent);

        global::Xamarin.Forms.Forms.Init(this, bundle);
        LoadApplication(new App());
    }

    protected override void OnNewIntent(Intent intent)
    {
        checkMessage(intent);
    }

    public void checkMessage(Intent intent)
    {
        if (null != intent)
        {
            if (intent.HasExtra(PushManager.PushReceiveEvent))
            {
                doOnMessageReceive(intent.Extras.GetString(PushManager.PushReceiveEvent));
            }
            else if (intent.HasExtra(PushManager.RegisterEvent))
            {
                doOnRegistered(intent.Extras.GetString(PushManager.RegisterEvent));
            }
            else if (intent.HasExtra(PushManager.UnregisterEvent))
            {
                doOnUnregisteredError(intent.Extras.GetString(PushManager.UnregisterEvent));
            }
            else if (intent.HasExtra(PushManager.RegisterErrorEvent))
            {
                doOnRegisteredError(intent.Extras.GetString(PushManager.RegisterErrorEvent));
            }
            else if (intent.HasExtra(PushManager.UnregisterErrorEvent))
            {
                doOnUnregistered(intent.Extras.GetString(PushManager.UnregisterErrorEvent));
            }

            resetIntentValues();
        }
    }

    public void doOnRegistered(String registrationId)
    {
        // code to run if device has succesfully registered
    }

    public void doOnRegisteredError(String errorId)
    {
        // code to run if device failed to register
    }

    public void doOnUnregistered(String registrationId)
    {
        // code to run if device has succesfully unregistered
    }

    public void doOnUnregisteredError(String errorId)
    {
        // code to run if device failed to unregister properly
    }

    public void doOnMessageReceive(String message)
    {
        // code to run when device receives notification
    }
    private void resetIntentValues()
    {
        Intent mainAppIntent = Intent;

        if (mainAppIntent.HasExtra(PushManager.PushReceiveEvent))
        {
            mainAppIntent.RemoveExtra(PushManager.PushReceiveEvent);
        }
        else if (mainAppIntent.HasExtra(PushManager.RegisterEvent))
        {
            mainAppIntent.RemoveExtra(PushManager.RegisterEvent);
        }
        else if (mainAppIntent.HasExtra(PushManager.UnregisterEvent))
        {
            mainAppIntent.RemoveExtra(PushManager.UnregisterEvent);
        }
        else if (mainAppIntent.HasExtra(PushManager.RegisterErrorEvent))
        {
            mainAppIntent.RemoveExtra(PushManager.RegisterErrorEvent);
        }
        else if (mainAppIntent.HasExtra(PushManager.UnregisterErrorEvent))
        {
            mainAppIntent.RemoveExtra(PushManager.UnregisterErrorEvent);
        }

        Intent = mainAppIntent;
    }

    protected override void OnResume()
    {
        base.OnResume();

        registerReceivers();
    }

    protected override void OnPause()
    {
        base.OnPause();

        unregisterReceivers();
    }

    public void registerReceivers()
    {
        IntentFilter intentFilter = new IntentFilter(PackageName + ".action.PUSH_MESSAGE_RECEIVE");

        if (mBroadcastPush)
        {
            RegisterReceiver(mMessageReceiver, intentFilter);
        }

        RegisterReceiver(mRegisterReceiver, new IntentFilter(PackageName + "." + PushManager.RegisterBroadCastAction));
    }

    public void unregisterReceivers()
    {
        UnregisterReceiver(mMessageReceiver);
        UnregisterReceiver(mRegisterReceiver);
    }
}

1

        

    
    <许可 android:name="PACKAGE_NAME.permission.C2D_MESSAGE" android:protectionLevel="signature" />
    <使用权限 android:name="PACKAGE_NAME.permission.C2D_MESSAGE" />
    
    <应用程序 android:label="Company Mobile" android:icon="@drawable/icon">
        <元数据android:name="com.google.android.gms.version"android:value="XXXXXXXX"/>
        <元数据 android:name="PW_APPID" android:value="XXXXX-XXXXX" />
        <元数据 android:name="PW_PROJECT_ID" android:value="XXXXXXX-XXXXXX-XXXXXXX" />
        
        <接收者 android:name="com.google.android.gms.gcm.GcmReceiver" android:exported="true" android:permission="com.google.android.c2dm.permission.SEND">
            <意图过滤器>
                <动作android:name="com.google.android.c2dm.intent.RECEIVE" />
                <类别android:name="com.company.mobile" />
            
        
    

我承认我是 android 开发的新手(但不是 .net 或 C#),所以这可能是相对明显的事情,但我不知所措。我查看了我能找到的与此相关的每个问题,并且 none 的解决方案有所帮助。谁能看出我做错了什么?

我相信这两行:

<permission android:name="PACKAGE_NAME.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="PACKAGE_NAME.permission.C2D_MESSAGE" />

PACKAGE_NAME 应更改为您的实际包名称,在您的情况下是 com.company.mobile<manifest> 元素中的 package 属性 ).

所以尝试:

<permission android:name="com.company.mobile.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.company.mobile.permission.C2D_MESSAGE" />