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

Solution that crashes on startup when aapt2 is used #3169

Closed
jonathanpeppers opened this issue Jun 4, 2019 · 2 comments · Fixed by #3171
Closed

Solution that crashes on startup when aapt2 is used #3169

jonathanpeppers opened this issue Jun 4, 2019 · 2 comments · Fixed by #3171
Assignees
Labels
Area: App+Library Build Issues when building Library projects or Application projects. bug Component does not function as intended.
Milestone

Comments

@jonathanpeppers
Copy link
Member

Related to:

Steps to Reproduce

  1. Clone: https://github.com/zijianhuang/xamarinforms4bugs/tree/ResourcesInLib (use the ResourcesInLib branch)
  2. Build/Deploy with 16.2/master
  3. App crashes on start with:
06-04 15:47:55.260 25714 25714 I MonoDroid: 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]]
06-04 15:47:55.260 25714 25714 I MonoDroid:    --- End of inner exception stack trace ---
06-04 15:47:55.260 25714 25714 I MonoDroid:   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
06-04 15:47:55.260 25714 25714 I MonoDroid:   at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualVoidMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x0005d] in <372c976a2c5d45cb9abb001729e14dbf>:0
06-04 15:47:55.260 25714 25714 I MonoDroid:   at Android.App.Activity.OnCreate (Android.OS.Bundle savedInstanceState) [0x00031] in <547679cba0d64c03859bc6ab9919a165>:0
06-04 15:47:55.260 25714 25714 I MonoDroid:   at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.OnCreate (Android.OS.Bundle savedInstanceState) [0x0001d] in <02288cf327c341c79f8385d5db4c09bf>:0
06-04 15:47:55.260 25714 25714 I MonoDroid:   at Demo2.Droid.MainActivity.OnCreate (Android.OS.Bundle savedInstanceState) [0x00001] in <16681ab0b39d4abe8efd53e748c930e4>:0
06-04 15:47:55.260 25714 25714 I MonoDroid:   at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_savedInstanceState) [0x00011] in <547679cba0d64c03859bc6ab9919a165>:0
06-04 15:47:55.260 25714 25714 I MonoDroid:   at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.7(intptr,intptr,intptr)
06-04 15:47:55.260 25714 25714 I MonoDroid:   --- End of managed Java.Lang.NoClassDefFoundError stack trace ---

The obj\Debug\81\android\src\android\support\v7\appcompat\R.java file did not exist.

If I build with /p:AndroidUseAapt2=False, then everything works correctly.

This solution is setup in an odd way:

  • Demo2.csproj - forms netstandard stuff
  • Demo2.Android.csproj - android head project, note that @(AndroidResource) is empty
  • ClassLibrary1.Android.csproj - android class library with all the resources

Somehow both <Aapt/> and <Aapt2Link/> are skipped here, causing the issue:

image

Expected Behavior

Even though this project is setup in an odd way, it should work with aapt2 enabled.

Actual Behavior

This solution crashes on startup with aapt2 enabled.

Version Information

16.2/master

Log File

Logs.zip

@jonathanpeppers jonathanpeppers added bug Component does not function as intended. Area: App+Library Build Issues when building Library projects or Application projects. labels Jun 4, 2019
@jonathanpeppers jonathanpeppers added this to the d16-2 milestone Jun 4, 2019
@jonathanpeppers
Copy link
Member Author

The root cause might be:

Target Name=_CompileResources Project=Demo2.Android.csproj
    ...
    Skipping target "_CompileResources" because it has no inputs.
    Though the target has declared its inputs, the input specification only references empty properties and/or empty item lists.

Because @(AndroidResource) is empty in the head project.

@jonathanpeppers
Copy link
Member Author

I think the fix might be as simple as this:

diff --git a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets
index 94f6851a..3fd5b932 100755
--- a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets
+++ b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets
@@ -1699,7 +1699,7 @@ because xbuild doesn't support framework reference assemblies.
        />

        <Aapt2Link
-               Condition="'$(_AndroidResourceDesignerFile)' != '' And '$(_AndroidUseAapt2)' == 'True' And Exists ('$(_AndroidLibraryFlatArchivesDirectory)\compiled.flata')"
+               Condition="'$(_AndroidResourceDesignerFile)' != '' And '$(_AndroidUseAapt2)' == 'True'"
                ContinueOnError="$(DesignTimeBuild)"
                ResourceNameCaseMap="$(_AndroidResourceNameCaseMap)"
                AssemblyIdentityMapFile="$(_AndroidLibrayProjectAssemblyMapFile)"

Tomorrow, I'll see if I can get a PR. I'll need to come up with a test showing this problem.

jonathanpeppers added a commit to jonathanpeppers/xamarin-android that referenced this issue Jun 5, 2019
…lata

Fixes: dotnet#3169
Context: https://github.com/zijianhuang/xamarinforms4bugs/tree/ResourcesInLib

We discovered a solution that crashes on startup when it is built with
`$(AndroidUseAapt2)=True`:

    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 ---

This solution is setup in an odd way:

* NetStandard library with Xamarin.Forms/xplat code
* Android head project, where `@(AndroidResource)` is empty
* Android class library with all the resources, activity, etc.

The root cause being that `<Aapt2Link/>` was completely skipped, due
to this condition:

    <Aapt2Link Condition="'$(_AndroidResourceDesignerFile)' != '' And '$(_AndroidUseAapt2)' == 'True' And Exists ('$(_AndroidLibraryFlatArchivesDirectory)\compiled.flata')" ...

The `compiled.flata` file does not exist, because there are no
`@(AndroidResource)` files.

The fix here is to simply remove the `Exists` check; I also added a
new test for this scenario.

There is some further weirdness in this area I will fix in future PRs.
For now, this will be a good patch we could cherry-pick to 16.2.
dellis1972 pushed a commit that referenced this issue Jun 6, 2019
…lata (#3171)

Fixes: #3169
Context: https://github.com/zijianhuang/xamarinforms4bugs/tree/ResourcesInLib

We discovered a solution that crashes on startup when it is built with
`$(AndroidUseAapt2)=True`:

    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 ---

This solution is setup in an odd way:

* NetStandard library with Xamarin.Forms/xplat code
* Android head project, where `@(AndroidResource)` is empty
* Android class library with all the resources, activity, etc.

The root cause being that `<Aapt2Link/>` was completely skipped, due
to this condition:

    <Aapt2Link Condition="'$(_AndroidResourceDesignerFile)' != '' And '$(_AndroidUseAapt2)' == 'True' And Exists ('$(_AndroidLibraryFlatArchivesDirectory)\compiled.flata')" ...

The `compiled.flata` file does not exist, because there are no
`@(AndroidResource)` files.

The fix here is to simply remove the `Exists` check; I also added a
new test for this scenario.

There is some further weirdness in this area I will fix in future PRs.
For now, this will be a good patch we could cherry-pick to 16.2.
jonathanpeppers added a commit that referenced this issue Jun 6, 2019
…lata (#3171)

Fixes: #3169
Context: https://github.com/zijianhuang/xamarinforms4bugs/tree/ResourcesInLib

We discovered a solution that crashes on startup when it is built with
`$(AndroidUseAapt2)=True`:

    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 ---

This solution is setup in an odd way:

* NetStandard library with Xamarin.Forms/xplat code
* Android head project, where `@(AndroidResource)` is empty
* Android class library with all the resources, activity, etc.

The root cause being that `<Aapt2Link/>` was completely skipped, due
to this condition:

    <Aapt2Link Condition="'$(_AndroidResourceDesignerFile)' != '' And '$(_AndroidUseAapt2)' == 'True' And Exists ('$(_AndroidLibraryFlatArchivesDirectory)\compiled.flata')" ...

The `compiled.flata` file does not exist, because there are no
`@(AndroidResource)` files.

The fix here is to simply remove the `Exists` check; I also added a
new test for this scenario.

There is some further weirdness in this area I will fix in future PRs.
For now, this will be a good patch we could cherry-pick to 16.2.
jonathanpeppers added a commit to jonathanpeppers/xamarin-android that referenced this issue Jun 6, 2019
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 pushed a commit that referenced this issue 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.
jonpryor pushed a commit that referenced this issue 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.
@ghost ghost locked as resolved and limited conversation to collaborators Jun 6, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Area: App+Library Build Issues when building Library projects or Application projects. bug Component does not function as intended.
Projects
None yet
2 participants