Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Xamarin.Android.Build.Tasks] Resource.designer.cs shouldn't be empty (…
…#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.
- Loading branch information