dotnet / android

.NET for Android provides open-source bindings of the Android SDK for use with .NET managed languages such as C#
MIT License
1.94k stars 533 forks source link

Android: Error in migrating Android specific Resources (AndroidResource) from Xamarin Forms to MAUI Android (R.java error) #9461

Open muffadal53 opened 3 months ago

muffadal53 commented 3 months ago

Description

We are migrating Resources of Android specific Resources (controls, colors) like .xml, .axml and .png files from Xamarin Forms to "MAUI->Platforms->Android->Resources" folder and getting error "APT2258 invalid symbol name 'com.companyname.mauiapp1:drawable/import'. C:\Users*User*\AppData\Local\Temp\2kevcthb.kih\com\companyname\mauiapp1\R.java"

I thought a per the thing mentioned in Blog "https://devblogs.microsoft.com/dotnet/android-resource-designer-dotnet-8/" this will automatically work but this is not the case with .Net 8.

Steps to Reproduce

  1. Copy the Resources file from Xamarin Forms Android specific resources.

  2. Move the resources (controls, colors) like .xml, .axml and .png etc. under "MAUI/Platforms/Android/Resources" folder structure as follows:

    a. Android\Resources\color\ b. Android\Resources\drawable\ c. Android\Resources\drawable-hdpi\ d. Android\Resources\drawable-ldpi\ e. Android\Resources\drawable-mdpi\ f. Android\Resources\drawable-xhdpi\ g. Android\Resources\drawable-xxhdpi\ h. Android\Resources\drawable-xxxhdpi\ i. Android\Resources\layout\ j. Android\Resources\values\

  3. And when we compile the solution we get following error which is as follows:

"APT2258 invalid symbol name 'com.companyname.mauiapp1:drawable/import'. C:\Users*User*\AppData\Local\Temp\2kevcthb.kih\com\companyname\mauiapp1\R.java"

Please let me know how can we solve this issue for MAUI migration.

Link to public reproduction project repository

https://github.com/muffadal53/MAUIAndroid_Resource

Version with bug

8.0.80 SR8

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android

Did you find any workaround?

N/A

Relevant log output

N/A
github-actions[bot] commented 3 months ago

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Open similar issues:

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

RoiChen001 commented 3 months ago

I can repro this issue at Android platform on the latest 17.12.0 Preview 1.0(8.0.80 & 8.0.72). image

muffadal53 commented 3 months ago

@jfversluis and @davidortinau can you please provide your inputs on this migration issue. Thanks.

samhouts commented 2 months ago

@dellis1972 ?

dellis1972 commented 2 months ago

@muffadal53 you issue is this file Platforms/Android/Resources/drawable-xxhdpi/Import.png. This happens to be a java keyword https://docs.oracle.com/javase/tutorial/java/nutsandbolts/_keywords.html. So when aapt2 (which is a newer verison that the old one) tries to generate the R.java file it is failing. The workaround is to rename this file to something that isn't a key word. I'm not entirely sure if we can do anthing this end because it would mean changing aapt2.

dellis1972 commented 2 days ago

PR is up https://github.com/dotnet/android/pull/9537