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

[Xamarin.Android.Build.Tasks] pass -S for am start commands #8032

Merged
merged 1 commit into from
May 15, 2023

Conversation

jonathanpeppers
Copy link
Member

Context: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1777086
Context: https://github.com/xamarin/xamarin-android/blob/17c74c5cfcc383464931e6a2f828a689ba998965/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/DeviceTest.cs#L187-L190

If an android app is already running, and you do one of:

dotnet build -t:Run
dotnet build -t:StartAndroidActivity

It doesn't actually close and restart the app.

To do this, we need to pass -S:

am start: start an Activity.  Options are:
...
-S: force stop the target app before starting the activity

This appears to work fine going back to API 21, we are already using this flag in unit tests.

Now the <Exec/> task prints an extra line:

Stopping: com.companyname.foo
Starting: Intent { cmp=com.companyname.foo/crc642c1279b4112b2ad7.MainActivity }

Note that this only fixes the OSS side of xamarin-android, we will need a change in:

https://github.com/xamarin/monodroid/blob/84a2ae648143924eafb8daa59b2a4e9f05f54359/tools/msbuild/Tasks/RunActivity.cs

To fix this in the commercial product.

Context: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1777086
Context: https://github.com/xamarin/xamarin-android/blob/17c74c5cfcc383464931e6a2f828a689ba998965/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/DeviceTest.cs#L187-L190

If an android app is already running, and you do one of:

    dotnet build -t:Run
    dotnet build -t:StartAndroidActivity

It doesn't actually close and restart the app.

To do this, we need to pass `-S`:

    am start: start an Activity.  Options are:
    ...
    -S: force stop the target app before starting the activity

This appears to work fine going back to API 21, we are already using
this flag in unit tests.

Now the `<Exec/>` task prints an extra line:

    Stopping: com.companyname.foo
    Starting: Intent { cmp=com.companyname.foo/crc642c1279b4112b2ad7.MainActivity }

Note that this only fixes the OSS side of xamarin-android, we will
need a change in:

https://github.com/xamarin/monodroid/blob/84a2ae648143924eafb8daa59b2a4e9f05f54359/tools/msbuild/Tasks/RunActivity.cs

To fix this in the commercial product.
@jonathanpeppers
Copy link
Member Author

The one failure was:

DesignTime build should be less than 10000 milliseconds.
Expected: less than or equal to 10000.0d
But was:  11210.0d

Should be unrelated, as DTBs wouldn't deploy. Going to merge.

@jonathanpeppers jonathanpeppers merged commit 2eae250 into dotnet:main May 15, 2023
@jonathanpeppers jonathanpeppers deleted the StartAndroidActivity branch May 15, 2023 13:23
grendello added a commit to grendello/xamarin-android that referenced this pull request May 16, 2023
* main:
  [Xamarin.Android.Build.Tasks] pass `-S` for `am start` commands (dotnet#8032)
jonathanpeppers added a commit that referenced this pull request May 25, 2023
Context: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1777086
Context: https://github.com/xamarin/xamarin-android/blob/17c74c5cfcc383464931e6a2f828a689ba998965/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Utilities/DeviceTest.cs#L187-L190

If an android app is already running, and you do one of:

    dotnet build -t:Run
    dotnet build -t:StartAndroidActivity

It doesn't actually close and restart the app.

To do this, we need to pass `-S`:

    am start: start an Activity.  Options are:
    ...
    -S: force stop the target app before starting the activity

This appears to work fine going back to API 21, we are already using
this flag in unit tests.

Now the `<Exec/>` task prints an extra line:

    Stopping: com.companyname.foo
    Starting: Intent { cmp=com.companyname.foo/crc642c1279b4112b2ad7.MainActivity }

Note that this only fixes the OSS side of xamarin-android, we will
need a change in:

https://github.com/xamarin/monodroid/blob/84a2ae648143924eafb8daa59b2a4e9f05f54359/tools/msbuild/Tasks/RunActivity.cs

To fix this in the commercial product.
@github-actions github-actions bot locked and limited conversation to collaborators Jan 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants