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] Resource.designer.cs should not be empty #3177

Merged
merged 2 commits into from
Jun 7, 2019

Conversation

jonathanpeppers
Copy link
Member

Context: #3169

In 36c52c2, I fixed some of the weirdness from the test case in #3169,
but there is another problem: Resource.designer.cs was blank!

This is actually an issue because Xamarin.Forms 4.0 uses
AndroidResource files. If there is a case where
Resource.designer.cs isn't generated, then those resource IDs will
be incorrect--causing a crash at runtime.

Looking through the code, the sequence of events is a bit bizarre:

  1. <GenerateResourceDesigner/> writes to a temp file using
    MonoAndroidHelper.CopyIfStringChanged.
  2. <CopyIfChanged/> moves from the temp file to
    Resources\Resource.designer.cs if there were changes.
  3. <CreateAndroidResourceStamp/> basically does a "touch" and
    appends a newline to Resources.designer.cs??? It also touches a
    stamp/flag file.

The steps didn't make sense--it seems they all will run every time.

It seemed like we just needed to clean things up:

  1. <GenerateResourceDesigner/> writes directly to
    Resources\Resource.designer.cs, relying on
    MonoAndroidHelper.CopyIfStringChanged.
  2. We get rid of <CreateAndroidResourceStamp/>.
  3. We just use <Touch/> for the flag file, and add it to
    @(FileWrites) appropriately.

I think these changes will make this scenario a bit more reliable and
improve performance slightly.

I also updated the AllResourcesInClassLibrary test to verify
Resource.designer.cs exists and is non-empty.

Context: dotnet#3169

In 36c52c2, I fixed some of the weirdness from the test case in dotnet#3169,
but there is another problem: `Resource.designer.cs` was blank!

This is actually an issue because Xamarin.Forms 4.0 uses
`AndroidResource` files. If there is a case where
`Resource.designer.cs` isn't generated, then those resource IDs will
be incorrect--causing a crash at runtime.

Looking through the code, the sequence of events is a bit bizarre:

1. `<GenerateResourceDesigner/>` writes to a temp file using
   `MonoAndroidHelper.CopyIfStringChanged`.
2. `<CopyIfChanged/>` moves from the temp file to
   `Resources\Resource.designer.cs` if there were changes.
3. `<CreateAndroidResourceStamp/>` basically does a "touch" and
   appends a newline to `Resources.designer.cs`??? It also touches a
   stamp/flag file.

The steps didn't make sense--it seems they all will run every time.

It seemed like we just needed to clean things up:

1. `<GenerateResourceDesigner/>` writes directly to
   `Resources\Resource.designer.cs`, relying on
   `MonoAndroidHelper.CopyIfStringChanged`.
2. We get rid of `<CreateAndroidResourceStamp/>`.
3. We just use `<Touch/>` for the flag file, and add it to
   `@(FileWrites)` appropriately.

I think these changes will make this scenario a bit more reliable and
improve performance slightly.

I also updated the `AllResourcesInClassLibrary` test to verify
`Resource.designer.cs` *exists* and is non-empty.
@jonpryor
Copy link
Member

jonpryor commented Jun 7, 2019

The Xamarin.Android.Build.Tests.AndroidUpdateResourcesTest.CheckResourceDesignerIsUpdatedWhenReadOnly(True,CSharp) / Release test is failing on Windows:

E:\A\_work\1534\s\bin\TestRelease\temp\CheckResourceDesignerIsUpdatedWhenReadOnlyTrueCSharp\Resources\Resource.designer.cs should be writable Expected: True But was: False 

This test needs to actually create a new `android:id` so the contents of `Resource.designer.cs` will change.
@jonpryor jonpryor merged commit ea6853a into dotnet:master Jun 7, 2019
jonpryor pushed a commit that referenced this pull request Jun 7, 2019
…#3177)

Context: #3169

In 36c52c2, I fixed some of the weirdness from the test case in
Issue #3169, but there is another problem: `Resource.designer.cs` was
empty!

This is actually an issue because Xamarin.Forms 4.0 uses
`@(AndroidResource)` files.  If there is a case where
`Resource.designer.cs` isn't generated, then those resource IDs will
be wrong, causing a runtime crash:

	Java.Lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v7/appcompat/R$drawable; ---> Java.Lang.ClassNotFoundException: Didn't find class "android.support.v7.appcompat.R$drawable" on path: DexPathList[[zip file "/system/framework/org.apache.http.legacy.boot.jar", zip file "/data/app/com.companyname.Demo2.Android-PozTNMz4ZBMXaHx-doetdQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.companyname.Demo2.Android-PozTNMz4ZBMXaHx-doetdQ==/lib/arm64, /data/app/com.companyname.Demo2.Android-PozTNMz4ZBMXaHx-doetdQ==/base.apk!/lib/arm64-v8a, /system/lib64]]
	   --- End of inner exception stack trace ---
	  at Java.Interop.JniEnvironment+InstanceMethods.CallNonvirtualVoidMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniObjectReference type, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x00089] in <372c976a2c5d45cb9abb001729e14dbf>:0
	  at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualVoidMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x0005d] in <372c976a2c5d45cb9abb001729e14dbf>:0
	  at Android.App.Activity.OnCreate (Android.OS.Bundle savedInstanceState) [0x00031] in <547679cba0d64c03859bc6ab9919a165>:0
	  at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.OnCreate (Android.OS.Bundle savedInstanceState) [0x0001d] in <02288cf327c341c79f8385d5db4c09bf>:0
	  at Demo2.Droid.MainActivity.OnCreate (Android.OS.Bundle savedInstanceState) [0x00001] in <16681ab0b39d4abe8efd53e748c930e4>:0
	  at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_savedInstanceState) [0x00011] in <547679cba0d64c03859bc6ab9919a165>:0
	  at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.7(intptr,intptr,intptr)
	  --- End of managed Java.Lang.NoClassDefFoundError stack trace ---


Looking through the code, the sequence of events is a bit bizarre:

 1. `<GenerateResourceDesigner/>` writes to a temp file using
    `MonoAndroidHelper.CopyIfStringChanged()`.
 2. `<CopyIfChanged/>` moves from the temp file to
    `Resources\Resource.designer.cs` if there were changes.
 3. `<CreateAndroidResourceStamp/>` basically does a "touch" and
    appends a newline to `Resources.designer.cs`???  It also touches
    a stamp/flag file.

The steps didn't make sense--it seems they all will run every time.

It seemed like we just needed to clean things up:

 1. `<GenerateResourceDesigner/>` writes directly to
    `Resources\Resource.designer.cs`, relying on
    `MonoAndroidHelper.CopyIfStringChanged()`.
 2. We get rid of `<CreateAndroidResourceStamp/>`.
 3. We just use `<Touch/>` for the flag file, and add it to
    `@(FileWrites)` appropriately.

I think these changes will make this scenario a bit more reliable and
improve performance slightly.

I also updated the `AllResourcesInClassLibrary` test to verify
`Resource.designer.cs` *exists* and is non-empty.
@jonathanpeppers jonathanpeppers deleted the resource.designer.cs branch June 7, 2019 16:29
@github-actions github-actions bot locked and limited conversation to collaborators Jan 30, 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