Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uninstalled app is not redeployed #3727

Closed
jpobst opened this issue Oct 2, 2019 · 12 comments
Closed

Uninstalled app is not redeployed #3727

jpobst opened this issue Oct 2, 2019 · 12 comments
Assignees
Labels
Area: App+Library Build Issues when building Library projects or Application projects.

Comments

@jpobst
Copy link
Contributor

jpobst commented Oct 2, 2019

Steps to Reproduce

  1. F5 on app using Shared Runtime + Fast Deployment
  2. App runs fine
  3. Close app
  4. Uninstall app on device
  5. F5

Expected Behavior

App is redeployed to device and debugging succeeds.

Actual Behavior

Error: Device could not find component named: com.companyname.deleteable/md52d2c55cfc97a76782f55285793be350d.MainActivity
The application could not be started. Ensure that the application has been installed to the target device and has a launchable activity (MainLauncher = true).
Additionally, check Build->Configuration Manager to ensure this project is set to Deploy for this configuration.
Couldn't connect debugger. You can see more details in Xamarin Diagnostic output and the full exception on logs.

Note that retrying a second time succeeds.

Version Information

VS 2019 16.3.2

Log File

build.log

@jpobst jpobst added the Area: App+Library Build Issues when building Library projects or Application projects. label Oct 2, 2019
@dellis1972
Copy link
Contributor

So it looks like out Task which detects if the app has been uninstalled is not completing before the _Upload target runs. So we need to take a look at that.

Also we should check to make sure the Shared Runtime etc is still installed.

@dellis1972 dellis1972 added this to the Under Consideration milestone Oct 2, 2019
@dellis1972
Copy link
Contributor

dellis1972 added a commit to dellis1972/xamarin-android that referenced this issue Oct 3, 2019
Context dotnet#3727

Somehow sometimes the code we have does NOT detect
that the user uninstalled the app. As a result the
`_Upload` target does not run. This commit just adds
some additional checks to make sure we skip that target
when we should, and run it when we need to.
jonpryor pushed a commit that referenced this issue Oct 3, 2019
Context: #3727

Sometimes the `_Upload` target code does NOT detect that the user
uninstalled the app, which means the `_Upload` target does not run.

We do not yet understand *why* this happens.

Add some additional checks to the
`InstallTests.ReInstallIfUserUninstalled()` unit test which assert
that the target is skipped when it should be skipped, and executed
when it should be executed.

Hopefully this might help us detect if and when this problem happens
on our CI build system when unit tests are executed.
jonpryor added a commit that referenced this issue Oct 21, 2019
@dellis1972
Copy link
Contributor

A fix for this issue was merged via xamarin/monodroid@663fa21 and xamarin/monodroid@400af80

@brendanzagaeski
Copy link
Contributor

Release status update

A new Preview version has now been published on Windows that includes the fix for this item. The fix is not yet included in a Release version. I will update this item again when a Release version is available that includes the fix.

The fix is not yet available on macOS. I will update this item again when a Preview version with the fix is available on macOS.

Fix included in Xamarin.Android 10.2.0.16.

Fix included on Windows in Visual Studio 2019 version 16.5 Preview 1. To try the Preview version that includes the fix, check for the latest updates in Visual Studio Preview.

Fix not yet available on macOS.

@brendanzagaeski
Copy link
Contributor

Release status update

A new Preview version has now been published on macOS that includes the fix for this item.

Fix included in Xamarin.Android 10.2.0.84.

Fix included on macOS in Visual Studio 2019 for Mac version 8.5 Preview 1. To try the Preview version that includes the fix, check for the latest updates on the Preview updater channel.

(Fix also included on Windows in Visual Studio 2019 version 16.5 Preview 1 and higher. To try the Preview version that includes the fix, check for the latest updates in Visual Studio Preview.)

@brendanzagaeski
Copy link
Contributor

Release status update

A new Release version has now been published on Windows that includes the fix for this item. The fix is not yet published in a Release version on macOS. I will update this item again when a Release version is available on macOS that includes the fix.

Fix included in Xamarin.Android 10.2.0.100.

Fix included on Windows in Visual Studio 2019 version 16.5. To get the new version that includes the fix, check for the latest updates or install the latest version from https://visualstudio.microsoft.com/downloads/.

(Fix also included on macOS in Visual Studio 2019 for Mac version 8.5 Preview 1 and higher. To try the Preview version that includes the fix, check for the latest updates on the Preview updater channel.)

@brendanzagaeski
Copy link
Contributor

Release status update

A new Release version has now been published on macOS that includes the fix for this item.

Fix included in Xamarin.Android 10.2.0.100.

Fix included on macOS in Visual Studio 2019 for Mac version 8.5. To get the new version that includes the fix, check for the latest updates on the Stable updater channel.

(Fix also included on Windows in Visual Studio 2019 version 16.5 and higher. To get the new version that includes the fix, check for the latest updates or install the latest version from https://visualstudio.microsoft.com/downloads/.)

@EJocys
Copy link

EJocys commented Apr 28, 2020

I still have same bug. Visual Studio & Xamarin just frequently fails to deploy and fails to start debugging session with:

Error: Device could not find component named: com.package.name/crc<MD5>.SplashActivity
The application could not be started. Ensure that the application has been installed to the target device and has a launchable activity (MainLauncher = true).
Additionally, check Build->Configuration Manager to ensure this project is set to Deploy for this configuration.
Couldn't connect debugger. You can see more details in Xamarin Diagnostic output and the full exception on logs.

I have to use reliable workaround, which is:

Forcing Visual Studio to create *.apk file on every debug build by adding AndroidBuildApplicationPackage element inside Debug property group of *.Android.csproj file:

  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <AndroidBuildApplicationPackage>true</AndroidBuildApplicationPackage>
    ...

Running DOS batch script ClearApp_Reinstall.bat, which deploys new debug *.apk manually to the Android phone or emulator:

SET app=com.package.name
SET adb=%ProgramFiles(x86)%\Android\android-sdk\platform-tools\adb.exe
"%adb%" uninstall "%app%"
"%adb%" push "Mobile.Android\bin\Debug\%app%-Signed.apk" "/data/local/tmp"
"%adb%" shell chmod 750 "/data/local/tmp/*.apk"
"%adb%" shell pm install -t -r "/data/local/tmp/%app%-Signed.apk"

Basically: Build, run the batch file and then start debugging.

@dellis1972
Copy link
Contributor

@EJocys if you are getting this on a regular basis could you install the Project System Tools extension in Visual Studio (https://marketplace.visualstudio.com/items?itemName=VisualStudioProductTeam.ProjectSystemTools).

You can then use that to get us the binlog files we need to figure out what is happening on your machine. You can see the instructions on how to use the tool here https://github.com/dotnet/project-system-tools#features.

Basically we need the logs for the Build and Install targets, they will appear in the Project System Tools window.

Under normal operations what should happen is you click Run in Visual Studio and it will detect if the app a) has been updated and needs to be installed or b) does not exist on the device and needs to be installed. The Install target is the msbuild target which handles that. It is called by the IDE when you hit run.

It would also be interesting to see the settings you have in your Debug configuration so we can make sure you are correctly setup for debugging.

@EJocys
Copy link

EJocys commented Apr 28, 2020

Issue starts with Visual Studio failing to build and deploy *.apk, which contains changed code. VS just just skips deployment process and starts old app for debugging. So, as a workaround I am uninstalling the app directly from the phone. This will trigger "Error: Device could not find component named:..." error when trying to debug. Visual Studio throws this error immediately, without any building or deploying. Build logging shows event below and trying to save anything saves nothing:

FailingToBuild

Now there is interesting part. If I open Android project properties, go to "Android Options" and keep tab open (which makes Visual Studio not to loose focus from the Android Project in Solution Explorer) then sooner or later this line appears:

FailingToBuild_2

Now, it is possible to save some logs. Also, selecting Android project and doing "Debug -> Start New Instance" results in Visual Studio deploying and starting new debug session successfully.

So, opening "Android Options" will trigger some event, which will resolve the error which is the topic of this issue.

I can rinse and repeat this with:

a) Going to *.Mobile shared Xamarin project and changing one value in the code like "var x = 2;" then,
b) Uninstalling the app from the mobile phone and
c) trying to start debug again.

Firs time it does some building and then just fails with the error: "Error: Device could not find component named:..." then just fails reliably and immediately with the same error unless I open "Android Options" of Android project (which is workaround 2).

P.S. I have all up to date in Visual Studio 2019 via Visual Studio Installer.

@dellis1972
Copy link
Contributor

@EJocys changing C# code should not need to re-install the apk if you are using the fast deployment system which should be on by default. You should not need to keep uninstalling the apk each time. Can you share the debug configuration for your application? I suspect you have some settings turned off/on which are interfering with the way our fasted system works.

As for the logs, you need to keep an eye out for entries which have Build or Install in the targets column. Not sure why its not saving data.

@EJocys
Copy link

EJocys commented Apr 28, 2020

@dellis1972: I would be glad to use fast deployment but it was just not working reliably. I would end up debugging old code, because Visual Studio would fail to deploy new code. I've started to use reliable alternatives exactly because Visual Studio auto-deployment options were not reliable.

Visual Studio error suggests that it can't find component "com.package.name/md<MD5>.MainActivity" when all "com.package.name" app is missing. It would be more reasonable error if it said:
"Error: could not find application named: com.package.name"

Debug config with sensitive info removed. It can create *.apk if forced no problem. Deployment is the issue:

  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProjectGuid>{********-****-****-****-************}</ProjectGuid>
    <ProjectTypeGuids>{********-****-****-****-************};{********-****-****-****-************}</ProjectTypeGuids>
    <TemplateGuid>{********-****-****-****-************}</TemplateGuid>
    <OutputType>Library</OutputType>
    <RootNamespace>*****.Mobile.Droid</RootNamespace>
    <AssemblyName>*****.Mobile.Android</AssemblyName>
    <AndroidApplication>True</AndroidApplication>
    <AndroidResgenFile>Resources\Resource.designer.cs</AndroidResgenFile>
    <AndroidResgenClass>Resource</AndroidResgenClass>
    <AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
    <MonoAndroidResourcePrefix>Resources</MonoAndroidResourcePrefix>
    <MonoAndroidAssetsPrefix>Assets</MonoAndroidAssetsPrefix>
    <AndroidUseLatestPlatformSdk>false</AndroidUseLatestPlatformSdk>
    <TargetFrameworkVersion>v9.0</TargetFrameworkVersion>
    <AndroidEnableSGenConcurrent>true</AndroidEnableSGenConcurrent>
    <AndroidUseAapt2>true</AndroidUseAapt2>
    <AndroidHttpClientHandlerType>Xamarin.Android.Net.AndroidClientHandler</AndroidHttpClientHandlerType>
    <NuGetPackageImportStamp>
    </NuGetPackageImportStamp>
    <SccProjectName>SAK</SccProjectName>
    <SccLocalPath>SAK</SccLocalPath>
    <SccAuxPath>SAK</SccAuxPath>
    <SccProvider>SAK</SccProvider>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>portable</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug</OutputPath>
    <DefineConstants>DEBUG;</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <AndroidLinkMode>None</AndroidLinkMode>
    <AotAssemblies>false</AotAssemblies>
    <EnableLLVM>false</EnableLLVM>
    <AndroidEnableProfiledAot>false</AndroidEnableProfiledAot>
    <BundleAssemblies>false</BundleAssemblies>
    <AndroidKeyStore>true</AndroidKeyStore>
    <AndroidSigningKeyStore>$(SolutionDir)\Resources\Keystore\*****.mobile.keystore</AndroidSigningKeyStore>
    <AndroidSigningKeyAlias>*****.mobile</AndroidSigningKeyAlias>
    <AndroidSigningKeyPass>*****</AndroidSigningKeyPass>
    <AndroidSigningStorePass>*****</AndroidSigningStorePass>
    <AndroidUseSharedRuntime>true</AndroidUseSharedRuntime>
    <EmbedAssembliesIntoApk>true</EmbedAssembliesIntoApk>
    <AndroidSupportedAbis>armeabi-v7a;x86;x86_64;arm64-v8a</AndroidSupportedAbis>
    <MandroidI18n />
    <AndroidUseAapt2>true</AndroidUseAapt2>
    <AndroidHttpClientHandlerType>System.Net.Http.HttpClientHandler</AndroidHttpClientHandlerType>
    <AndroidCreatePackagePerAbi>false</AndroidCreatePackagePerAbi>
    <AndroidPackageFormat>apk</AndroidPackageFormat>
  </PropertyGroup>
... 
<PropertyGroup>
    <PostBuildEvent>echo Build Log: $(IntDir)\$(MSBuildProjectName).log</PostBuildEvent>
  </PropertyGroup>
<

@ghost ghost locked as resolved and limited conversation to collaborators Jun 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Area: App+Library Build Issues when building Library projects or Application projects.
Projects
None yet
Development

No branches or pull requests

4 participants