"Invalid file path" error

AUU 1 Reputation point
2021-01-27T21:56:01.657+00:00

Hi there,

I added a "icons1.ttf" file under \Android\Resources\Fonts directory and VS 2019 keeps on giving the error message : "invalid file path 'S:\Ulvi\Apps\samples\Mobile1\Mobile1.Android\obj\Debug\90\res\fonts\icons1.ttf'. And it does not build.

I also followed some comments that I should delete bin and obj directories : exited, deleted dirs and started VS again. No difference :/

Any idea what is happening ? Frustrating :(

AUU

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,301 questions
0 comments No comments
{count} votes

4 answers

Sort by: Most helpful
  1. mc 3,726 Reputation points
    2021-01-28T01:00:28.02+00:00

    why you want to access the font file?
    If you want to use your font you can use embedded fonts.

    just add the "icons1.ttf" to the shared projects's folder and set it to EmbeddedResource.

    and add the code to anywhere in your code file.
    [assembly: ExportFont("icons1.ttf", Alias = "icons1")]

    Then you can use it in your Label.

    please check the url:https://devblogs.microsoft.com/xamarin/embedded-fonts-xamarin-forms/

    0 comments No comments

  2. AUU 1 Reputation point
    2021-01-28T02:32:09.77+00:00

    Thanks for the hint 65841535; that's what I eventually did anyways.

    On the other hand, I simply followed-up another "set of instructions" to copy the ttf file under /Android/Resources/Fonts. Since it did not work (which is still not clear why), I just want to remove all that.

    So, it still is stuck there :/

    0 comments No comments

  3. mc 3,726 Reputation points
    2021-01-28T03:10:32.433+00:00

    Did you set the /Android/Resources/Fonts/ttf. as AndroidAsset?

    Then set the resources

    <ContentPage.Resources>
        <ResourceDictionary>
            <OnPlatform x:TypeArguments="x:String" x:Key="cfont">
                <On Platform="Android" Value="font.ttf#Open Sans" />
            </OnPlatform>
        </ResourceDictionary>
    </ContentPage.Resources>
    

    then set the font-family:

    <Label Text="Custom FontFamily" FontFamily="{StaticResource cfont}"/>
    
    0 comments No comments

  4. AUU 1 Reputation point
    2021-01-28T03:47:30.327+00:00

    Have a look at here : [https://developercommunity.visualstudio.com/content/problem/1156349/invalid-file-path-deploy-android-project.html][1]

    "As I was writing that, I found that the resources that cause these errors would have been silently excluded from the applications in the previous versions of Visual Studio and Xamarin.Android, so I think the Xamarin.Android team might decide to keep the new behavior because it can help prevent unexpected behaviors for app authors."

    It looks like it is not wanted under "Android/Resource" tree. So I moved it to "drawable", it works.

    Yet, my original issue persists. I cannot delete the "wrong" directory. This should not be so difficult :/

    0 comments No comments