Forum Xamarin.Android
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Conflicting generated resources throws "Android.Content.Res.Resources+NotFoundException"

DamianSuessDamianSuess USMember ✭✭✭
edited October 4 in Xamarin.Android

Has anyone see this issue, know if its a new bug, or if it's something in my system's cache? I appreciate any assistance as this is a show-stopper for our project.

Android.Content.Res.Resources+NotFoundException: 'String resource ID #0x7f0c0001'

Shortly after upgrading from VS v16.7.2 to v16.7.5 I started to get the error in my Android project's OnCreate method in the base.OnCreate(bundle). The odd thing is, the Pull Request for this branch doesn't show any resource changes in the Android project.

Just to prove it was not the new branch, I created a new folder using the develop branch and I get the same error after just a few rebuilds which did not happen before.

Attempts to resolve

I've tried the following which worked for a little bit, and now it throws the error every time.

  • Clean Solution and Rebuild"
  • Delete all obj and bin folders and rebuild (with VS restart)
  • git clean -fxd (with VS closed)
  • Upgraded Xamarin.Forms from 4.8.0.1269 to 4.8.0.1451
  • Even, PC reboots

Research

The Resource ID 0x7F0C0001 points to:

// aapt resource value: 0x7F0D0001
public const int abc_action_bar_up_description = 2131558401;

I performed a file search for the const associated with the hex-value. The const has different values being generated across each of the files in the obj folder.
Why would this happen?

  • Resource.Designer.cs in \droid\Resources is different than the obj folder.
  • R.java - Same value in some files
  • R.txt - Different value in all of them

Project Details

  • The project is in the pre-production phase
  • Xamarin.Forms (v4.8)
  • Uses #AndroidX
  • Uses #Prism

Environment:

Microsoft Visual Studio Enterprise 2019 v16.7.5
VisualStudio.16.Release/16.7.5+30523.141
Microsoft .NET Framework
Version 4.8.03752

Mono Debugging for Visual Studio   16.7.5 (112c7bc)
Support for debugging Mono processes with Visual Studio.

Xamarin   16.7.000.452 ([email protected])
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Designer   16.7.0.495 (remotes/origin/[email protected])
Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin Templates   16.7.85 (1bcbbdf)
Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms.

Xamarin.Android SDK   11.0.2.0 (d16-7/025fde9)
Xamarin.Android Reference Assemblies and MSBuild support.
    Mono: 83105ba
    Java.Interop: xamarin/java.interop/[email protected]
    ProGuard: Guardsquare/proguard/[email protected]
    SQLite: xamarin/sqlite/[email protected]
    Xamarin.Android Tools: xamarin/xamarin-android-tools/[email protected]

Best Answer

  • DamianSuessDamianSuess USMember ✭✭✭
    edited November 6 Accepted Answer

    The issue was solved using the undesirable destructive method where no lessons were learned :disappointed:
    Steps:
    1. Uninstall Visual Studio 2019 (Enterprise)
    2. Performed the Remove Visual Studio procedure
    3. Removed all NuGet packages via, nuget locals all -Clear

        * Clearing NuGet HTTP cache: %UserProfile%\AppData\Local\NuGet\v3-cache
        * Clearing NuGet global packages folder: %UserProfile%\.nuget\packages\
        * Clearing NuGet Temp cache: %UserProfile%\AppData\Local\Temp\NuGetScratch
        * Clearing NuGet plugins cache: %UserProfile%\AppData\Local\NuGet\plugins-cache
    
    1. Manually removed all Xamarin folders
        * %UserProfile%\AppData\Local\Xamarin\
        * %UserProfile%\AppData\Local\Xamarin.Android\
    
    1. Cleared all Temp files via System Cleanup
    2. Rebooted system and reinstalled Visual Studio 2019

    Although I am unhappy that nothing was learned about the root-cause, I am happy that is this project can continue again until the next time.

    Thank you @Irongut for assisting in the troubleshooting process. That was a huge help! Your next beer is on me if we ever meet at a convention. :smile:

Answers

  • DamianSuessDamianSuess USMember ✭✭✭
    edited October 4

    This is quite odd. I noticed there was an update in Android SDK Manager for Android 9.0 to spring my Platform 28 up from v5 to v6 and Platform 29 from v4 to v5. After upgrading and rebuilding, the project launched - Resource.Designer.cs has the value as 0x7F0D0001 in both the project and obj folders.

    // aapt resource value: 0x7F0D0001
    public const int abc_action_bar_up_description = 2131558401;
    

    Unfortunately, after a couple of cleans and rebuilds with no code changes. It reverts back to 0x7f0c0001 in the project and gets out of sync with the Resource.Designer.cs in the obj folder and fails to run.

    Can someone help point me to anything as to why this is being generated like so?

    Reading over @JonathanPeppers article, Faster Xamarin.Android Builds & Smaller Dex Files for any insights to how these are generated.

  • DamianSuessDamianSuess USMember ✭✭✭
    edited October 7

    Though the issue remains, I tested with my 2nd older laptop where it does not have the issue. Keep in mind, this older laptop isn't sticking around much longer - therefore I'm not switching to this one.

    On the 2nd dev device, I am unable to reproduce the issue using VS 2019 Enterprise v16.7.3 (not v16.7.5 above). This leads to conclude, there is either something wrong with the caching or the upgraded system introduces the issue.

    AppData - Something Odd

    Searching for abc_action_bar_up_description in the AppData folder uncovered something different in the R.txt files. Only the Xamarin.Android.Support.v7.MediaRouter folder had the R.txt with the conflicting value.

    Folder Version Value
    Xamarin.Android.Support.Design 23.3.0.0 0x7f050003
    Xamarin.Android.Support.v7.AppCompat 23.3.0.0 0x7f050003
    Xamarin.Android.Support.v7.MediaRouter 23.3.0.0 0x7f060003

    Question:
    Any thoughts as to why these values are different and why Xamarin.Android throws a conflict?

    Projects Generated Files

    The obj\Debug\100 folder does not have conflicting values for R.txt and the Resource.Designer.cs files.

    Generated R.txt

    int string abc_action_bar_up_description 0x7f0d0001
    

    Generated Resource.Designer.cs

    // aapt resource value: 0x7F0D0001
    public const int abc_action_bar_up_description = 2131558401;
    

    Laptop-2 Version

    Failure PC Good PC
    VS Version 16.7.5+30523.141 16.7.3+30503.244
    **Xamarin ** 16.7.000.452 ([email protected]) 16.7.000.440 ([email protected])
    Xamarin Designer (Same) 16.7.0.495 (remotes/origin/[email protected]) 16.7.0.495 (remotes/origin/[email protected])
    Xamarin.Android SDK (Same) 11.0.2.0 (d16-7/025fde9) 11.0.2.0 (d16-7/025fde9)
  • DamianSuessDamianSuess USMember ✭✭✭
    edited October 12

    @JamesMontemagno do you have any advice on what information I should collect before creating a new bug for Xamarin.Android?

    Currently, abc_action_bar_up_description appears to have different values for its constants which is causing run-time failures at the line, base.OnCreate(bundle);

        protected override void OnCreate(Bundle bundle)
        {
          TabLayoutResource = Resource.Layout.Tabbar;
          ToolbarResource = Resource.Layout.Toolbar;
    
          base.OnCreate(bundle);
    
          // Library initialization
          Xamarin.Essentials.Platform.Init(this, bundle);
    
          global::Xamarin.Forms.Forms.Init(this, bundle);
          LoadApplication(new Client.App(new AndroidInitializer()));
        }
    
  • IrongutIrongut Member ✭✭✭

    @DamianSuess Did you find a solution to this issue? I'm having a similar problem with a different resource id.

    Android.Content.Res.Resources+NotFoundException Message=String resource ID #0x7f0c0003

  • DamianSuessDamianSuess USMember ✭✭✭
    edited October 18
    @Irongut, unfortunately no long-term solution. Everytime it "goes away" it returns within a day. Shame too, my product is at a standstill.

    Are you using AndroidX packages by chance? Been hoping for someone from Xamarin to assist in troubleshooting
  • IrongutIrongut Member ✭✭✭

    @DamianSuess said:
    Are you using AndroidX packages by chance? Been hoping for someone from Xamarin to assist in troubleshooting

    Yes, I'm using AndroidX and like yourself the app with the issue is at a standstill. Fortunately it is just an experimental app, not a released product but I was hoping to use it for testing Xamarin 5.0 which is not possible while I can't debug.

  • IrongutIrongut Member ✭✭✭

    I found time to compare the problem app with one of my other apps that uses the exact same AndroidX packages, it has no problems.

    My apps use GitHub Actions to keep dependencies up to date and run builds + unit tests. So I compared the list of Nugets between the two apps and downgraded the packages that were only in the problem app to versions that were available the last time I built and tested manually. This eventually pinpointed the problem package - Microcharts. Not a great surprise, the new maintainer of that library breaks something with every release.

    @DamianSuess I suggest you try something similar, downgrade any libraries you're not sure about to an earlier version and hopefully you'll find the one causing you problems too.

  • DamianSuessDamianSuess USMember ✭✭✭
    edited October 21

    @Irongut, which version of AndroidX did you end up downgrading to? Definitely would like to give it a try.

    Thanks for the heads up on the Microcharts; I was using MoneyFox.Microcharts.Forms. Unfortunately, even after removing that dependency & switching to a custom CircleProgress bar, I'm still getting that dreaded error. Also removed, Xamarin.Forms.Visual.Material w/ a Clean > closed VS > deleted obj & Resource.Designer.cs.

    Can you think of any tree to shake from the official Xamarin team who may have some insight into this?

  • DamianSuessDamianSuess USMember ✭✭✭

    Dumping my latest exception if this assists anyone reading this

    {Android.Content.Res.Resources+NotFoundException: String resource ID #0x7f0c0001
      at Java.Interop.JniEnvironment+InstanceMethods.CallNonvirtualVoidMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniObjectReference type, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x0008e] in <42748fcc36b74733af2d9940a8f3cc8e>:0 
      at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualVoidMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x0005d] in <42748fcc36b74733af2d9940a8f3cc8e>:0 
      at AndroidX.AppCompat.App.AppCompatActivity.SetSupportActionBar (AndroidX.AppCompat.Widget.Toolbar toolbar) [0x00027] in D:\a\1\s\generated\androidx.appcompat.appcompat\obj\Release\monoandroid90\generated\src\AndroidX.AppCompat.App.AppCompatActivity.cs:466 
      at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.OnCreate (Android.OS.Bundle savedInstanceState, Xamarin.Forms.Platform.Android.ActivationFlags flags) [0x00129] in D:\a\1\s\Xamarin.Forms.Platform.Android\AppCompat\FormsAppCompatActivity.cs:290 
      at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.OnCreate (Android.OS.Bundle savedInstanceState) [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.Android\AppCompat\FormsAppCompatActivity.cs:211 
      at Xeno.FungKuFit.Droid.MainActivity.OnCreate (Android.OS.Bundle bundle) [0x00017] in C:\work\xi\FungKuFit\source\Xeno.FungKuFit.Android\MainActivity.cs:48 
      at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_savedInstanceState) [0x0000f] in <7d2292394f8c488b97f5bc2a0ac0240d>:0 
      at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.4(intptr,intptr,intptr)
      --- End of managed Android.Content.Res.Resources+NotFoundException stack trace ---
    android.content.res.Resources$NotFoundException: String resource ID #0x7f0c0001
        at android.content.res.Resources.getText(Resources.java:348)
        at android.content.res.Resources.getString(Resources.java:441)
        at android.content.Context.getString(Context.java:578)
        at androidx.appcompat.widget.ToolbarWidgetWrapper.setNavigationContentDescription(ToolbarWidgetWrapper.java:626)
        at androidx.appcompat.widget.ToolbarWidgetWrapper.setDefaultNavigationContentDescription(ToolbarWidgetWrapper.java:201)
        at androidx.appcompat.widget.ToolbarWidgetWrapper.<init>(ToolbarWidgetWrapper.java:179)
        at androidx.appcompat.widget.ToolbarWidgetWrapper.<init>(ToolbarWidgetWrapper.java:96)
        at androidx.appcompat.app.ToolbarActionBar.<init>(ToolbarActionBar.java:70)
        at androidx.appcompat.app.AppCompatDelegateImpl.setSupportActionBar(AppCompatDelegateImpl.java:587)
        at androidx.appcompat.app.AppCompatActivity.setSupportActionBar(AppCompatActivity.java:159)
        at crc64c3bfe838752d7825.MainActivity.n_onCreate(Native Method)
        at crc64c3bfe838752d7825.MainActivity.onCreate(MainActivity.java:46)
        at android.app.Activity.performCreate(Activity.java:7136)
        at android.app.Activity.performCreate(Activity.java:7127)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6669)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
    }
    
  • DamianSuessDamianSuess USMember ✭✭✭
    edited November 6 Accepted Answer

    The issue was solved using the undesirable destructive method where no lessons were learned :disappointed:
    Steps:
    1. Uninstall Visual Studio 2019 (Enterprise)
    2. Performed the Remove Visual Studio procedure
    3. Removed all NuGet packages via, nuget locals all -Clear

        * Clearing NuGet HTTP cache: %UserProfile%\AppData\Local\NuGet\v3-cache
        * Clearing NuGet global packages folder: %UserProfile%\.nuget\packages\
        * Clearing NuGet Temp cache: %UserProfile%\AppData\Local\Temp\NuGetScratch
        * Clearing NuGet plugins cache: %UserProfile%\AppData\Local\NuGet\plugins-cache
    
    1. Manually removed all Xamarin folders
        * %UserProfile%\AppData\Local\Xamarin\
        * %UserProfile%\AppData\Local\Xamarin.Android\
    
    1. Cleared all Temp files via System Cleanup
    2. Rebooted system and reinstalled Visual Studio 2019

    Although I am unhappy that nothing was learned about the root-cause, I am happy that is this project can continue again until the next time.

    Thank you @Irongut for assisting in the troubleshooting process. That was a huge help! Your next beer is on me if we ever meet at a convention. :smile:

Sign In or Register to comment.