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 project build fails after upgrading to Visual Studio 17.3.5 (from 17.2.5) due to missing .dll in AOT folder and aapt_rules.txt #7447

Closed
vilinet opened this issue Oct 10, 2022 · 18 comments · Fixed by #7587
Assignees
Labels
Area: App+Library Build Issues when building Library projects or Application projects.

Comments

@vilinet
Copy link

vilinet commented Oct 10, 2022

Android application type

Classic Xamarin.Android (MonoAndroid12.0, etc.)

Affected platform version

VS 17.3.5

Description

Not a single change in our project or CI script, just VS got update to the currently latest one and we experience 2 strange and blocker side-effect during AOT apk build, that can be strangely workaround if we get rid of those packages, but still nothing change on our side at all aside the VS update:

First:
It looks like some .dll is not getting copied/generated into the target folder anymore like Humanizer or PublicHoliday give us this error at the very end of the AOT process when it tries to zip the aot files into a zip:
"X.Android.csproj" (SignAndroidPackage target) (1) -> (_BuildApkEmbed target) -> C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2049,3): error XABLD7028: Sy [MissingDllDuringAOT.zip](https://github.com/xamarin/xamarin-android/files/9745881/MissingDllDuringAOT.zip) stem.IO.FileNotFoundException: Could not find file 'X.Android\obj\DEV-Release\110\aot\arm64-v8a\libaot-PublicHoliday.dll.so'. [X.Android.csproj] C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(2049,3): error XABLD7028: File name: 'X.Android\obj\DEV-Release\110\aot\arm64-v8a\libaot-PublicHoliday.dll.so'

Second error that even if we get those things fixed, we get now these errors during the "startup" phase of the build that we have no idea so far why and can't even workaround it:

MSBUILD : java.exe error JAVA0000: Error in obj\Release\110\aapt_rules.txt at line 289, column 1: [C:\Jenkins\workspace\Demo\Demo.Android\Demo.Android.csproj] MSBUILD : java.exe error JAVA0000: Expected char '-' at obj\Release\110\aapt_rules.txt:289:1 [C:\Jenkins\workspace\Demo\Demo.Android\Demo.Android.csproj] MSBUILD : java.exe error JAVA0000: nit>(...); } [C:\Jenkins\workspace\Demo\Demo.Android\Demo.Android.csproj] MSBUILD : java.exe error JAVA0000: Compilation failed

I hope someone can help why these now happen and some possible workaround to fix these issues

Steps to Reproduce

I can reproduce the error by trying to build the attached MissingDllDuringAOT.zip in Release mode.

Did you find any workaround?

No response

Relevant log output

Severity Code Description Project File Line Suppression State Error XABBA7028: System.IO.FileNotFoundException: Could not find file 'C:\Users\Charlie\Downloads\MissingDllDuringAOT\MissingDllDuringAOT\MissingDllDuringAOT\obj\Release\110\aot\armeabi-v7a\libaot-Humanizer.dll.so'. File name: 'C:\Users\Charlie\Downloads\MissingDllDuringAOT\MissingDllDuringAOT\MissingDllDuringAOT\obj\Release\110\aot\armeabi-v7a\libaot-Humanizer.dll.so' at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.File.GetAttributes(String path) at Xamarin.Tools.Zip.WindowsPlatformServices.IsDirectory(ZipArchive archive, String path, Boolean& result) in /Users/runner/work/1/s/LibZipSharp/Xamarin.Tools.Zip/WindowsPlatformServices.cs:line 47 at Xamarin.Tools.Zip.PlatformServices.CallServices(Func2 code) in /Users/runner/work/1/s/LibZipSharp/Xamarin.Tools.Zip/PlatformServices.cs:line 166
at Xamarin.Tools.Zip.PlatformServices.IsDirectory(ZipArchive archive, String path) in /Users/runner/work/1/s/LibZipSharp/Xamarin.Tools.Zip/PlatformServices.cs:line 74
at Xamarin.Tools.Zip.ZipArchive.AddFile(String sourcePath, String archivePath, EntryPermissions permissions, CompressionMethod compressionMethod, Boolean overwriteExisting) in /Users/runner/work/1/s/LibZipSharp/Xamarin.Tools.Zip/ZipArchive.cs:line 406
at Xamarin.Android.Tasks.BuildApk.ExecuteWithAbi(String[] supportedAbis, String apkInputPath, String apkOutputPath, Boolean debug, Boolean compress, IDictionary2 compressedAssembliesInfo, String assemblyStoreApkName) at Xamarin.Android.Tasks.BuildApk.RunTask() at Microsoft.Android.Build.Tasks.AndroidTask.Execute() in /Users/runner/work/1/s/xamarin-android/external/xamarin-android-tools/src/Microsoft.Android.Build.BaseTasks/AndroidTask.cs:line 17 0 _No response_

@vilinet vilinet added Area: App+Library Build Issues when building Library projects or Application projects. needs-triage Issues that need to be assigned. labels Oct 10, 2022
@vilinet vilinet changed the title Xamarin.Android project build fails after upgrading to latest Visual Studio 17.3.5 due to missing .dll in AOT folder and also Xamarin.Android project build fails after upgrading to latest Visual Studio 17.3.5 due to missing .dll in AOT folder and aapt_rules.txt Oct 10, 2022
@vilinet vilinet changed the title Xamarin.Android project build fails after upgrading to latest Visual Studio 17.3.5 due to missing .dll in AOT folder and aapt_rules.txt Xamarin.Android project build fails after upgrading to Visual Studio 17.3.5 (from 17.2.5) due to missing .dll in AOT folder and aapt_rules.txt Oct 10, 2022
@dellis1972
Copy link
Contributor

Hi, The second error seems to be related to the AndroidLinkTool which you are using in your project.
I think the recommendation is to use r8 now for the AndroidLinkTool for release builds and d8 for debug. You might need to delete your bin/obj folders to get a clean build on upgrade. The error suggests that the format of the aapt_rules.txt file has changed and the old version is now incompatible. This file is auto generated by aapt2 during the build pocess.

Can you provide a diagnostic build log which contains the error ?

This can be done on the Visual Studio Developer Command Prompt. You can navigate to your project directory then use

msbuild Demo.Android.csproj /restore /p:Configuration=Release /t:SignAndroidPackage /bl

This will produce a msbuild.binlog file which you can zip up and attach to this issue.

@dellis1972 dellis1972 added need-info Issues that need more information from the author. and removed needs-triage Issues that need to be assigned. labels Oct 10, 2022
@ghost
Copy link

ghost commented Oct 10, 2022

Hi @vilinet. We have added the "need-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.

@vilinet
Copy link
Author

vilinet commented Oct 10, 2022

@dellis1972
I will run it soon with the logging.

Until that, This issue happens in release only anyway and we always build with cleaned/removed bin/obj dirs.

This is the Android.csproj related section:
<AndroidManagedSymbols>true</AndroidManagedSymbols> <AndroidUseSharedRuntime>false</AndroidUseSharedRuntime> <EmbedAssembliesIntoApk>true</EmbedAssembliesIntoApk> <AndroidLinkMode>SdkOnly</AndroidLinkMode> <AotAssemblies>true</AotAssemblies> <AndroidLinkTool>r8</AndroidLinkTool> <AndroidCreatePackagePerAbi>true</AndroidCreatePackagePerAbi> <AndroidKeyStore>true</AndroidKeyStore> <AndroidApkSignerAdditionalArguments>--v2-signing-enabled true</AndroidApkSignerAdditionalArguments>

@vilinet
Copy link
Author

vilinet commented Oct 10, 2022

Regarding the missing AOT-d dlls, i noticed that the 2 libs we have issues with, Humanizer and PublicHoliday, both uses local-dependent nuget packages as dependencies.
So i wonder if something changed/broke in msbuild local resolution causing AOT not finding the proper local-dependent dll for AOt-ing?

@ghost ghost added need-attention A xamarin-android contributor needs to review and removed need-info Issues that need more information from the author. labels Oct 10, 2022
@vilinet
Copy link
Author

vilinet commented Oct 10, 2022

I cant really provide the logs as they are kind of private for now, i will try to replicate it with a new project, BUT
I found something strange, i found out why the aapt_rules are failing,
it looks like the aapt_rules.txt file is not getting flushed properly during the generation.
Sometimes the CI has no issue and it just builds that, but most of the time the aapt_rules.txt has some random "garbage" due to some bad stream flushing:

Like here:
image
Seemingly in the 128th line, the -keep and "#Referenced at" line got merged somehow into a single line.

So i am gonna have a look at our CI.
But the missing .dll is still happening on every machine.

@vilinet
Copy link
Author

vilinet commented Oct 10, 2022

I managed to reproduce the AOT dll problem with a sample project that i attached and added to the "Reproduce" section also the exact error message to the "Relevent Log output"

@jonathanpeppers jonathanpeppers added need-info Issues that need more information from the author. and removed need-attention A xamarin-android contributor needs to review labels Oct 10, 2022
@ghost
Copy link

ghost commented Oct 10, 2022

Hi @vilinet. We have added the "need-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.

@ghost
Copy link

ghost commented Oct 17, 2022

Hi @vilinet. Due to inactivity, we will be closing this issue. Please feel free to re-open this issue if the issue persists. For enhanced visibility, if over 7 days have passed, please open a new issue and link this issue there. Thank you.

@ghost ghost closed this as completed Oct 17, 2022
@vilinet
Copy link
Author

vilinet commented Oct 18, 2022

[Updated]

Here is the .binlog for the missing dll problem during AOT:
MissingDllDuringAOT_Release_AnyCPU_Build_2022-10-18T15_22_45.9764268+01_00.zip
MissingDllDuringAOT_Release_AnyCPU_Build_2.zip

Detailed build log:
build_aot_output.txt

Video about the error:
https://user-images.githubusercontent.com/13279531/196472862-16d1a7aa-66e3-472b-a456-07c3c9357258.mp4

Also we noticed that during AOT, the build output shows this (at ~18seconds in the video) or look at the build log.

But we think these error blocking the AOT .dll from being generated:

[aot-compiler stderr] obj\Release\110\aot\arm64-v8a\Humanizer.dll\temp.s:77327:84: error: unexpected token in directive
[aot-compiler stderr] .local Humanizer_Localisation_NumberToWords_GreekNumberToWordsConverter_ConvertIntÎ_13_long_bool
[aot-compiler stderr] obj\Release\110\aot\arm64-v8a\Humanizer.dll\temp.s:77328:83: error: expected STT_<TYPE_IN_UPPER_CASE>, '#', '@', '%' or ""
[aot-compiler stderr] .type Humanizer_Localisation_NumberToWords_GreekNumberToWordsConverter_ConvertIntÎ_13_long_bool,@function
[aot-compiler stderr] obj\Release\110\aot\arm64-v8a\Humanizer.dll\temp.s:77329:76: error: invalid operand
[aot-compiler stderr] Humanizer_Localisation_NumberToWords_GreekNumberToWordsConverter_ConvertIntÎ_13_long_bool:
[aot-compiler stderr] obj\Release\110\aot\arm64-v8a\Humanizer.dll\temp.s:77369:83: error: unexpected token in directive
[aot-compiler stderr] .size Humanizer_Localisation_NumberToWords_GreekNumberToWordsConverter_ConvertIntÎ_13_long_bool,.-Humanizer_Localisation_NumberToWords_GreekNumberToWordsConverter_ConvertIntÎ_13_long_bool
[aot-compiler stdout] Running: "C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Xamarin\Android\binutils\bin\llvm-mc.exe" --arch=arm --triple=arm-linux-gnu --assemble --filetype=obj --mattr=+armv7-a,+vfp3 -o=obj\Release\110\aot\armeabi-v7a\Xamarin.Forms.Core.dll\temp.s.o obj\Release\110\aot\armeabi-v7a\Xamarin.Forms.Core.dll\temp.s
[aot-compiler stderr] ld: warning: lld uses blx instruction, no object with architecture supporting feature detected
[aot-compiler stdout] Running: "C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Xamarin\Android\binutils\bin\llvm-mc.exe" --arch=aarch64 --triple=aarch64-linux-gnu --assemble --filetype=obj -o=obj\Release\110\aot\arm64-v8a\Java.Interop.dll\temp.s.o obj\Release\110\aot\arm64-v8a\Java.Interop.dll\temp.s
[aot-compiler stderr] obj\Release\110\aot\arm64-v8a\Humanizer.dll\temp.s:154705:88: error: unexpected token in directive
[aot-compiler stderr] .local plt_Humanizer_Localisation_NumberToWords_GreekNumberToWordsConverter_ConvertIntÎ_13_long_bool
[aot-compiler stderr] obj\Release\110\aot\arm64-v8a\Humanizer.dll\temp.s:154706:87: error: expected STT_<TYPE_IN_UPPER_CASE>, '#', '@', '%' or ""
[aot-compiler stderr] .type plt_Humanizer_Localisation_NumberToWords_GreekNumberToWordsConverter_ConvertIntÎ_13_long_bool,@function
[aot-compiler stderr] obj\Release\110\aot\arm64-v8a\Humanizer.dll\temp.s:154707:80: error: invalid operand
[aot-compiler stderr] plt_Humanizer_Localisation_NumberToWords_GreekNumberToWordsConverter_ConvertIntÎ_13_long_bool:
[aot-compiler stderr] obj\Release\110\aot\arm64-v8a\Humanizer.dll\temp.s:154714:87: error: unexpected token in directive
[aot-compiler stderr] .size plt_Humanizer_Localisation_NumberToWords_GreekNumberToWordsConverter_ConvertIntÎ_13_long_bool,.-plt_Humanizer_Localisation_NumberToWords_GreekNumberToWordsConverter_ConvertIntÎ_13_long_bool
[aot-compiler stdout] Mono Ahead of Time compiler - compiling assembly

@vilinet
Copy link
Author

vilinet commented Oct 18, 2022

@dellis1972 Hi, could you re-open the ticket please? Sorry for the late .binlog but there it is. Just as an example solution to reproduce the problem.

@dellis1972 dellis1972 reopened this Oct 18, 2022
@vilinet
Copy link
Author

vilinet commented Oct 18, 2022

Regarding the AAPT2 error, here is a video of the AAPT 2 error with a fresh, clean build and the regarding binlog files:
aapt-error-binlog.zip

aapt_error.mp4

It really looks like the aap rules files is not getting flushed properly during generation and the lines getting scrambled

@ghost ghost added need-attention A xamarin-android contributor needs to review and removed need-info Issues that need more information from the author. labels Oct 18, 2022
@melimion
Copy link

vs 17.4.1 - issue still persists

@jonathanpeppers
Copy link
Member

I tried the project above, and I'm not hitting an issue with aapt_rules.txt, but I get:

Xamarin.Android.Common.targets(2084,3): error XABBA7028: System.IO.FileNotFoundException: Could not find file 'C:\Users\jopepper\Downloads\MissingDllDuringAOT\MissingDllDuringAOT\obj\Release\110\aot\armeabi-v7a\libaot-Humanizer.dll.so'.

It looks like the core problem is that Mono's AOT compiler is having an issue with Humanizer:

[aot-compiler stderr] obj\\Release\\110\\aot\\armeabi-v7a\\Humanizer.dll\\temp.s:36178:83: error: expected STT_<TYPE_IN_UPPER_CASE>, '#<type>', '%<type>' or "<type>"
[aot-compiler stderr]         .type Humanizer_Localisation_NumberToWords_GreekNumberToWordsConverter_ConvertInt╬_13_long_bool,#function

It looks like the "B" here is some unicode character:

https://github.com/Humanizr/Humanizer/blob/7f80e03070f9e46cb5bc499567a95e0f54b4bdb5/src/Humanizer/Localisation/NumberToWords/GreekNumberToWordsConverter.cs#L187

GitHub can't even render it here:

https://github.com/Humanizr/Humanizer/blob/7f80e03070f9e46cb5bc499567a95e0f54b4bdb5/src/Humanizer/Localisation/NumberToWords/GreekNumberToWordsConverter.cs#L161

image

So to look into this further:

  1. If you don't use Humanizer, do the issues go away?
  2. Does this still happen in .NET 6+?

If the problem happens in .NET 6+, we will have an easier time reporting an issue for the AOT compiler and getting it fixed.

@jonathanpeppers jonathanpeppers removed the need-attention A xamarin-android contributor needs to review label Nov 28, 2022
@jonathanpeppers jonathanpeppers added the need-info Issues that need more information from the author. label Nov 28, 2022
@ghost
Copy link

ghost commented Nov 28, 2022

Hi @vilinet. We have added the "need-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.

@melimion
Copy link

@jonathanpeppers , try remove bin and obj folders and then Rebuild project. Not Build or Deploy.
Rebuild reproduces aapt_rules.txt issue.

If I use Build, projects builds successfully.
If I use Deploy, your issue with Humanizer reproduced.

@ghost ghost added need-attention A xamarin-android contributor needs to review and removed need-info Issues that need more information from the author. labels Nov 29, 2022
@dellis1972
Copy link
Contributor

@melimion I think this is related to the AndroidCreatePackagePerAbi setting.
can you try turning that off?

I think whats happening is multiple calls to aapt2 link are using the same file, and they are tripping over each other.

@dellis1972 dellis1972 removed the need-attention A xamarin-android contributor needs to review label Nov 29, 2022
@melimion
Copy link

@dellis1972 looks like you're right, 5 rebuilds with <AndroidCreatePackagePerAbi>false</AndroidCreatePackagePerAbi> succeded

@dellis1972
Copy link
Contributor

@melimion ok cool good to know, I'm working on a fix 👍

dellis1972 added a commit to dellis1972/xamarin-android that referenced this issue Nov 29, 2022
Fixes dotnet#7447

Users are reporting a error with the aapt_rules file generated by aapt2
```
MSBUILD : java.exe error JAVA0000: Error in obj\Release\110\aapt_rules.txt at line 289, column 1: [C:\Jenkins\workspace\Demo\Demo.Android\Demo.Android.csproj]
MSBUILD : java.exe error JAVA0000: Expected char '-' at obj\Release\110\aapt_rules.txt:289:1 [C:\Jenkins\workspace\Demo\Demo.Android\Demo.Android.csproj]
MSBUILD : java.exe error JAVA0000: nit>(...); } [C:\Jenkins\workspace\Demo\Demo.Android\Demo.Android.csproj]
MSBUILD : java.exe error JAVA0000: Compilation failed
```

This only happens when building with `AndroidCreatePackagePerAbi` set
to `true`. After looking at the code, it turns out that we call
`aapt2 link` multiple times when building per abi. The temp file used
for the `aapt2 link` proguard output was the same file for ALL of the
calls. This results in one call to aapt2 overwriting the previous ones
results... or worse leaving garbage at the end.

So the fix in this case is to provide a different temp file for each
call to `aapt2`. These files are then combined later just in case they
contain unique information for that abi. While this does result in
duplicate lines in the `aapt_rules` file, this does not impact on the
build.
dellis1972 added a commit to dellis1972/xamarin-android that referenced this issue Nov 30, 2022
Fixes dotnet#7447

Users are reporting a error with the aapt_rules file generated by aapt2
```
MSBUILD : java.exe error JAVA0000: Error in obj\Release\110\aapt_rules.txt at line 289, column 1: [C:\Jenkins\workspace\Demo\Demo.Android\Demo.Android.csproj]
MSBUILD : java.exe error JAVA0000: Expected char '-' at obj\Release\110\aapt_rules.txt:289:1 [C:\Jenkins\workspace\Demo\Demo.Android\Demo.Android.csproj]
MSBUILD : java.exe error JAVA0000: nit>(...); } [C:\Jenkins\workspace\Demo\Demo.Android\Demo.Android.csproj]
MSBUILD : java.exe error JAVA0000: Compilation failed
```

This only happens when building with `AndroidCreatePackagePerAbi` set
to `true`. After looking at the code, it turns out that we call
`aapt2 link` multiple times when building per abi. The temp file used
for the `aapt2 link` proguard output was the same file for ALL of the
calls. This results in one call to aapt2 overwriting the previous ones
results... or worse leaving garbage at the end.

So the fix in this case is to provide a different temp file for each
call to `aapt2`. These files are then combined later just in case they
contain unique information for that abi. While this does result in
duplicate lines in the `aapt_rules` file, this does not impact on the
build.
dellis1972 added a commit to dellis1972/xamarin-android that referenced this issue Dec 1, 2022
Fixes dotnet#7447

Users are reporting a error with the aapt_rules file generated by aapt2
```
MSBUILD : java.exe error JAVA0000: Error in obj\Release\110\aapt_rules.txt at line 289, column 1: [C:\Jenkins\workspace\Demo\Demo.Android\Demo.Android.csproj]
MSBUILD : java.exe error JAVA0000: Expected char '-' at obj\Release\110\aapt_rules.txt:289:1 [C:\Jenkins\workspace\Demo\Demo.Android\Demo.Android.csproj]
MSBUILD : java.exe error JAVA0000: nit>(...); } [C:\Jenkins\workspace\Demo\Demo.Android\Demo.Android.csproj]
MSBUILD : java.exe error JAVA0000: Compilation failed
```

This only happens when building with `AndroidCreatePackagePerAbi` set
to `true`. After looking at the code, it turns out that we call
`aapt2 link` multiple times when building per abi. The temp file used
for the `aapt2 link` proguard output was the same file for ALL of the
calls. This results in one call to aapt2 overwriting the previous ones
results... or worse leaving garbage at the end.

So the fix in this case is to provide a different temp file for each
call to `aapt2`. These files are then combined later just in case they
contain unique information for that abi. While this does result in
duplicate lines in the `aapt_rules` file, this does not impact on the
build.
dellis1972 added a commit to dellis1972/xamarin-android that referenced this issue Dec 5, 2022
Fixes dotnet#7447

Users are reporting a error with the aapt_rules file generated by aapt2
```
MSBUILD : java.exe error JAVA0000: Error in obj\Release\110\aapt_rules.txt at line 289, column 1: [C:\Jenkins\workspace\Demo\Demo.Android\Demo.Android.csproj]
MSBUILD : java.exe error JAVA0000: Expected char '-' at obj\Release\110\aapt_rules.txt:289:1 [C:\Jenkins\workspace\Demo\Demo.Android\Demo.Android.csproj]
MSBUILD : java.exe error JAVA0000: nit>(...); } [C:\Jenkins\workspace\Demo\Demo.Android\Demo.Android.csproj]
MSBUILD : java.exe error JAVA0000: Compilation failed
```

This only happens when building with `AndroidCreatePackagePerAbi` set
to `true`. After looking at the code, it turns out that we call
`aapt2 link` multiple times when building per abi. The temp file used
for the `aapt2 link` proguard output was the same file for ALL of the
calls. This results in one call to aapt2 overwriting the previous ones
results... or worse leaving garbage at the end.

So the fix in this case is to provide a different temp file for each
call to `aapt2`. These files are then combined later just in case they
contain unique information for that abi. While this does result in
duplicate lines in the `aapt_rules` file, this does not impact on the
build.
dellis1972 added a commit to dellis1972/xamarin-android that referenced this issue Dec 7, 2022
Fixes dotnet#7447

Users are reporting a error with the aapt_rules file generated by aapt2
```
MSBUILD : java.exe error JAVA0000: Error in obj\Release\110\aapt_rules.txt at line 289, column 1: [C:\Jenkins\workspace\Demo\Demo.Android\Demo.Android.csproj]
MSBUILD : java.exe error JAVA0000: Expected char '-' at obj\Release\110\aapt_rules.txt:289:1 [C:\Jenkins\workspace\Demo\Demo.Android\Demo.Android.csproj]
MSBUILD : java.exe error JAVA0000: nit>(...); } [C:\Jenkins\workspace\Demo\Demo.Android\Demo.Android.csproj]
MSBUILD : java.exe error JAVA0000: Compilation failed
```

This only happens when building with `AndroidCreatePackagePerAbi` set
to `true`. After looking at the code, it turns out that we call
`aapt2 link` multiple times when building per abi. The temp file used
for the `aapt2 link` proguard output was the same file for ALL of the
calls. This results in one call to aapt2 overwriting the previous ones
results... or worse leaving garbage at the end.

So the fix in this case is to provide a different temp file for each
call to `aapt2`. These files are then combined later just in case they
contain unique information for that abi. While this does result in
duplicate lines in the `aapt_rules` file, this does not impact on the
build.
jonpryor pushed a commit that referenced this issue Dec 12, 2022
Fixes: #7447

Users are reporting a error with the aapt_rules file generated by aapt2

	MSBUILD : java.exe error JAVA0000: Error in obj\Release\110\aapt_rules.txt at line 289, column 1: [C:\Jenkins\workspace\Demo\Demo.Android\Demo.Android.csproj]
	MSBUILD : java.exe error JAVA0000: Expected char '-' at obj\Release\110\aapt_rules.txt:289:1 [C:\Jenkins\workspace\Demo\Demo.Android\Demo.Android.csproj]
	MSBUILD : java.exe error JAVA0000: nit>(...); } [C:\Jenkins\workspace\Demo\Demo.Android\Demo.Android.csproj]
	MSBUILD : java.exe error JAVA0000: Compilation failed

This only happens when building with
`$(AndroidCreatePackagePerAbi)`=True.   After looking at the code:

 1. we call `aapt2 link` multiple times when building per abi
 2. the temp file used for the `aapt2 link` proguard output was the
    same file for *all* of the `aapt2 link` calls.

The combination of (1) and (2) can result in one call to `aapt2`
overwriting the previous `aapt2` invocation results, or (worse)
leaving garbage at the end of the file.
results... or worse leaving garbage at the end.

Fix this by providing a different temp file for each call to `aapt2`.
These files are then combined later just in case they contain unique
information for that abi.  While this does result in duplicate lines
in the `aapt_rules` file, this does not impact on the build.
@ghost ghost locked as resolved and limited conversation to collaborators Jan 12, 2023
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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants