You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Xamarin.Android.Build.Tasks] Resource ids must be consistent (#721)
Fixes: https://bugzilla.xamarin.com/show_bug.cgi?id=57279
The DesignTimeBuilds are causing a bit of a problem.
Because they are being run as soon as the project is loaded, it
resulted in `_UpdateAndroidResGen` thinking that the
resources are up to date. This results in the following
$ find . -iname R.java | xargs grep EntryActivityStartButton
./IntuneMAMSampleAndroid/obj/AnyCPU/Debug/android/com/microsoft/intune/mam/R.java: public static final int EntryActivityStartButton=0x7f070000;
./IntuneMAMSampleAndroid/obj/AnyCPU/Debug/android/microsoftintunemamsampleandroid/microsoftintunemamsampleandroid/R.java: public static final int EntryActivityStartButton=0x7f070000;
./IntuneMAMSampleAndroid/obj/AnyCPU/Debug/android/src/android/support/v4/R.java: public static int EntryActivityStartButton=0x7f0c0050;
./IntuneMAMSampleAndroid/obj/AnyCPU/Debug/android/src/android/support/v7/appcompat/R.java: public static int EntryActivityStartButton=0x7f0c0050;
./IntuneMAMSampleAndroid/obj/AnyCPU/Debug/android/src/com/microsoft/intune/mam/R.java: public static final int EntryActivityStartButton=0x7f0c0050;
./IntuneMAMSampleAndroid/obj/AnyCPU/Debug/android/src/microsoftintunemamsampleandroid/microsoftintunemamsampleandroid/R.java: public static final int EntryActivityStartButton=0x7f0c0050;
Note that the `EntryActivityStartButton` value is different, they
should all be the same. This is because the `_UpdateAndroidResGen`
target was NOT running. As a result of this, when the app runs a
`NullReferenceException` could be thrown when the wrong resource id
value is inadvertently used with e.g. `Activity.FindViewById<T>(int)`:
// C#
var button = FindViewById<Button>(Resource.Id.button);
// `button` is actually null, as `Resource.id.button` is wrong
button.Click += delegate { /* ... */ };
// throws `NullReferenceException`, as `button` is null
Fortunately commit 1cd582e adds `$(DesignTimeBuild)` to the list
of properties in the `@(_PropertyCacheItems)` ItemGroup. So we can
now use the `$(_AndroidBuildPropertiesCache)` property to detect
when we are moving from a DesignTimeBuild into a normal Build.
This means the resources are then generated correctly.
Assert.IsFalse(b.Output.IsTargetSkipped("_BuildAdditionalResourcesCache"),"_BuildAdditionalResourcesCache should have run.");
90
-
Assert.IsTrue(b.LastBuildOutput.Contains($"Downloading {url}")||b.LastBuildOutput.Contains($"reusing existing archive: {zipPath}"),$"{url} should have been downloaded.");
100
+
Assert.IsTrue(b.LastBuildOutput.Contains($"Downloading {url}")||b.LastBuildOutput.Contains($"reusing existing archive: {zipPath}"),$"{url} should have been downloaded.");
91
101
Assert.IsTrue(File.Exists(Path.Combine(extractedDir,"1","content","android-N","aapt")),$"Files should have been extracted to {extractedDir}");
0 commit comments