Skip to content

[Xamarin.Android.Build.Tasks] Add Support for bundletool meta-data #6616

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

Merged
merged 1 commit into from
Jan 24, 2022

Conversation

dellis1972
Copy link
Contributor

@dellis1972 dellis1972 commented Jan 6, 2022

Fixes: #5378

Context: 2dab2bc

When uploading an .apk or .aab file which contains native
libraries such as AOT'd .NET assemblies to the Google Play store,
the Google Play Console reports the following warning:

This App Bundle contains native code, and you've not uploaded
debug symbols. We recommend that you upload a symbol file to make
your crashes and ANRs easier to analyse and debug.

Commit 2dab2bc addresses a similar warning regarding obfuscated
Java/Kotlin code.

Improve support for this scenario by adding a new
$(AndroidCreateProguardMappingFile) MSBuild property which controls
the creation of the ProGuard mapping file.

When True (the default when r8 is used), a ProGuard mapping file will
be created and added to .apk/.aab build outputs. This increases
the size of resulting applications by ~1% for our unit tests, and
will remove the above warning for Google Play Store submissions.

To make $(AndroidCreateProguardMappingFile)=True work, add
support for a new @(AndroidAppBundleMetaDataFile) item group.
%(AndroidAppBundleMetaDataFile.Include) values are those used by
the bundletool build-bundle --metadata-file option:

--metadata-file=target-bundle-path:local-file-path

  • target-bundle-path specifies a path relative to the root of
    the app bundle where you would like the metadata file to be
    packaged, and
  • local-file-path specifies the path to the local metadata file
    itself.

When $(AndroidCreateProguardMappingFile)=True, we automatically add:

<AndroidAppBundleMetaDataFile Include="com.android.tools.build.obfuscation/proguard.map:$(AndroidProguardMappingFile" />

which causes the ProGuard mapping file to be included into the bundle.
This only applies to .aab package formats.

For .apk files the ProGuard mapping file will not be included in the
.apk, as it doesn't not support it. However the file will be copied
to the $(OutputPath) along with the .apk. It can be manually uploaded
to the Google Play Store from there.

@dellis1972 dellis1972 marked this pull request as ready for review January 10, 2022 12:27
@jonpryor
Copy link
Contributor

Shouldn't we enable this by default for .NET 6+ apps?

@dellis1972
Copy link
Contributor Author

Shouldn't we enable this by default for .NET 6+ apps?

Enabling this causes the apk to get bigger (which is why the apkdiff desc files were updated in the first place). Is this something we want?

@dellis1972 dellis1972 force-pushed the bundletoolmeta branch 2 times, most recently from 0137410 to 66cabca Compare January 17, 2022 10:11
@dellis1972
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@dellis1972
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jonpryor
Copy link
Contributor

The RemoveEventHandlerResolution failures are fixed by 599fffd.

@jonpryor
Copy link
Contributor

Context: https://discord.com/channels/732297728826277939/732297837953679412/933674595557466172

Enabling $(AndroidCreateProguardMappingFile)=True by default increases .apk size by ~1%. We felt this was acceptable.

@dellis1972: That said, where is that 1% coming from? I figured there'd be a mapping.txt entry somewhere in the .apk, but the updated .apkdesc files in this PR don't show the presence of a mapping.txt. Where is the mapping.txt information kept?

@jonpryor
Copy link
Contributor

Fixes: https://github.com/xamarin/xamarin-android/issues/5378

Context: 2dab2bc3725a3ca3d56c6767c60f0eecf6426f46

When uploading an `.apk` or `.aab` file which contains native
libraries such as AOT'd .NET assemblies to the Google Play store,
the Google Play Console reports the following warning:

> This App Bundle contains native code, and you've not uploaded
> debug symbols.  We recommend that you upload a symbol file to make
> your crashes and ANRs easier to analyse and debug.

Commit 2dab2bc3 addresses a similar warning regarding obfuscated
Java/Kotlin code.

Improve support for this scenario by adding a new
`$(AndroidCreateProguardMappingFile)` MSBuild property which controls
the creation of the ProGuard mapping file.

When True (the default when r8 is used), a ProGuard mapping file will
be created and added to `.apk`/`.aab` build outputs.  This increases
the size of resulting applications by ~1% for our unit tests, and
will remove the above warning for Google Play Store submissions.

To make `$(AndroidCreateProguardMappingFile)`=True *work*, add
support for a new `@(AndroidAppBundleMetaDataFile)` item group.
`%(AndroidAppBundleMetaDataFile.Include)` values are those used by
the [`bundletool build-bundle --metadata-file`][0] option:

> `--metadata-file=target-bundle-path:local-file-path`
> 
>   * `target-bundle-path` specifies a path relative to the root of
>      the app bundle where you would like the metadata file to be
>      packaged, and
>   * `local-file-path` specifies the path to the local metadata file
>     itself.

When `$(AndroidCreateProguardMappingFile)`=True, we automatically add:

	<AndroidAppBundleMetaDataFile Include="com.android.tools.build.obfuscation/proguard.map:$(AndroidProguardMappingFile" />

which causes the ProGuard mapping file to be included into the bundle.

[0]: https://developer.android.com/studio/build/building-cmdline#bundletool-build

Fixes: dotnet#5378

Context: 2dab2bc

When uploading an `.apk` or `.aab` file which contains native
libraries such as AOT'd .NET assemblies to the Google Play store,
the Google Play Console reports the following warning:

> This App Bundle contains native code, and you've not uploaded
> debug symbols.  We recommend that you upload a symbol file to make
> your crashes and ANRs easier to analyse and debug.

Commit 2dab2bc addresses a similar warning regarding obfuscated
Java/Kotlin code.

Improve support for this scenario by adding a new
`$(AndroidCreateProguardMappingFile)` MSBuild property which controls
the creation of the ProGuard mapping file.

When True (the default when r8 is used), a ProGuard mapping file will
be created and added to `.apk`/`.aab` build outputs.  This increases
the size of resulting applications by ~1% for our unit tests, and
will remove the above warning for Google Play Store submissions.

To make `$(AndroidCreateProguardMappingFile)`=True *work*, add
support for a new `@(AndroidAppBundleMetaDataFile)` item group.
`%(AndroidAppBundleMetaDataFile.Include)` values are those used by
the [`bundletool build-bundle --metadata-file`][0] option:

> `--metadata-file=target-bundle-path:local-file-path`
>
>   * `target-bundle-path` specifies a path relative to the root of
>      the app bundle where you would like the metadata file to be
>      packaged, and
>   * `local-file-path` specifies the path to the local metadata file
>     itself.

When `$(AndroidCreateProguardMappingFile)`=True, we automatically add:

	<AndroidAppBundleMetaDataFile Include="com.android.tools.build.obfuscation/proguard.map:$(AndroidProguardMappingFile" />

which causes the ProGuard mapping file to be included into the bundle.
This only applies to `.aab` package formats.

For `.apk` files the ProGuard mapping file will not be included in the
`.apk`,  as it doesn't not support it. However the file will be copied
to the  `$(OutputPath)` along with the `.apk`. It can be manually uploaded
to the Google Play Store from there.

[0]: https://developer.android.com/studio/build/building-cmdline#bundletool-build
@dellis1972
Copy link
Contributor Author

@jonpryor I made a few additions to your commit message and updated my commit to use it.

@dellis1972
Copy link
Contributor Author

Test failure seems unrelated error ANDZA0000: Unable to open 'obj/Debug/android/bin/com.xamarin.checkmonocomponentsmask.apk' as zip archive

@jonpryor jonpryor merged commit 2994604 into dotnet:main Jan 24, 2022
@dellis1972 dellis1972 deleted the bundletoolmeta branch January 24, 2022 20:25
@github-actions github-actions bot locked and limited conversation to collaborators Jan 24, 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.

Debug symbols upload on Google Play Console for better crash information
3 participants