-
Notifications
You must be signed in to change notification settings - Fork 533
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
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
|
This test needs to actually create a new `android:id` so the contents of `Resource.designer.cs` will change.
dellis1972
reviewed
Jun 7, 2019
dellis1972
approved these changes
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.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 whereResource.designer.cs
isn't generated, then those resource IDs willbe incorrect--causing a crash at runtime.
Looking through the code, the sequence of events is a bit bizarre:
<GenerateResourceDesigner/>
writes to a temp file usingMonoAndroidHelper.CopyIfStringChanged
.<CopyIfChanged/>
moves from the temp file toResources\Resource.designer.cs
if there were changes.<CreateAndroidResourceStamp/>
basically does a "touch" andappends a newline to
Resources.designer.cs
??? It also touches astamp/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:
<GenerateResourceDesigner/>
writes directly toResources\Resource.designer.cs
, relying onMonoAndroidHelper.CopyIfStringChanged
.<CreateAndroidResourceStamp/>
.<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 verifyResource.designer.cs
exists and is non-empty.