android: "Unable to read profile ... The system cannot find the file specified" for adb.exe when attempting to complete profiling with FinishAotProfiling
Steps to reproduce
-
Create a new Android Single View App project.
-
Open Tools > Command Line > Developer Command Prompt.
-
Ensure that a target Android device is attached.
-
Run the following command in the solution directory:
msbuild -t:BuildAndStartAotProfiling -
After the app launches successfully, run the following command:
msbuild -t:FinishAotProfiling
Expected behavior
The FinishAotProfiling target completes successfully.
Actual behavior
The FinishAotProfiling target fails:
Task "Exec" (TaskId:12)
Task Parameter:Command="C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\MSBuild\Xamarin\Android\aprofutil" -s -v -f -p 9999 -o "custom.aprof" (TaskId:12)
"C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\MSBuild\Xamarin\Android\aprofutil" -s -v -f -p 9999 -o "custom.aprof" (TaskId:12)
Calling 'adb forward tcp:9999 tcp:9999'... (TaskId:12)
EXEC : error : aotprofile-tool: Unable to read profile through local port: 9999.
System.ComponentModel.Win32Exception (0x80004005): The system cannot find the file specified (TaskId:12)
at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo) (TaskId:12)
at System.Diagnostics.Process.Start(ProcessStartInfo startInfo) (TaskId:12)
at aotprofiletool.MainClass.ReadProfileFromPort(ProfileReader reader) (TaskId:12)
at aotprofiletool.MainClass.Main(String[] args) (TaskId:12)
C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\MSBuild\Xamarin\Android\Xamarin.Android.Application.targets(62,5): error MSB3075: The command ""C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\MSBuild\Xamarin\Android\aprofutil" -s -v -f -p 9999 -o "custom.aprof"" exited with code 5. Please verify that you have sufficient rights to run this command.
Done executing task "Exec" -- FAILED. (TaskId:12)
Perhaps of interest, the adb logcat output seems to indicate that profiling started successfully on the device:
01-20 22:48:31.937 7781 7781 W monodroid: Initializing profiler with options: aot:port=9999,output=/data/user/0/com.companyname.androidsingleviewapp1/files/.__override__/profile.aotprofile
The following command also ran successfully when I ran it by hand:
adb forward tcp:9999 tcp:9999
And netstat on the device seems to indicate it is indeed listening on port 9999:
C:\>adb shell netstat -n -l
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:9999 0.0.0.0:* LISTEN
Version information
- Visual Studio 2019 version 16.5 Internal Preview
- Xamarin.Android SDK 10.2.0.84 (d16-5/ac3f71f)
- Mono: df42020
- Java.Interop: xamarin/java.interop/d16-5@c0cc770
- ProGuard: xamarin/proguard/master@905836d
- SQLite: xamarin/sqlite/3.28.0@46204c4
- Xamarin.Android Tools: xamarin/xamarin-android-tools/master@9f4ed4b
Android 9.0 (API level 28) arm64-v8a Google Pixel 3
Log files
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 2
- Comments: 21 (9 by maintainers)
Commits related to this issue
- Set the adb port forwarding Fixes https://github.com/xamarin/xamarin-android/issues/4152 And don't use `-f` option when calling `aprofutil` as the adb might not be in the `PATH` — committed to radekdoulik/xamarin-android by radekdoulik 6 years ago
- [Xamarin.Android.Build.Tasks] FinishAotProfiling port forwarding (#4740) Fixes: https://github.com/xamarin/xamarin-android/issues/4152 The `FinishAotProfiling` target (853b367c) would fail if `adb... — committed to dotnet/android by radekdoulik 6 years ago
- [Xamarin.Android.Build.Tasks] FinishAotProfiling port forwarding (#4740) Fixes: https://github.com/xamarin/xamarin-android/issues/4152 The `FinishAotProfiling` target (853b367c) would fail if `adb... — committed to dotnet/android by radekdoulik 6 years ago
Workaround
I was able to work around the Unable to read profile … The system cannot find the file specified error by adding the directory containing
adb.exeto thePATHenvironment variable in the Developer Command Prompt before runningmsbuild -t:FinishAotProfiling:Additional notes
It seems that
msbuild -t:FinishAotProfilingmight not yet do any steps to ensure the path toadb.exeis known beforeaprofutilattempts to start it.Just updated my startup tracing for and confirm that this is still an issue. Visual Studio 2019 Version 16.9.3 Xamarin.Android SDK - 11.2.2.1
Release status update
A new Release version of Xamarin.Android has now been published that includes the fix for this item that was previously published in the Preview versions.
Fix included in Xamarin.Android SDK version 11.0.0.3.
Fix included on Windows in Visual Studio 2019 version 16.7. To get the new version that includes the fix, check for the latest updates or install the most recent release from https://visualstudio.microsoft.com/downloads/.
Fix included on macOS in Visual Studio 2019 for Mac version 8.7. To get the new version that includes the fix, check for the latest updates on the Stable updater channel.
Why is it not fixed in VS since January ? Still need to add the PATH trick ! Just fall on it today using latest stable VS2019 Enterprise on Windows.
Workaround for macOS
Ah yes, on macOS, the workaround would be similar. For the default install path that Visual Studio for Mac uses for
adb, the workaround would be: