简体   繁体   English

Xamarin - Android - Visual Studio - 应用程序无法启动

[英]Xamarin - Android - Visual Studio - The application could not be started

I was working on an Android project using Xamarin in Visual Studio 2012. I recently upgraded from an HDD to a SSD so I reinstalled Windows and all of my programs.我在 Visual Studio 2012 中使用 Xamarin 处理 Android 项目。我最近从 HDD 升级到 SSD,因此我重新安装了 Windows 和我的所有程序。

After cloning my git repository and trying to run the application on my device, I have not been able to get it to run.克隆我的 git 存储库并尝试在我的设备上运行该应用程序后,我无法让它运行。 I was able to start a new hello world project and I got that to run, but I can't get this project to run.我能够开始一个新的 hello world 项目并且我可以运行它,但是我无法运行这个项目。

This is what the error says:这是错误所说的:

The application could not be started.应用程序无法启动。 Ensure that the application has been installed to the target device and has a launchable activity (MainLauncher = true).确保应用程序已安装到目标设备并具有可启动的活动 (MainLauncher = true)。

Additionally, check Build->Configuration Manager to ensure this project is set to Deploy for this configuration.此外,检查 Build->Configuration Manager 以确保将此项目设置为 Deploy 以进行此配置。

I have searched for a solution to this issue but have been unable to find anything that worked.我一直在寻找解决此问题的方法,但找不到任何有效的方法。

I solved the issue.我解决了这个问题。 Somehow the application still existed on my device even though it did not show up in my applications and I needed to remove it.不知何故,该应用程序仍然存在于我的设备上,即使它没有出现在我的应用程序中,我需要将其删除。

The solution was to find an old APK that I had emailed and I installed that.解决方案是找到我通过电子邮件发送的旧 APK 并安装了它。 Then I uninstalled the application and deployed it again from Visual Studio.然后我卸载了该应用程序并从 Visual Studio 再次部署它。 This time it worked.这次成功了。

You can read more here: https://forums.xamarin.com/discussion/8501/install-failed-update-incompatible您可以在此处阅读更多信息: https : //forums.xamarin.com/discussion/8501/install-failed-update-incompatible

EDIT (March 13th, 2017):编辑(2017 年 3 月 13 日):

Seems a lot of people found this answer useful so I decided I should update it with an alternate method to uninstall the app if you don't have access to an old version.似乎很多人发现这个答案很有用,所以我决定如果您无法访问旧版本,我应该使用替代方法更新它以卸载该应用程序。

As Atul Chaudhary and Nestel mentioned, you can open up your adb command prompt and run adb uninstall <com.your.application.package.name> .正如 Atul Chaudhary 和 Nestel 提到的,您可以打开 adb 命令提示符并运行adb uninstall <com.your.application.package.name> If there are any remnants of your application which remain this should get rid of them.如果您的应用程序仍有任何残余,则应将其清除。

在此处输入图片说明

  1. Renamed Application name.重命名应用程序名称。

  2. Added Package name.添加了包名称。

App.应用程序。 started working on Emulator, Renamed application again, app.开始在模拟器上工作,再次重命名应用程序,应用程序。 continued to run.继续跑。

Note: Resetting device, un-installing the app.注意:重置设备,卸载应用程序。 and related runtime etc. from settings did not work for me.设置中的相关运行时等对我不起作用。

Hope this helps someone.希望这可以帮助某人。

Running this command from the adb shell solved it for me:从 adb shell 运行此命令为我解决了这个问题:

adb shell pm uninstall -k com.packagename

To access the adb shell from Visual Studio Tools -> Android -> Android Adb Command Prompt.从 Visual Studio 工具 -> Android -> Android Adb 命令提示符访问 adb shell。

Very interesting error, seems like Visual Studio is unable to unistall the previous version completely.非常有趣的错误,似乎 Visual Studio 无法完全卸载以前的版本。

Obviously the OP figured out the issue to their problem but I still wanted to post an answer relating to an issue I had with the same error message.显然 OP 找出了他们问题的问题,但我仍然想发布与我遇到的问题相关的答案,并显示相同的错误消息。 I am using Visual Studio (within Parallels) and attempting to debug the app on a Xamarin Android Player instance (which is running on my Mac).我正在使用 Visual Studio(在 Parallels 内)并尝试在 Xamarin Android Player 实例(在我的 Mac 上运行)上调试应用程序。

I kept getting this error and realized that a different, more helpful, error message was showing up in the Build Output saying that I was not supporting the correct architecture.我不断收到此错误,并意识到构建输出中显示了一条不同的、更有帮助的错误消息,指出我不支持正确的架构。

Heading into the Android Project Properties -> Android Options -> Advanced -> and checking x86 finally allowed my to successfully deploy to the Xamarin Android Player.进入 Android 项目属性 -> Android 选项 -> 高级 -> 并检查x86最终允许我成功部署到 Xamarin Android Player。

The ADB approach does not worked for me.亚行的方法对我不起作用。 I did not want to factory reset my phone nor uninstall my apps so I have managed to deploy by changing the package.我不想恢复出厂设置我的手机也不想卸载我的应用程序所以我设法通过更改包进行部署。

  1. Right click on your Droid project右键单击您的 Droid 项目
  2. Select Properties选择属性
  3. Got to Application Manifest进入应用程序清单
  4. Change the Package name更改包名称
  5. Re-deploy your project重新部署您的项目在此处输入图片说明

Hope this helps希望这可以帮助

I had the same error today, trying to run Xamarin Android-app on Xamarin Android Player.我今天遇到了同样的错误,试图在 Xamarin Android Player 上运行 Xamarin Android-app。 To fix it I needed to check the "x86" box at the "Supported architectures" section.要修复它,我需要选中“支持的架构”部分中的“x86”框。 So you might want check this section.所以你可能想检查这个部分。

I experienced this problem when there was not sufficient memory on device.当设备上没有足够的内存时,我遇到了这个问题。 After "successful" deployment the app was missing even from the app list in Settings. “成功”部署后,即使在“设置”中的应用程序列表中也缺少该应用程序。 Deleting through adb gave me Failure which indicated it was not installed.通过 adb 删除给了我失败,表明它没有安装。 In Output log in VS2015 I was having the same message as OP.在 VS2015 的输出日志中,我收到了与 OP 相同的消息。 Finally it worked after I cleaned up about 50-100 MB, even though in App Settings it showed me that there were 500 MB free.最后它在我清理了大约 50-100 MB 后工作了,即使在应用程序设置中它显示我有 500 MB 可用空间。 I tried different solutions (deleting through adb, cleaning, building then deploying) but only cleaning up worked.我尝试了不同的解决方案(通过 adb 删除、清理、构建然后部署)但只有清理工作。

adb uninstall did the trick. adb uninstall 做到了。 The strange thing is that even if you run the command to list all app that are installed it will not show up but if you run the uninstall command with ur package name which should be ur project name or name that you have assigned you will get the success result which means it got uninstalled and to check that if run the uninstall command again with same package name u will get failure command.奇怪的是,即使您运行命令列出所有已安装的应用程序,它也不会显示,但是如果您使用您的包名称运行卸载命令,您的包名称应该是您的项目名称或您分配的名称,您将获得成功结果这意味着它已被卸载并检查是否使用相同的包名称再次运行卸载命令,您将获得失败命令。 Then deploying ur package again should work然后再次部署你的包应该可以工作

In my case issue was two activities were Launcher activities,so I made one of them Launcher activity.就我而言,问题是两个活动是 Launcher 活动,所以我做了其中一个 Launcher 活动。

You can remove <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> from AndroidManifest.xml file or MainLauncher = true from .cs Activity file attribute您可以从 AndroidManifest 中删除<intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> .xml 文件或MainLauncher = true来自 .cs 活动文件属性

If you've reinstalled everything you may have to set the configuration manager back up in VS.如果您重新安装了所有内容,则可能需要在 VS 中备份配置管理器。

In Visual Studio: Build -> Configuration Manager -> Put a check in the "Deploy" box.在 Visual Studio 中:构建 -> 配置管理器 -> 勾选“部署”框。

I've managed to solve it by wiping user data from emulator.我设法通过从模拟器中擦除用户数据来解决它。

From AVD Manager, when you start the emulator, check "Wipe user data" and your emulated device will behave like new.在 AVD 管理器中,当您启动模拟器时,选中“擦除用户数据”,您的模拟设备将像新设备一样运行。

Problem itself appeared after updating to Android SDK Tools 25.1.3.问题本身在更新到 Android SDK Tools 25.1.3 后出现。

I could not get this working, initially.最初,我无法使其正常工作。 Tried removing everything (Mono runtime, app, etc.), but to no avail.尝试删除所有内容(Mono 运行时、应用程序等),但无济于事。

What did work was renaming my package, which was fine in my case since I haven't release my apk yet.什么工作是重命名我的包,这对我来说很好,因为我还没有发布我的 apk。 Some ghost version is obviously still stored on my unit.一些幽灵版本显然仍然存储在我的设备上。

重命名应用程序名称和包名称(转到清单设置)有助于解决此问题

The only alternatives which help me solve this were the following:帮助我解决此问题的唯一替代方法如下:

  • From the Xamarin Android Studio home page (where all devices are displayed), click on the "three-dots" button and then Factory Reset .从 Xamarin Android Studio 主页(显示所有设备),单击“三点”按钮,然后单击Factory Reset

OR或者

  • Install a new device and deploy your app there.安装新设备并在那里部署您的应用程序。

Whenever I encounter this problem, I publish the app and install in manually using每当我遇到这个问题时,我都会发布应用程序并使用手动安装

adb install "<path to apk file>"

in the Android Adb Command Prompt.在 Android Adb 命令提示符中。

Hopefully, a fix is out soon, according to https://github.com/xamarin/xamarin-android/issues/3727希望尽快修复,根据https://github.com/xamarin/xamarin-android/issues/3727

Happened to me today, after updating a project from Git and running in Android Emulator.今天发生在我身上,从 Git 更新一个项目并在 Android Emulator 中运行后。 Uninstalling the app from emulator, performing Clean and Rebuild in VS and instaling the application again helped.从模拟器卸载应用程序,在 VS 中执行清理和重建并再次安装应用程序有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM