Unable to build xamarin project to real device - android

I am working on a Xamarin project (Visual Studio 2017). It's working fine in the emulator when run in Debug and Release mode but I am unable to run it in a real device as Visual Studio is not showing any attached device though device is already attached and also developer option and all necessary options are active.
I am also getting the following error when I try to make an APK and run it in a real device:
app not installed, package is corrupted

There can be several reasons for your issue that you don't see the device in the VS dropdown:
You have activated USB Debugging on your device but have not trusted the computer you're connecting to. Just try to deactivate and reactivate debugging. If a dialog appears that asks is you want to trust this computer, than this was your issue.
You have configured a minimum API Level / SDK Version for your app that is higher than the API Level of your device. So just check your Android version on your device and the version you've defined as minimum in your project settings
Regarding the "package corrupt" error, I can think of the following:
You have not signed your apk before you deployed it to the device. Just building the apk is not enough. There is an "archive" menu option in the context menu of your Android app. More info on that can be found here https://learn.microsoft.com/en-us/xamarin/android/deploy-test/release-prep/?tabs=vswin#archive-for-publishing

Build it in release mode. Debug builds aren't signed. Then make an archive and distribute it (ad-hoc-mode). This will create a signed apk. More info: learn.microsoft.com/en-us/xamarin/android/deploy-test/… – Andre Kraemer

Related

How i can build and run my app in android studio

How can i resolve this? After building my app on android studio and running on my phone it works fine but when i share it to another phone it says "There was error parsing this package"
The problem is probably one of the following:
You set a minimum SDK version that is not supported in your friend's device. or maybe you added other restrictions in your app that prevents the APK from being installed on that device.
The APK you're trying to install is considered to be coming from an "unknown source", The Android system prevents you from installing apps from sources that are not known to the system.
To install that APK on your friend's device, you need to enable installing APKs from unknown sources, this setting is by default disabled and can be enabled from the device settings, on some devices you can find this option under Security settings, and on other devices it can be found under the Apps settings

I cannot install .apk which have geneteted from AndroidStudio on my phone

As I have stated in the title I'm struggling with .apk I cannot install application on my phone I'm getting app not installed. But when installing via usb I'm able to install application on the emulator phone. It’s always showing App Not Installed on mobile phone.
When I run application via AndroidStudio to USB the application has been installed. I do not know where I should looking for issues. May be someone had the similat issue.
There are two things you can try:
First of all build your apk by Build/Build Bundles/Build APK and not just by creating apk as a side effect of simply running the app under Android Studio
Make sure no other flavors are installed on your device - sometimes devices offer "Uninstall for all users" - that's what you should be looking for.

Android third party causes "app not installed" error

I have created with the use of android studio a small project and then I generated the signed apk. Then I tried to install it in three phones and in the first one (which has android 8) the app was installed successfully but in the second one (which has android 4.2) and third one (which has android 5) I got the "app not installed" error. This is my second app (project) and my first one has been installed successfully in all these three phones. The minimum SDK version of the app is Android 4.0.3 (API level 15), so that's not causing the problem. Can anyone guess where the problem is?
Sign the apk with both v1 and v2 signatures. this is the most likely culprit given your scenario. apk will not get installed on devices with less than marshmallow if you only sign with v2
Well you can try following:
Change install location of app on the phones it's creating problem.
Try resetting app preferences
Clear Data and Cache of Package Installer
Allow Apps from Unknown Sources (Go to Settings → Security → Unknown Sources. Enable Unknown Sources. And then try installing App)
Try Deleting .android_secure/smdl2tmpl.asec file from your SD Card if using SD card
Resign the app.
Try changing app codes by using some apk editor app

Xamarin Android "app not installed the package appears to be corrupt" when installing a release build apk

Updated Information: I am now discovering that this only seems to be an issue on Android 7 and up. I have multiple devices, and the apk will install on my 6.0.1 Nexus 5. But the Galaxy Tab S2 on 7.0 and the Pixel XL on 9.0 both get this error.
After the Visual Audio Mac update to 7.6.2 (build 33) I all of a sudden cannot install the generated APK for AdHoc distribution. It builds just fine in debug and release mode, but when I archive it and then side load it to a device, I get the message,
"App not installed. The package appears to be corrupt".
I am pulling my hair out on this one. Searching for answers most of the day has turned up very little.
Any hints on what might be the issue?
This was a bug that we recently fixed. The problem was that the wrong apk was signed in Visual Studio for Mac when we changed from jarsigner to apksigner by default, in which gave you an unsigned final apk that users assumed were signed. Please sign your applications manually using the following instructions until the hotfix is released shortly in Visual Studio for Mac 7.6.3.
Manually Signing Docs:
https://learn.microsoft.com/en-us/xamarin/android/deploy-test/signing/manually-signing-the-apk
Original Issue:
https://developercommunity.visualstudio.com/content/problem/317799/major-error-76-build-2190-creates-invalid-apk-for.html
Once you click "Open Folder", look for the folder "signed-apks", you will find the signed apk there, install it on your device. It works for me.

Android Studio 2.3: Autogenerated Debug-APK no longer runs on physical device

I used to test my Android apps (min API 21, target 25) in an API 21 AVD. After clicking the "run app" button in Android Studio, a debug APK was built in {project}/app/build/outputs/apk/. I then copied that APK to my physical API 25 device for further testing.
Since upgrading Android Studio from 2.2.3.0.145.3537739 to 2.3.0.8.162.3764568 on Gentoo Linux, those autogenerated APKs no longer run on the physical device. The apps crash instantly upon startup and the log shows a "java.lang.RuntimeException: Unable to instantiate activity" caused by a "java.lang.ClassNotFoundException: Didn't find class {my main activity class}".
When I build a debug APK manually by clicking on "Build > Build APK", the generated APK has a different file size than the autogenerated one, plus it runs on the physical device without any complaints.
So, there are actually two questions:
1. Why does the manually generated debug APK differ from the autogenerated one?
2. What is causing the autogenerated one to fail on my physical device since Android Studio 2.3? It worked fine with all Studio versions before.
Hoping for some insight, even though USB debugging exists and the process of copying the debug APK to the device is actually pretty pointless. :-)
As a recap of the comments to the question, if Instant Run is enabled then generated debug apk will contain device API specific code hence rendering it not usable on other APIs that it was not built for. Turning off the Instant Run would solve that.

Categories

Resources