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

Modifying the code and running a Xamarin.Android application doesn't work fine #6113

Closed
arivoir opened this issue Jul 22, 2021 · 33 comments · Fixed by #6133
Closed

Modifying the code and running a Xamarin.Android application doesn't work fine #6113

arivoir opened this issue Jul 22, 2021 · 33 comments · Fixed by #6133
Assignees
Labels
Area: App+Library Build Issues when building Library projects or Application projects. need-info Issues that need more information from the author.

Comments

@arivoir
Copy link

arivoir commented Jul 22, 2021

In many occasions it happens I modify the code of the application I'm building and when I run the application, the running application is old and it doesn't contain my changes.

Rebuilding the application doesn't fix it.

The only way of fixing it is to delete bin and obj folders and run the application again

@arivoir arivoir added Area: App Runtime Issues in `libmonodroid.so`. needs-triage Issues that need to be assigned. labels Jul 22, 2021
@arivoir
Copy link
Author

arivoir commented Jul 22, 2021

Sometimes is necessary to uninstall the application from the emulator.

@grendello grendello added Area: App+Library Build Issues when building Library projects or Application projects. and removed Area: App Runtime Issues in `libmonodroid.so`. needs-triage Issues that need to be assigned. labels Jul 22, 2021
@dellis1972
Copy link
Contributor

dellis1972 commented Jul 23, 2021

Thanks for the bug report. We will try to repo this issue locally, but it would be very helpful if you could provide some diagnostic build output. You can get the required output using the steps below.

  1. Set Tools > Options > Project and Solutions [section] > Build and Run [subsection] > MSBuild project build output verbosity to Diagnostic.
  2. Repeat the scenario where a deployment to device causes the application data to be removed.
  3. After the project is deployed, open the View > Output window, and set Show output from to Deploy (also for Build).
  4. Make sure the Output window is selected, and then choose File > Save Output As to save the contents to a text file. Or copy and paste the build output into a text file.
  5. In the View > Output window, change Show output from to Xamarin Diagnostics.
  6. Once again make sure the Output window is selected, and then choose File > Save Output As to save the contents to a text file. Or copy and paste the build output into a text file.

Attach back the text files from steps 4 and 6 in a new comment on this item, You can zip the files before attaching them to make the upload size smaller.

If you could provide both the Build and Deploy logs that would be helpful. The Deploy logs are really important.

If you are comfortable using the VS2019 Developer command prompt an easier way to get the logs all in one go is to run the following command

msbuild <your project.csproj> /restore /t:Install /bl

Then attach the resulting msbuild.binlog.

Thanks in advance

@dellis1972 dellis1972 added the need-info Issues that need more information from the author. label Jul 23, 2021
@arivoir
Copy link
Author

arivoir commented Jul 23, 2021

I attached the requested output files and include others just in case.

Output.zip

@arivoir
Copy link
Author

arivoir commented Jul 23, 2021

there is no "Deploy" window. I attached Build and Debug

image

@arivoir
Copy link
Author

arivoir commented Jul 23, 2021

I also tried the command msbuild InputHandling.csproj /restore /t:Install. /bl in the console, but it gives me this error

"InputHandling.csproj" (Install. target) (1:7) ->
InputHandling.csproj : error MSB4057: The target
"Install." does not exist in the project.

@dellis1972
Copy link
Contributor

@arivoir sorry there was a typo in my post, the target is Install not Install.

@dellis1972
Copy link
Contributor

can you try using the following

msbuild InputHandling.csproj /restore /t:Install /bl /p:_FastDeploymentDiagnosticLogging=true

This will enabled the fast dev diagnostic logging. I suspect you hare hitting an issue which we might have fixed internally already.

@arivoir
Copy link
Author

arivoir commented Jul 23, 2021

Good point.
msbuild.binlog.zip

@arivoir
Copy link
Author

arivoir commented Jul 23, 2021

This one includes /p:_FastDeploymentDiagnosticLogging=true
msbuild.binlog..zip

@jonathanpeppers
Copy link
Member

jonathanpeppers commented Jul 23, 2021

@dellis1972 I think @PureWeen was hitting this, and we thought this change fixed it:

https://github.com/xamarin/monodroid/commit/33e542fac95f1ac4e56d3965d2f336a1d6a5f98e#diff-047d4e16157f5854902aeb0701c482698138887e17fe4051d967aa60cdf57459R44

Our test case was changing a static readonly int Foo = 1 to different numbers and the change wasn't applied. But it seems like the problem went away in Preview 7.

@arivoir if you make a larger change, do you see you're changes depoyed? Something like Console.WriteLine("Some string") would be enough to do it.

@dellis1972
Copy link
Contributor

@jonathanpeppers yup that was the fix I was thinking about.

@arivoir
Copy link
Author

arivoir commented Jul 23, 2021

@jonathanpeppers Adding Console.WriteLine("Some string"); is not working either. It still doesn't deploy the changes.

@jonathanpeppers
Copy link
Member

@arivoir can you share a log when you make that change?

We shouldn't be seeing a log message like this:

NotifySync SkipCopyFile obj\Debug\net6.0-android\android\assets\InputHandling.dll=>InputHandling.dll file is up to date. [0ms]

But we should be able to see what it thought the timestamp of the file on the device was.

@dellis1972
Copy link
Contributor

It's probably the same issue. We had an issue with the time stamps that were being returned from our native fast deployment tooling. On x86 based CPU's the time stamp from the device was different from what it should have been, we suspect it was down to an arithmetic overflow of some sort because we were dealing with 64bit ints.

@dellis1972
Copy link
Contributor

@jonathanpeppers this #6113 (comment) has the data. But its an older version so it doesn't have the additional logging we added for P7.

@arivoir
Copy link
Author

arivoir commented Jul 23, 2021

@jonathanpeppers I uploaded the logs here #6113 (comment)
I don't know what else to share. Please clarify if you need something else. I'm very interested in this bug being fixed.

@arivoir
Copy link
Author

arivoir commented Jul 23, 2021

But we should be able to see what it thought the timestamp of the file on the device was.

Can I make anything to get the timestamp? Please give me instructions

@jonathanpeppers
Copy link
Member

What .cs file changes were made prior to the build log in #6113 (comment)?

For all we know, there might have been no changes. We don't have that detail here.

@arivoir
Copy link
Author

arivoir commented Jul 23, 2021

I'm changing the MainActivity.cs of the project, but I've had this problem in other parts of the code. I'm sure the source is changes, because if I delete the application from the emulator and run it again I can see the changes.

@jonathanpeppers
Copy link
Member

Can you share an example of what you changed? I will try to repro it with xamarin-android/main (preview 7).

@arivoir
Copy link
Author

arivoir commented Jul 23, 2021

Will a "Live share" work for this?

@jonathanpeppers
Copy link
Member

jonathanpeppers commented Jul 23, 2021

A C# code snippet is all we need, for example:

--var button = FindViewById<Button> (Resource.Id.myButton);
++var button = FindViewById<Button> (Resource.Id.anotherButton);

I have no idea if the above causes the issue, or what kind of code changes does.

@arivoir
Copy link
Author

arivoir commented Jul 23, 2021

In this particular case I was working on, I'm setting the Foreground of TextView

new TextView(BaseContext) { Text = "Hello", /*Foreground = Resources.GetDrawable(Resource.Drawable.gradient_background),*/}

Commenting it out will not make the foreground to appear, unless I remove the app from the emulator

@arivoir
Copy link
Author

arivoir commented Jul 23, 2021

I was able to reproduce the issue in a very simple project

Created an empty project dotnet new android -n AndroidDeployIssue

Added an id to the TextView

image

Then in MainActivity I set the foreground programmatically, it works fine, but then I comment out that code and the textbox is still green

image

image

If I remove the app from the emulator and run it again, I can see the textview without the foreground.

image

AndroidDeployIssue.zip

@dellis1972
Copy link
Contributor

I get a different issue with that test project on main. It deploys all assemblies all the time. hmmm. Looks like we have a problem with x86 emulators :(

@arivoir
Copy link
Author

arivoir commented Jul 23, 2021

I just tried with a real device and the problem didn't appear, but developing with the emulator is crucial. I hope you can fix it.

@dellis1972
Copy link
Contributor

dellis1972 commented Jul 26, 2021

@arivoir ok so I did a review of our code and I think I figured out what is going on. I suspect your emulator is an x86_64 one, not a standard x86 one. The problem here is we are deploying the x86 fast dev tooling to the emulator not the x86_64 versions we should be.

What we normally do is run a task called GetPrimaryCpuAbi to get the abi of the device/emulator for fast deployment. The bug I think is we are not storing this in the devices.cache file. As a result when we actually deploy the files we are deploying the wrong abi. Because we have a fallback to use the ResultingAbi if ToolsAbi is empty.

The problem with .net 6 is we filter the ResultingAbi based on the RuntimeIdentifiers ItemGroup. So if the app does not support android-x64 that value will get changed to be x86 only.

So in theory adding the following to your csproj will work around the issue

<RuntimeIdentifiers>android-arm64;android-x64</RuntimeIdentifiers>

Assuming you want to use 64bit on both device and emulator.

you will need to do a complete clean for this work around to work, and probably remove the app from the device as well just to make sure everything gets updated.

@arivoir
Copy link
Author

arivoir commented Jul 26, 2021

I tired that and got this

Error ADB0020: Mono.AndroidTools.IncompatibleCpuAbiExceptiopn: The package does not support the CPU architecture of this device.
at Mono.AndroidTools.Internal.AdbOutputParsing.CheckInstallSuccess(String output, String packageName) in /Users/builder/azdo/_work/1/s/xamarin-android/external/monodroid/tools/msbuild/external/androidtools/Mono.AndroidTools/Internal/AdbOutputParsing.cs:line 342
at Mono.AndroidTools.AndroidDevice.<>c__DisplayClass100_0.b__0(Task1 t) in /Users/builder/azdo/_work/1/s/xamarin-android/external/monodroid/tools/msbuild/external/androidtools/Mono.AndroidTools/AndroidDevice.cs:line 803
at System.Threading.Tasks.ContinuationTaskFromResultTask1.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at AndroidDeviceExtensions.d__12.MoveNext() in /Users/builder/azdo/_work/1/s/xamarin-android/external/monodroid/tools/msbuild/external/androidtools/Xamarin.AndroidTools/Devices/AndroidDeviceExtensions.cs:line 206
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at AndroidDeviceExtensions.d__12.MoveNext() in /Users/builder/azdo/_work/1/s/xamarin-android/external/monodroid/tools/msbuild/external/androidtools/Xamarin.AndroidTools/Devices/AndroidDeviceExtensions.cs:line 223
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Xamarin.Android.Tasks.FastDeploy.d__105.MoveNext() in /Users/builder/azdo/_work/1/s/xamarin-android/external/monodroid/tools/msbuild/Tasks/FastDeploy.cs:line 339
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Xamarin.Android.Tasks.FastDeploy.d__105.MoveNext() in /Users/builder/azdo/_work/1/s/xamarin-android/external/monodroid/tools/msbuild/Tasks/FastDeploy.cs:line 356
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at Xamarin.Android.Tasks.FastDeploy.d__100.MoveNext() in /Users/builder/azdo/_work/1/s/xamarin-android/external/monodroid/tools/msbuild/Tasks/FastDeploy.cs:line 213 0

I suppose it is because of this

image

What should I change? the emulator processor? I appreciate if you can orient me.

@dellis1972
Copy link
Contributor

Err ok. very weird. So we have a problem , but it's not the one you are getting.
That is worrying, it suggests that the x86 version of our fastdev tooling is completely broken :'( .
I'll have a look.

@arivoir
Copy link
Author

arivoir commented Jul 26, 2021

I just tried creating a new emulator

image

Added the runtime identifiers
image

And the same problem appeared. It looks it is something different

@arivoir
Copy link
Author

arivoir commented Jul 27, 2021

Why did you closed it? When are the bugs going to be fixed?

@jonathanpeppers
Copy link
Member

We just merged a PR with the fix (change is in a private repo). The plan is for this to land in Preview 7.

@arivoir
Copy link
Author

arivoir commented Jul 27, 2021

Perfect! I'll test it when it is released. Thanks.

jonpryor added a commit to jonpryor/xamarin-android that referenced this issue Jul 27, 2021
Fixes: dotnet#6113

Changes: xamarin/monodroid@33e542f...ab6c39e

  * xamarin/monodroid@ab6c39ee5: [tools/fastdev] use strtoull to parse 64 bit argument. (dotnet#1217)
  * xamarin/monodroid@aa75b5b89: [tools/msbuild] Cache the ToolsAbi value for the device. (dotnet#1216)
  * xamarin/monodroid@d4a8977cb: [tools/msbuild] add missing RuntimeConfigBinFilePath value (dotnet#1213)
jonpryor added a commit that referenced this issue Jul 28, 2021
Fixes: #6113

Changes: xamarin/monodroid@33e542f...ab6c39e

  * xamarin/monodroid@ab6c39ee5: [tools/fastdev] use strtoull to parse 64 bit argument. (#1217)
  * xamarin/monodroid@aa75b5b89: [tools/msbuild] Cache the ToolsAbi value for the device. (#1216)
  * xamarin/monodroid@d4a8977cb: [tools/msbuild] add missing RuntimeConfigBinFilePath value (#1213)
jonpryor added a commit that referenced this issue Jul 28, 2021
Fixes: #6113

Changes: xamarin/monodroid@33e542f...ab6c39e

  * xamarin/monodroid@ab6c39ee5: [tools/fastdev] use strtoull to parse 64 bit argument. (#1217)
  * xamarin/monodroid@aa75b5b89: [tools/msbuild] Cache the ToolsAbi value for the device. (#1216)
  * xamarin/monodroid@d4a8977cb: [tools/msbuild] add missing RuntimeConfigBinFilePath value (#1213)
@ghost ghost locked as resolved and limited conversation to collaborators Jun 2, 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. need-info Issues that need more information from the author.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants