Thanks to visit codestin.com
Credit goes to github.com

Skip to content

.NET Android Release Build( AAB) does not honor AndroidBundleConfigurationFile #10097

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

Open
cgrant78 opened this issue May 1, 2025 · 9 comments
Assignees
Labels
Area: App+Library Build Issues when building Library projects or Application projects. need-attention A xamarin-android contributor needs to review

Comments

@cgrant78
Copy link

cgrant78 commented May 1, 2025

Android framework version

net8.0-android

Affected platform version

VS 2022

Description

When setting the .NET MSBuild property 'AndroidBundleConfigurationFile' to a custom BundConfig.json file, the build process does not use the custom file. Inspection of the build log shows the bundletool using a temp file ( assuming some default build generated file) for the --config options instead of the file specified via the AndroidBundleConfigurationFile property.
Initially I thought this issue was caused by Uno SDK build configuration, but I create a simple .NET MAUI app using the default template and the behavior is the same. The side-effect of this is that the app binaries are not getting extracted. I've seen a few Issues that claim to have this resolved, but I don't see how. Using the system loader to load the shared object will always work, using any other means, ex fopen etc will fail.

Steps to Reproduce

MauiApp1.zip

Extract the attached zip file content, build and deploy the Android Release configuration to an emulator or device. Observe the Deploy target does not use the custom BundleConfig.json.

Did you find any workaround?

No.

Relevant log output

Skipping target "_ManifestMerger" because all output files are up-to-date with respect to the input files.
Skipping target "_ConvertCustomView" because all output files are up-to-date with respect to the input files.
Skipping target "_AddStaticResources" because all output files are up-to-date with respect to the input files.
Skipping target "_GeneratePackageManagerJava" because all output files are up-to-date with respect to the input files.
Skipping target "_GenerateAndroidAssetsDir" because all output files are up-to-date with respect to the input files.
Touching "E:\dev\camtastik\Camtastik\_build\Camtastik\Release\net8.0-android\android\bin\packaged_resources".
Skipping target "_CompileJava" because all output files are up-to-date with respect to the input files.
Skipping target "_CompileNativeAssemblySources" because all output files are up-to-date with respect to the input files.
Skipping target "_CreateApplicationSharedLibraries" because all output files are up-to-date with respect to the input files.
Skipping target "_CompileToDalvik" because all output files are up-to-date with respect to the input files.
C:\Program Files (x86)\Android\openjdk\jdk-17.0.12\bin\java.exe -Xmx1G -jar "C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\34.0.147\tools\bundletool.jar" build-bundle --modules E:\dev\camtastik\Camtastik\_build\Camtastik\Release\net8.0-android\android\bin\base.zip --output E:\dev\camtastik\Camtastik\_build\Camtastik\Release\net8.0-android\android\bin\com.atlasmultimedia.Camtastik.aab --config C:\Users\cgrant1\AppData\Local\Temp\tmpCE12.tmp --metadata-file=com.android.tools.build.obfuscation/proguard.map:E:\dev\camtastik\Camtastik\_build\Release\net8.0-android\mapping.txt
@cgrant78 cgrant78 added Area: App+Library Build Issues when building Library projects or Application projects. needs-triage Issues that need to be assigned. labels May 1, 2025
@jonathanpeppers
Copy link
Member

The code merges the file you pass in with some required settings:

<BuildAppBundle
Condition=" '$(AndroidPackageFormat)' == 'aab' "
ToolPath="$(JavaToolPath)"
JavaMaximumHeapSize="$(JavaMaximumHeapSize)"
JavaOptions="$(JavaOptions)"
JarPath="$(AndroidBundleToolJarPath)"
BaseZip="$(_BaseZipIntermediate)"
Modules="@(AndroidAppBundleModules)"
Output="$(_AppBundleIntermediate)"
UncompressedFileExtensions="$(AndroidStoreUncompressedFileExtensions)"
CustomBuildConfigFile="$(AndroidBundleConfigurationFile)"
MetaDataFiles="@(AndroidAppBundleMetaDataFile)"
IntermediateOutputPath="$(IntermediateOutputPath)"
AssemblyIdentityMapFile="$(_AndroidLibrayProjectAssemblyMapFile)"
/>

JsonNode json = JsonNode.Parse ("{}")!;
if (!string.IsNullOrEmpty (CustomBuildConfigFile) && File.Exists (CustomBuildConfigFile)) {
using Stream fs = File.OpenRead (CustomBuildConfigFile);
using JsonDocument doc = JsonDocument.Parse (fs, new JsonDocumentOptions { AllowTrailingCommas = true });
json = doc.RootElement.ToNode ();
}
var jsonAddition = new {
compression = new {
uncompressedGlob = uncompressed,
}
};
var jsonAdditionDoc = JsonSerializer.SerializeToNode (jsonAddition);
var mergedJson = json.Merge (jsonAdditionDoc);
var output = mergedJson.ToJsonString (new JsonSerializerOptions { WriteIndented = true });

Can you share a .binlog of this not working? https://aka.ms/binlog

There is a test checking it generally works:

app.SetProperty ("AndroidBundleConfigurationFile", "buildConfig.config");

Assert.AreEqual (app_config.ignore_split_configs, true, $"App config should indicate that split configs must be ignored");

@jonathanpeppers jonathanpeppers added need-info Issues that need more information from the author. and removed needs-triage Issues that need to be assigned. labels May 1, 2025
@jonathanpeppers jonathanpeppers added this to the Under Consideration milestone May 1, 2025
@cgrant78
Copy link
Author

cgrant78 commented May 1, 2025

Hi @@cgrant78. 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.

Good to know that the fine contents is being merged in with some defaults. My assumption is base on the fact that with the attached BundleConfig.json , I am still not seeing my shared libraries getting extracted to where they should be.

I've attached a binlog ( the last timestamped one in the output directory) as well as the BuildConfig.json used.

CentralNode_devenv_PID=4144_x64_BuildManager_Default.zip

BundleConfig.json

@dotnet-policy-service dotnet-policy-service bot added need-attention A xamarin-android contributor needs to review and removed need-info Issues that need more information from the author. labels May 1, 2025
@jonathanpeppers
Copy link
Member

jonathanpeppers commented May 1, 2025

I am still not seeing my shared libraries getting extracted to where they should be.

Are you trying to control the behavior of android:extractNativeLibs="true"?

I'm not sure if that actually is possible or not. I thought that bundletool forces extractNativeLibs="false", as a way to improve on-disk size.

If you make some other option in your BundleConfig.json, is that working? Like this one, for example:

// Disable split by ABI
const string BuildConfig = @"{
""compression"": { },
""optimizations"": {
""splitsConfig"": {
""splitDimension"": [
{
""value"": ""ABI"",
""negate"": true
}
],
}
}
}";

@jonathanpeppers
Copy link
Member

CentralNode_devenv_PID=4144_x64_BuildManager_Default.zip

This .binlog doesn't contain the <BuildAppBundle/> task running. Can you record one at the command-line? dotnet build -c Release -bl

@cgrant78
Copy link
Author

cgrant78 commented May 1, 2025

Are you trying to control the behavior of android:extractNativeLibs="true"?

That is correct.

I'm not sure if that actually is possible or not. I thought that bundletool forces extractNativeLibs="false", as a way to improve on-disk size.

So therein lies my confusion, as I've seen using a custom bundle configuration file propose at the solution to this problem is a few issues for this repro.

Making changes to the bundle configuration file doesn't reflect, as I set it not to split along ABI, and I still see the split.

Working on getting you a valid binlog

@cgrant78
Copy link
Author

cgrant78 commented May 1, 2025

Disregards that last binlog as, it was from a more complex app and not the one I initially attached. Here is the binlog for the attached app, building just the net8.0-android framework.

msbuild.zip

@jonathanpeppers
Copy link
Member

jonathanpeppers commented May 5, 2025

The .binlog prints the log message:

BundleConfig.json: {
  "optimizations": {
    "splits_config": {
      "split_dimension": [
        {
          "value": "ABI",
          "negate": false
        }
      ]
    },
    "uncompress_native_libraries": {
      "enabled": false
    }
  },
  "compression": {
    "uncompressedGlob": [
      "typemap.mj",
      "typemap.jm",
      "assemblies/**",
      "**/*.3g2",
      "**/*.3gp",
      "**/*.3gpp",
      "**/*.3gpp2",
      "**/*.aac",
      "**/*.amr",
      "**/*.awb",
      "**/*.gif",
      "**/*.imy",
      "**/*.jet",
      "**/*.jpeg",
      "**/*.jpg",
      "**/*.m4a",
      "**/*.m4v",
      "**/*.mid",
      "**/*.midi",
      "**/*.mkv",
      "**/*.mp2",
      "**/*.mp3",
      "**/*.mp4",
      "**/*.mpeg",
      "**/*.mpg",
      "**/*.ogg",
      "**/*.png",
      "**/*.rtttl",
      "**/*.smf",
      "**/*.wav",
      "**/*.webm",
      "**/*.wma",
      "**/*.wmv",
      "**/*.xmf",
      "**/*.blob"
    ]
  }
}

This looks to be a merged combination of .NET for Android's defaults, and your input file:

{
  "optimizations": {
    "splits_config": {
      "split_dimension": [{
        "value": "ABI",
        "negate": false
      }]
    },
	"uncompress_native_libraries": {
	  "enabled": false
	}
  }
}

If you are asking about bundletool behavior, do we need to file an issue here instead?

@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 May 5, 2025
@cgrant78
Copy link
Author

cgrant78 commented May 5, 2025

That would seem to be direction based on your finding. Thanks for looking into the issue.

@dotnet-policy-service dotnet-policy-service bot added need-attention A xamarin-android contributor needs to review and removed need-info Issues that need more information from the author. labels May 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: App+Library Build Issues when building Library projects or Application projects. need-attention A xamarin-android contributor needs to review
Projects
None yet
Development

No branches or pull requests

2 participants