Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Xamarin.Android.Build.Tasks] deletebinobj fix for resources #2199

Merged
merged 1 commit into from
Sep 20, 2018

Commits on Sep 20, 2018

  1. [Xamarin.Android.Build.Tasks] deletebinobj fix for resources

    Fixes: dotnet#2193
    
    I have been able to reproduce a #deletebinobj bug with the following
    steps:
    1. `File | New Project | Android App (Xamarin) | Tabbed App`, set
       `Minimum Android Version` to `Android 5.0 (Lollipop)`
    2. Build
    3. Add a new `TextView` to `Resources\layout\activity_main.axml`, with
       an id of `textView1`
    4. Build and Deploy
    
    Get a crash at runtime:
    
        Android.Views.InflateException: Binary XML file line #1: Error inflating class android.support.design.widget.BottomNavigationView occurred
    
    A `Rebuild` fixes the problem, and the app starts correctly again.
    
    After comparing `obj` directories from before and after, I noticed
    `obj\Debug\android\src\android\support\compat\R.java` was missing the
    field for `R.id.textView1`!
    
        public static int textView1=0x7f080091;
    
    This doesn't match the error message we are getting here at all... But
    this file is updated by the `_GenerateJavaDesignerForComponent`
    MSBuild target. Further research showed that this target was getting
    skipped at step no. 4 above, because it was found to be up to date
    according to its inputs and outputs.
    
    To verify this was the case, I could delete
    `obj\Debug\Component.R.cs.flag` which would also resolve the runtime
    exception (instead of a full `Rebuild`).
    
    First, I created a new test:
    - `CustomViewAddResourceId` builds a project with
      `<android.support.design.widget.BottomNavigationView />`
    - Adds a `textView1` layout, builds again
    - Verifies that `obj\Debug\android\src\android\support\compat\R.java`
      contains `textView1`
    
    To fix the problem, I did the following:
    - Added `$(_AndroidResgenFlagFile)` as an input to
      `_GenerateJavaDesignerForComponent`, so it will run again when
      `_UpdateAndroidResgen` runs
    - Removed
      `AndroidComponentResgenFlagFile="$(_AndroidComponentResgenFlagFile)"`
      from the call to the `<Aapt />` MSBuild task, so it will re-run
      `aapt` and generate `R.java`.
    
    However, things were breaking when `$(AndroidUseAapt2)` was
    enabled.
    
    For `aapt2` support I had to:
    - Remove `AndroidComponentResgenFlagFile` from the `<Aapt2Link />`
      call
    - Set an extra property that the other `<Aapt2Link />` calls are
      already doing:
      `CompiledResourceFlatArchive="$(IntermediateOutputPath)\compiled.flata"`
    jonathanpeppers committed Sep 20, 2018
    Configuration menu
    Copy the full SHA
    f829ffd View commit details
    Browse the repository at this point in the history