Skip to content

[AOT] Failed to deploy app  #6697

Closed
Closed
@workgroupengineering

Description

@workgroupengineering

Android application type

Classic Xamarin.Android (MonoAndroid12.0, etc.)

Affected platform version

VS 2022 17.1 Preview 5

Description

Unable to deploy the app

Steps to Reproduce

  1. Clone Uno Repository
  2. Rename crosstargeting_override.props.sample crosstargeting_override.props
  3. Open crosstargeting_override.props
  4. UnoTargetFrameworkOverride and set MonoAndroid12.0
  5. Open Uno.UI-Android-only.slnf
  6. Set SampleApp.Droid as Startup application
  7. Run debug

Did you find any workaround?

Add the following target to Directory.Build.props

<UsingTask TaskName="ShortPath"
             TaskFactory="CodeTaskFactory"
             AssemblyFile="$(MSBuildBinPath)\Microsoft.Build.Tasks.Core.dll"
             >
    <ParameterGroup>
      <LongPath ParameterType="System.String" Required="true" />
      <OutputPath ParameterType="System.String" Output="true" />
    </ParameterGroup>
    <Task>
      <Code Type="Class" Language="C#">
        <![CDATA[

    using System.Text;
    using System.Runtime.InteropServices;
    using Microsoft.Build.Framework;

    public class ShortPath : ITask
    {
        const int MAX_PATH = 255;

        [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
        private static extern int GetShortPathName(
            [MarshalAs(UnmanagedType.LPTStr)]
         string path,
            [MarshalAs(UnmanagedType.LPTStr)]
         StringBuilder shortPath,
            int shortPathLength
            );

        private static string GetShortPath(string path)
        {
            var shortPath = new StringBuilder(MAX_PATH);
            GetShortPathName(path, shortPath, MAX_PATH);
            return shortPath.ToString();
        }

        [Required]
        public string LongPath { get; set; }

        public string OutputPath { get; set; }
        public IBuildEngine BuildEngine { get; set; }
        public ITaskHost HostObject { get; set; }

        public bool Execute()
        {
            OutputPath = GetShortPath(LongPath);
            return true;
        }
    }
        ]]>
      </Code>
    </Task>
  </UsingTask>

  <Target Name="Fix_AndroidNdkPath"
          BeforeTargets="_AndroidAot"
          Condition="'$(MSBuildVersion)' &gt;= '17.1'">
    <PropertyGroup>
      <_OriginalAndroidNdkDirectory>$(AndroidNdkDirectory)</_OriginalAndroidNdkDirectory>
    </PropertyGroup>
    <ShortPath LongPath="$(_OriginalAndroidNdkDirectory)">
      <Output TaskParameter="OutputPath" PropertyName="_AndroidNdkDirectory" />
    </ShortPath>
  </Target>

Relevant log output

[CC] "C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\armv7a-linux-androideabi16-clang.CMD" -c -D__ANDROID_API__=16 -DANDROID -o obj\Debug\120\bundles\armeabi-v7a\temp.o -I "C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\sysroot\usr\include\arm-linux-androideabi" -I "C:\Program Files (x86)\Android\android-sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\sysroot\usr\include" obj\Debug\120\bundles\armeabi-v7a\temp.c
"C:\Program " is not recognized as an internal or external command,
  an executable program or batch file.

Metadata

Metadata

Labels

Area: App+Library BuildIssues when building Library projects or Application projects.need-infoIssues that need more information from the author.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions