Skip to content

Conversation

@dellis1972
Copy link
Contributor

Fixes https://work.azdo.io/1288593

This is a weird bug which I cannot reproduce locally. However reading
the code this code path is possible.

When trying to do incremental builds when using the AndroidPackageFormat
aab we get the following error

 [BT : 1.4.0] error : Module 'base' is missing mandatory file 'manifest/AndroidManifest.xml'.

The problem is the base.zip doesn't have ANY AndroidManifest.xml in it...
But why?

Well what seems to happen is in this case the input file packaged_resources
and the output base.zip are unchanged. packaged_resources has
an AndroidManifest.xml file and base.zip has a manifest/AndroidManifest.xml
file. Because it was renamed from AndroidManifest.xml to manifest/AndroidManifest.xml
on a previous build. This is so that our base.zip confirms to the expected
folder structure for an aab. So this is by design.

However, in this case because BOTH files are up to date, we DONT add
the AndroidManifest.xml file from packaged_resources to the base.zip.
A compounding problem is because no physical file manifest/AndroidManifest.xml
exists, that file is then removed from the base.zip.
As a result the FixupArchive which does the renaming of the AndroidManifest.xml
for aab files has nothing to do. Because its source file does not exist.

So we end up with a base.zip without ANY AndroidManifest.xml file in it.

The fix in this case is to NEVER remove an AndroidManifest.xml file from
the base.zip or apk. It is a protected file and should always exist.

… project is cleaned first

Fixes https://work.azdo.io/1288593

This is a weird bug which I cannot reproduce locally. However reading
the code this code path is possible.

When trying to do incremental builds when using the `AndroidPackageFormat`
`aab` we get the following error

     [BT : 1.4.0] error : Module 'base' is missing mandatory file 'manifest/AndroidManifest.xml'.

The problem is the base.zip doesn't have ANY AndroidManifest.xml in it...
But why?

Well what seems to happen is in this case the input file `packaged_resources`
and the output `base.zip` are unchanged. `packaged_resources` has
an `AndroidManifest.xml` file and `base.zip` has a `manifest/AndroidManifest.xml`
file. Because it was renamed from `AndroidManifest.xml` to `manifest/AndroidManifest.xml`
on a previous build. This is so that our `base.zip` confirms to the expected
folder structure for an `aab`. So this is by design.

However, in this case because BOTH files are up to date, we DONT add
the `AndroidManifest.xml` file from `packaged_resources` to the `base.zip`.
A compounding problem is because no physical file `manifest/AndroidManifest.xml`
exists, that file is then removed from the `base.zip`.
As a result the `FixupArchive` which does the renaming of the `AndroidManifest.xml`
for `aab` files has nothing to do. Because its source file does not exist.

So we end up with a `base.zip` without ANY `AndroidManifest.xml` file in it.

The fix in this case is to NEVER remove an `AndroidManifest.xml` file from
the base.zip or apk. It is a protected file and should always exist.
@jonpryor
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jonpryor
Copy link
Contributor

Fixes: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1288593

This is a weird bug which I cannot reproduce locally.  However,
reading the code this code path is possible:

When trying to do incremental builds when using
`$(AndroidPackageFormat)`=aab, we get the following error:

	[BT : 1.4.0] error : Module 'base' is missing mandatory file 'manifest/AndroidManifest.xml'.

The problem is that `base.zip` doesn't have *any*
`AndroidManifest.xml` in it!  But why?

What appears to happen is:

 1. During "initial build", `packaged_resources` is created, and
    contains `AndroidManifest.xml`.  `base.zip` is created based on
    the contents of `packaged_resources`, renaming
    `AndroidManifest.xml` to `manifest/AndroidManifest.xml`, so that
    `base.zip` has the expected folder structure for `aab` files.
    (This "copy and rename" is done by `<FixupArchive/>`.)

    Both `packaged_resources` and `base.zip` have the same timestamp.

 2. On a subsequent incremental build, neither `packaged_resources`
    nor `base.zip` is changed (because they didn't need to, e.g. no
    Android Resources were added), and the `_BuildApkEmbed` target is
    executed.

 3. The `_BuildApkEmbed` target runs the `<BuildApk/>` task, which
    "cleans up removed files" within `base.zip`.  Because there is no
    corresponding file "on disk" for `manifest/AndroidManifest.xml`
    within `base.zip`, the `manifest/AndroidManifest.xml` file is
    *removed* from `base.zip`.

 4. `_BuildApkEmbed` later calls `<BuildAppBundle/>`, which calls
    `bundletool.jar`, and fails with the above error message:

        [BT : 1.4.0] error : Module 'base' is missing mandatory file 'manifest/AndroidManifest.xml'.

The fix is to update the `<BuildApk/>` task to *never remove* files
named `AndroidManifest.xml`.  It is a protected file and should
always exist.

@jonpryor jonpryor merged commit d653245 into dotnet:main Mar 23, 2021
@dellis1972 dellis1972 deleted the WorkItem_1288593 branch March 23, 2021 14:43
@github-actions github-actions bot locked and limited conversation to collaborators Jan 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants