How to package Dotnet.Android as an aar ?
I tried to build Dotnet.Android library as an aar using Android Studio, but without success:
The original version of Dotnet.Android built by MSBuild has the "assemblies" folder is in the top level folder of the apk , but I don't know how to achieve this effect with gradle commands.
I tried to copy assemblies to a folder and set the sourceSet attribute, but assemblies are then copied to "assets“ folder, not the "assemblies" folder, which causes the test app crashing with something as
Make sure that all entries in the APK directory named
assemblies/
are STORED (not compressed)
I also asked ChatGPT, it told me to use the libraryVariants attribute as follows (kotlin):
libraryVariants.forEach { variant ->
val packTask = variant.packageLibraryProvider
//-----------------this log didn't show, meaning the code block is not executed.
println("------------------------------------------ variant = $variant, pack = $packTask")
variant.outputs.forEach { output ->
println("------------------------------------------ outputDir = $output")
val outputDir = output.outputFile?.parentFile
if(outputDir != null){
val assembliesDir = File(outputDir, "assemblies")
if (assembliesDir.exists()) {
tasks.register<Copy>("copyAssembliesToAAR") {
from(assembliesDir)
into(outputDir)
}
}
}
}
}
But as the comment showed, it didn't work.
So I am stuck on the above problem. To make further progress, I see two possibilities:
1, modify the source from https://github.com/dotnet/android (embedded-assemblies.hh, specifically), change the default assemblies' search path to "assets/assemblies". It means I must compile a version which is not compatible with MS's.
2, since Dotnet.Android app built from Visual Studio can put assemblies to the top level folder inside the apk, Learn how it does and replicate in the gradle scripts. I am not familiar with either MBBuild or gradle (I use Visual Studio/Android Studio primarily), so this road is more difficult to me.
So I am here, asking for help! Can you provide a guide? Both solutions (or any other solution you propose) are welcome, although solution #2 is more welcome :)