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

Corrupt aapt_rules.txt when Creating a Package per Abi on Android #15800

Closed
yayameen opened this issue Jun 22, 2023 · 8 comments
Closed

Corrupt aapt_rules.txt when Creating a Package per Abi on Android #15800

yayameen opened this issue Jun 22, 2023 · 8 comments
Labels
partner/android Issues for the Android SDK platform/android 🤖 s/needs-attention Issue has more information and needs another look t/bug Something isn't working

Comments

@yayameen
Copy link

Description

Seems to be related to: dotnet/android#7447

When AndroidCreatePackagePerAbi is set to True in a project, a build error occurs due a corrupt aapt_rules.txt file.

I was able to duplicate this in both Visual Studio 17.5.4 and Visual Studio 17.6.4 on different machines.

Sample of end of aapt_rules.txt:

# Referenced at E:\Dev\Mission\trunk\dev\MySolution\MYProject\obj\Release\net6.0-android31.0\lp\157\jl\res\layout\flyoutcontent.xml:1
-keep class crc640ec207abc449b2ca.ShellFlyoutLayout { <init>(...); }

roid31.0\lp\157\jl\res\layout\flyoutcontent.xml:1
-keep class crc640ec207abc449b2ca.ShellFlyoutLayout { <init>(...); }

Steps to Reproduce

  1. Create New MAUI app
  2. In the project properties, turn on R8, AAPT2, and Create Package Per Abi.
  3. Build in Release mode.
  4. In a small project, it is possible that the issue is avoided. Likely that a minimum amount of project complexity is needed.

Link to public reproduction project repository

None

Version with bug

7.0.86

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

31

Did you find any workaround?

Turning off AndroidCreatePackagePerAbi removes the build error, but then you end up with an APK 4 times larger, which contains architectures you do not need to target. In my circumstance the APK is over 100MB.

Side note: Nothing I do will prevent release mode from placing every architecture in the APK. In debug mode I can target a single architecture. I am targeting ARM64. I haven't tried other architectures. Creating an APK for each abi was my way of working around that issue.

Relevant log output

Error in obj\Release\net6.0-android31.0\aapt_rules.txt at line 239, column 1:
         Expected char '-' at obj\Release\net6.0-android31.0\aapt_rules.txt:239:1
         roid31.0\lp\157\jl\res\layout\flyoutcontent.xml:1
         ^
         Compilation failed
         Exception in thread "main" java.lang.RuntimeException: com.android.tools.r8.CompilationFailedException: Compilation failed to complete, position: offset: 14490, line: 239, column: 1, origin: obj\Release\net6.0-android31.0\aapt_rules.txt
         	at com.android.tools.r8.internal.Bj.a(R8_3.3.28_2aaf796388b4e9f6bed752d926eca110512a53a3f09a8d755196089c1cfdf799:98)
         	at com.android.tools.r8.R8.main(R8_3.3.28_2aaf796388b4e9f6bed752d926eca110512a53a3f09a8d755196089c1cfdf799:4)
         Caused by: com.android.tools.r8.CompilationFailedException: Compilation failed to complete, position: offset: 14490, line: 239, column: 1, origin: obj\Release\net6.0-android31.0\aapt_rules.txt
         	at Version.fakeStackEntry(Version_3.3.28.java:0)
         	at com.android.tools.r8.internal.Bj.a(R8_3.3.28_2aaf796388b4e9f6bed752d926eca110512a53a3f09a8d755196089c1cfdf799:75)
         	at com.android.tools.r8.internal.Bj.a(R8_3.3.28_2aaf796388b4e9f6bed752d926eca110512a53a3f09a8d755196089c1cfdf799:28)
         	at com.android.tools.r8.internal.Bj.a(R8_3.3.28_2aaf796388b4e9f6bed752d926eca110512a53a3f09a8d755196089c1cfdf799:27)
         	at com.android.tools.r8.BaseCommand$Builder.build(R8_3.3.28_2aaf796388b4e9f6bed752d926eca110512a53a3f09a8d755196089c1cfdf799:2)
         	at com.android.tools.r8.R8.b(R8_3.3.28_2aaf796388b4e9f6bed752d926eca110512a53a3f09a8d755196089c1cfdf799:19)
         	at com.android.tools.r8.R8.a(R8_3.3.28_2aaf796388b4e9f6bed752d926eca110512a53a3f09a8d755196089c1cfdf799:2212)
         	at com.android.tools.r8.internal.Bj.a(R8_3.3.28_2aaf796388b4e9f6bed752d926eca110512a53a3f09a8d755196089c1cfdf799:85)
         	... 1 more
         Caused by: com.android.tools.r8.internal.f: Expected char '-' at obj\Release\net6.0-android31.0\aapt_rules.txt:239:1
         roid31.0\lp\157\jl\res\layout\flyoutcontent.xml:1
         ^
         	at com.android.tools.r8.internal.DT.a(R8_3.3.28_2aaf796388b4e9f6bed752d926eca110512a53a3f09a8d755196089c1cfdf799:14)
         	at com.android.tools.r8.internal.DT.error(R8_3.3.28_2aaf796388b4e9f6bed752d926eca110512a53a3f09a8d755196089c1cfdf799:1)
         	at com.android.tools.r8.shaking.J1.a(R8_3.3.28_2aaf796388b4e9f6bed752d926eca110512a53a3f09a8d755196089c1cfdf799:12)
         	at com.android.tools.r8.R8Command$Builder.q(R8_3.3.28_2aaf796388b4e9f6bed752d926eca110512a53a3f09a8d755196089c1cfdf799:17)
         	at com.android.tools.r8.R8Command$Builder.p(R8_3.3.28_2aaf796388b4e9f6bed752d926eca110512a53a3f09a8d755196089c1cfdf799:4)
         	at com.android.tools.r8.R8Command$Builder.c(R8_3.3.28_2aaf796388b4e9f6bed752d926eca110512a53a3f09a8d755196089c1cfdf799:1)
         	at com.android.tools.r8.BaseCommand$Builder.a(R8_3.3.28_2aaf796388b4e9f6bed752d926eca110512a53a3f09a8d755196089c1cfdf799:2)
         	at com.android.tools.r8.internal.Bj.a(R8_3.3.28_2aaf796388b4e9f6bed752d926eca110512a53a3f09a8d755196089c1cfdf799:24)
         	... 5 more
         	Suppressed: java.lang.RuntimeException: com.android.tools.r8.internal.f: Expected char '-' at obj\Release\net6.0-android31.0\aapt_rules.txt:239:1
         roid31.0\lp\157\jl\res\layout\flyoutcontent.xml:1
         ^
         		at com.android.tools.r8.internal.DT.a(R8_3.3.28_2aaf796388b4e9f6bed752d926eca110512a53a3f09a8d755196089c1cfdf799:25)
         		at com.android.tools.r8.shaking.J1.a(R8_3.3.28_2aaf796388b4e9f6bed752d926eca110512a53a3f09a8d755196089c1cfdf799:239)
         		... 10 more
         	Caused by: [CIRCULAR REFERENCE: com.android.tools.r8.internal.f: Expected char '-' at obj\Release\net6.0-android31.0\aapt_rules.txt:239:1
         roid31.0\lp\157\jl\res\layout\flyoutcontent.xml:1
         ^]
     2>C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\32.0.485\tools\Xamarin.Android.D8.targets(51,5): error : java.lang.RuntimeException: com.android.tools.r8.CompilationFailedException: Compilation failed to complete, position: offset: 14490, line: 239, column: 1, origin :  obj\Release\net6.0-android31.0\aapt_rules.txt [E:\Dev\Mission\trunk\dev\MySolution\MySolution\MySolution.csproj::TargetFramework=net6.0-android31.0]
     2>Done Building Project "E:\Dev\Mission\trunk\dev\MySolution\MySolution\MySolution.csproj" (Build target(s)) -- FAILED.
     2>Done Building Project "E:\Dev\Mission\trunk\dev\MySolution\MySolution\MySolution.csproj" (Rebuild target(s)) -- FAILED.
     1>Done Building Project "E:\Dev\Mission\trunk\dev\MySolution\MySolution.sln" (rebuild target(s)) -- FAILED.

Build FAILED.
@yayameen yayameen added the t/bug Something isn't working label Jun 22, 2023
@drasticactions
Copy link
Contributor

drasticactions commented Jun 23, 2023

Going by that original issue, this doesn't seem specific to the MAUI UI Project but a general issue with the Xamarin.Android.Build.Tasks that would affect anything. This seems like something that would go to the xamarin-android repo, if it's not already addressed in the newest versions of VS / Android SDK. @jonathanpeppers what do you think? Is there anything in this repo that needs to be addressed?

@jonathanpeppers
Copy link
Member

This change should be in .NET 7 already: dotnet/android#7587

Are you able to record a .binlog when you hit this issue?

@jonathanpeppers jonathanpeppers added partner/android Issues for the Android SDK s/needs-info Issue needs more info from the author labels Jun 23, 2023
@ghost
Copy link

ghost commented Jun 23, 2023

Hi @yayameen. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@yayameen
Copy link
Author

I will try to record a log and add it. I am targeting .NET 6 now, but I don't know that there is any reason not to move to .NET 7. I can try that as well. I was trying to get a new version of the software out the door, so I stayed with .NET 6 to reduce the number of moving parts.

@ghost ghost added s/needs-attention Issue has more information and needs another look and removed s/needs-info Issue needs more info from the author labels Jun 23, 2023
@jonathanpeppers
Copy link
Member

The above fix is not in .NET 6, so it would make sense if you see it there.

It is a general good idea to move to .NET 7, because .NET 6 mobile workloads are out of support:

https://dotnet.microsoft.com/platform/support/policy/maui

@yayameen
Copy link
Author

Migrating to NET 7 seems to have worked. I ran into this issue at first ( xamarin/GooglePlayServicesComponents#694 ) but followed the work around. That being said, I can't say definitively that the bug was consistent before. I'm not sure if a race condition or some other build setting might have come into play. For now, I will consider this resolved with your amazing help. Thank You.

@yayameen
Copy link
Author

I built many times successfully, but our build machine just encountered the same error using NET 7 targeting Android 33.0

@yayameen
Copy link
Author

Turning off r8 linking seemed to resolve the issue, but I can't say that workaround is reliable.

@ghost ghost locked as resolved and limited conversation to collaborators Jul 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
partner/android Issues for the Android SDK platform/android 🤖 s/needs-attention Issue has more information and needs another look t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants