Skip to content

Conversation

@dellis1972
Copy link
Contributor

@dellis1972 dellis1972 commented Aug 7, 2017

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
does result in the _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.

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.

@jonpryor
Copy link
Contributor

jonpryor commented Aug 8, 2017

Is it possible/practical to add a unit test for this? Would doing a (design-time build, Resource.designer.cs content check, normal build, content check) work?

@dellis1972
Copy link
Contributor Author

I can probably put a test together. Or expand the existing design time test

…- System.NullReferenceException at IntuneMAMSampleAndroid.EntryActivity.OnCreate

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
does result in the `_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.

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.
@jonpryor jonpryor merged commit 52d32c8 into dotnet:master Aug 10, 2017
jonpryor pushed a commit that referenced this pull request Aug 10, 2017
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.
jonpryor pushed a commit that referenced this pull request Oct 20, 2020
Fixes: dotnet/java-interop#461
Fixes: dotnet/java-interop#682
Fixes: dotnet/java-interop#717
Fixes: dotnet/java-interop#719
Fixes: dotnet/java-interop#728

Changes: dotnet/java-interop@ac914ce...b991bb8

  * dotnet/java-interop@b991bb86: [generator] Revert change to use auto-properties in EventArgs classes (#736)
  * dotnet/java-interop@ee50d89b: Bump to xamarin/xamarin-android-tools/master@f2af06f2 (#733)
  * dotnet/java-interop@a0b895c1: [build] Suppress NuGet warnings (#730)
  * dotnet/java-interop@8b1b0507: [generator] Fix parsing of complex generic types (#729)
  * dotnet/java-interop@ee7afeed: [generator] Prevent generating duplicate EventArgs classes (#726)
  * dotnet/java-interop@1f21f38c: [generator] Use GC.KeepAlive for reference type method parameters. (#725)
  * dotnet/java-interop@5136ef98: [Xamarin.Android.Tools.Bytecode] Hide Kotlin nested types inside (#723)
  * dotnet/java-interop@53d60513: [jnimarshalmethod-gen] Fix registration on Windows (#721)
  * dotnet/java-interop@5a834d42: [jnimarshalmethod-gen] Avoid creating AppDomains (#720)
  * dotnet/java-interop@a76edb8c: [Xamarin.Android.Tools.ApiXmlAdjuster] Find app.android.IntentService (#718)
  * dotnet/java-interop@6cde0877: [Java.Interop] Emit a reference assembly for Java.Interop.dll (#716)
  * dotnet/java-interop@b858dc59: [generator] Provide line/col numbers for api.xml warnings (#715)
  * dotnet/java-interop@9be92a04: [ci] Don't kick off CI for documentation only changes. (#712)
  * dotnet/java-interop@03c22722: [jnimarshalmethod-gen] Fix type resolution crash (#706)
@github-actions github-actions bot locked and limited conversation to collaborators Feb 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants