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

Debug symbols upload on Google Play Console for better crash information #5378

Closed
EmilAlipiev opened this issue Dec 7, 2020 · 27 comments · Fixed by #6616
Closed

Debug symbols upload on Google Play Console for better crash information #5378

EmilAlipiev opened this issue Dec 7, 2020 · 27 comments · Fixed by #6616
Assignees
Labels
Area: App+Library Build Issues when building Library projects or Application projects.

Comments

@EmilAlipiev
Copy link

EmilAlipiev commented Dec 7, 2020

When we upload an app bundle or apk, below warning is returned from google play console. Question is what kind of source symbols should we or can we upload here? I am guessing that it is it not pdb files :) Is there a way for Xamarin.forms applications for android to get symbols and better crash information?

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.

image

@EmilAlipiev EmilAlipiev added the Area: App+Library Build Issues when building Library projects or Application projects. label Dec 7, 2020
@jonathanpeppers jonathanpeppers self-assigned this Dec 8, 2020
@jonathanpeppers jonathanpeppers added this to the Under Consideration milestone Dec 8, 2020
@jonathanpeppers
Copy link
Member

This was solved for obfuscated Java/Kotlin code here:

#5304

It doesn't look like we have solved this for native code, which would include AOT'd .NET assemblies.

@tbrentlong
Copy link

I'm seeing the same issue when uploading a bundle build via VS2019. Is there a file somewhere that can be uploaded? I also still get the deobfuscation message noted in 5186 even though I'm not using a code shrinker.

@jonathanpeppers
Copy link
Member

@tbrentlong as mentioned in #5304, I think you would need to use AndroidLinkMode=r8 to get the mapping.txt file.

Can you share a screenshot of the warning you get?

@Eversor
Copy link

Eversor commented Apr 19, 2021

I'm getting the same issue here, i cannot find the mapping.txt in the bin/Release folder, and i don't know where to change the cfg file either.
image
image

Microsoft Visual Studio Community 2019
Version 16.7.6
VisualStudio.16.Release/16.7.6+30611.23
Microsoft .NET Framework
Version 4.8.04084

Xamarin 16.7.000.456 (d16-7-6@f8d55b6)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin.Android SDK 11.0.2.0 (d16-7/025fde9)
Xamarin.Android Reference Assemblies and MSBuild support.
Mono: 83105ba
Java.Interop: xamarin/java.interop/d16-7@1f3388a
ProGuard: Guardsquare/proguard@ebe9000
SQLite: xamarin/sqlite@1a3276b
Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-7@017078f

@dellis1972
Copy link
Contributor

VS 2019 16.7.x does not include the fix from #5304 since it was released before the fix was merged.
You will need to be on 16.9.x.
Also PR #5318 made it an "opt-in" feature. Which means you need to set the following in
your release config in the csproj in order to activate it.

<AndroidProguardMappingFile>$(OutputPath)mapping.txt</AndroidProguardMappingFile>

@Eversor
Copy link

Eversor commented Apr 19, 2021

Thank you for the information, will try to update and post my findings... Do i need to activate Proguard code shrinking for the mappings to be outputted?

@dellis1972
Copy link
Contributor

The AndroidProguardMappingFile only works with r8 / d8. It should output the mapping if those are set.

@plaili
Copy link

plaili commented Jun 8, 2021

It doesn't look like we have solved this for native code, which would include AOT'd .NET assemblies.

Is this issue with no debug symbols for native code tracked anywhere? Or will it be tracked here?

@EmilAlipiev
Copy link
Author

@plaili #5342
#5304
#5318

Those are better. it actually already works like @dellis1972 suggested. I can see the file is generated.

@plaili
Copy link

plaili commented Jul 27, 2021

#5342
#5304
#5318

Those are better. it actually already works like @dellis1972 suggested. I can see the file is generated.

The mapping.txt is fine, it's generated here, too, but for native code there is still something missing as far as I understand it. At least I still see the warning.

@EmilAlipiev
Copy link
Author

@dellis1972 @jonathanpeppers <AndroidProguardMappingFile>$(OutputPath)mapping.txt</AndroidProguardMappingFile>

this works fine in my local build. I can see the mapping.txt but in Azure Devops Pipelines, I am not seeing it it is generated. Is there any difference?

@cjsharp01
Copy link

Hi, it doesn't seem to be working for me. Settings: bundle, d8 Dex, r8 code shrinker (VS 16.11.5 & Xamarin.Android 11.4.0.5).

If I put "-keepattributes SourceFile,LineNumberTable -printmapping mapping.txt" in the proguard config file and I get the following error when I build the app:

Error in obj\Release\110\androidx\proguard\mapping.txt at line 7, column 1:
Expected char '-' at obj\Release\110\androidx\proguard\mapping.txt:7:1
android.runtime.JavaProxyThrowable -> android.runtime.JavaProxyThrowable:
^
Compilation failed
MSB6006: "java.exe" exited with code 1.

If I have put $(OutputPath)mapping.txt in the Android Project Properties then I get the mapping.txt file outputted but when I try Archiving the project (after a successful build) I get the following error:

C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Xamarin\Android\Xamarin.Android.D8.targets(51,5): error MSB6006: "java.exe" exited with code 1.

Am I missing something or is it still an issue? Thanks

@lauxjpn
Copy link
Contributor

lauxjpn commented Jan 5, 2022

There are a couple of issues in regards to the AndroidProguardMappingFile property.

1. The AndroidProguardMappingFile docs are incorrect in regards to the default value:

The default value is $(OutputPath)mapping.txt.

There is no default value. If the property is not explicitly set, no mapping file will be created.

2. The AndroidProguardMappingFile docs are misleading in regards to the value of $(OutputPath)mapping.txt:

This value is not going to work as is. Unless you explicitly set the OutputPath property in your project file, it will not yet exist when you set the AndroidProguardMappingFile property. This then results in the mapping.txt file being output in the current project root directory instead.

To fix this issue, I use the following:

<AndroidLinkTool>r8</AndroidLinkTool>
<AndroidProguardMappingFile>mapping.txt</AndroidProguardMappingFile>

<Target Name="FixAndroidProguardMappingFilePath" BeforeTargets="_CompileToDalvik">
    <PropertyGroup>
        <AndroidProguardMappingFile Condition="'$(AndroidProguardMappingFile)' != ''">$(OutputPath)$(AndroidProguardMappingFile)</AndroidProguardMappingFile>
    </PropertyGroup>
</Target>

@jonathanpeppers
Copy link
Member

@lauxjpn you should be able to use $(OutputPath) if you set your property after this line:

<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
<PropertyGroup>
  <AndroidProguardMappingFile>$(OutputPath)mapping.txt</AndroidProguardMappingFile>
</PropertyGroup>

It seems like we should maybe set $(AndroidProguardMappingFile) by default -- so you don't have to do this at all?

@lauxjpn
Copy link
Contributor

lauxjpn commented Jan 5, 2022

@jonathanpeppers Ah, you're right that should work!

I think it makes sense to have $(OutputPath)mapping.txt as the default.

In case the mapping file generation is a performance hit, it might also make sense to introduce a simple flag property that when true would set the $(OutputPath)mapping.txt default. This flag property could then be set to true by default for either release or publish builds, and would otherwise be false.

@plaili
Copy link

plaili commented Jan 6, 2022

I am trying to include the mapping.txt in my aab bundle:
<PropertyGroup> <AndroidProguardMappingFile>$(OutputPath)mapping.txt</AndroidProguardMappingFile> <AndroidBundleToolExtraArgs>--metadata-file=com.android.tools.obfuscation/mapping.txt:$(OutputPath)mapping.txt"</AndroidBundleToolExtraArgs> </PropertyGroup>
Unfortunately this does not include the mapping in the BUNDLE-METADATA folder of the aab. Has anyone got this to work?

@dellis1972
Copy link
Contributor

dellis1972 commented Jan 6, 2022

@plaili ok looks like our Task which is responsible for calling the build-bundle command on bundletool does not support additional arguments. It seems that the --metadata-file argument has been added recently.

The AndroidBundleToolExtraArgs is only used when we call build-apks. So we are going to need to add this feature.
I'll take a. look, we will probably add a AndroidBundleMetaDataFile ItemGroup which might look like

<ItemGroup>
<AndroidBundleMetaDataFile Include="com.android.tools.obfuscation/mapping.txt:$(OutputPath)mapping.txt" />
</ItemGroup>

I'll talk this over with @jonathanpeppers and see if we can come up with an easy way to handle this.

@dellis1972
Copy link
Contributor

For reference

jar -jar bundletool.jar help build-bundle
Description:
    Builds an Android App Bundle from a set of Bundle modules provided as zip
    files.

    Note that the resource table, the AndroidManifest.xml and the resources must
    already have been compiled with aapt2 in the proto format.

Synopsis:
    bundletool build-bundle 
        --modules=<path/to/module1.zip,path/to/module2.zip,...>
        --output=<bundle.aab>
        [--config=<BundleConfig.pb.json>]
        [--metadata-file=<com.some.namespace/file-name:path/to/file>]
        [--overwrite]

Flags:
    --modules: The list of module files to build the final Android App Bundle
        from.

    --output: Path to the where the Android App Bundle should be built.

    --config: (Optional) Path to a JSON file that describes the configuration of
        the App Bundle. This configuration will be merged with BundleTool
        defaults.

    --metadata-file: (Optional) Specifies a file that will be included as
        metadata in the Android App Bundle. The format of the flag value is
        '<bundle-path>:<physical-file>' where 'bundle-path' denotes the file
        location inside the App Bundle's metadata directory, and 'physical-file'
        is an existing file containing the raw data to be stored. The flag can
        be repeated.

    --overwrite: (Optional) If set, any previous existing output will be
        overwritten.

@jonathanpeppers
Copy link
Member

It seems like we could define these two by default if AndroidLinkTool=r8:

<!-- PropertyGroup -->
<AndroidProguardMappingFile>$(OutputPath)mapping.txt</AndroidProguardMappingFile>
<!-- ItemGroup-->
<AndroidAppBundleMetaDataFile Include="$(AndroidProguardMappingFile)" />

dellis1972 added a commit to dellis1972/xamarin-android that referenced this issue Jan 6, 2022
Context dotnet#5378

Provide a default value for `AndroidProguardMappingFile` when using
`AndroidLinkTool=r8`.

Add support for providing meta-data files to `bundletool` when building
the app bundle. This allows developers to provide additional meta-data
such as the proguard mapping file. The new ItemGroup is called
`AndroidAppBundleMetaDataFile`.
@dellis1972
Copy link
Contributor

@plaili where did you find the value for the com.android.tools.obfuscation meta-data item?
I can't find any mention of it in the docs and I just tested am aab and google still complains about the mapping.txt file being missing.

@dellis1972
Copy link
Contributor

Never mind, I found it should be BUNDLE-METADATA/com.android.tools.build.obfuscation/proguard.map by looking at an existing Java based app.

@plaili
Copy link

plaili commented Jan 7, 2022

I am always confused about proguard.map vs. mapping.txt, but as you write they seem to be the same thing and must just be named accordingly in different situations.

dellis1972 added a commit to dellis1972/xamarin-android that referenced this issue Jan 11, 2022
Context dotnet#5378

Provide a default value for `AndroidProguardMappingFile` when using
`AndroidLinkTool=r8`.

Add support for providing meta-data files to `bundletool` when building
the app bundle. This allows developers to provide additional meta-data
such as the proguard mapping file. The new ItemGroup is called
`AndroidAppBundleMetaDataFile`.
dellis1972 added a commit to dellis1972/xamarin-android that referenced this issue Jan 13, 2022
Context dotnet#5378

Provide a default value for `AndroidProguardMappingFile` when using
`AndroidLinkTool=r8`.

Add support for providing meta-data files to `bundletool` when building
the app bundle. This allows developers to provide additional meta-data
such as the proguard mapping file. The new ItemGroup is called
`AndroidAppBundleMetaDataFile`.
dellis1972 added a commit to dellis1972/xamarin-android that referenced this issue Jan 17, 2022
Context dotnet#5378

Add a new property `AndroidCreateProguardMappingFile` to control the
creation of the proguard mapping file.
This will default to `False` because it does has some impact on the final
apk sizes.

Also Provide a default value for `AndroidProguardMappingFile` when using
`AndroidLinkTool=r8` and `AndroidCreateProguardMappingFile=True`.

Add support for providing meta-data files to `bundletool` when building
the app bundle. This allows developers to provide additional meta-data
such as the proguard mapping file. The new ItemGroup is called
`AndroidAppBundleMetaDataFile`.
dellis1972 added a commit to dellis1972/xamarin-android that referenced this issue Jan 17, 2022
Context dotnet#5378

Add a new property `AndroidCreateProguardMappingFile` to control the
creation of the proguard mapping file.
This will default to `False` because it does has some impact on the final
apk sizes.

Also Provide a default value for `AndroidProguardMappingFile` when using
`AndroidLinkTool=r8` and `AndroidCreateProguardMappingFile=True`.

Add support for providing meta-data files to `bundletool` when building
the app bundle. This allows developers to provide additional meta-data
such as the proguard mapping file. The new ItemGroup is called
`AndroidAppBundleMetaDataFile`.
dellis1972 added a commit to dellis1972/xamarin-android that referenced this issue Jan 19, 2022
Context dotnet#5378

Add a new property `AndroidCreateProguardMappingFile` to control the
creation of the proguard mapping file.
This will default to `False` because it does has some impact on the final
apk sizes.

Also Provide a default value for `AndroidProguardMappingFile` when using
`AndroidLinkTool=r8` and `AndroidCreateProguardMappingFile=True`.

Add support for providing meta-data files to `bundletool` when building
the app bundle. This allows developers to provide additional meta-data
such as the proguard mapping file. The new ItemGroup is called
`AndroidAppBundleMetaDataFile`.
dellis1972 added a commit to dellis1972/xamarin-android that referenced this issue Jan 19, 2022
Context dotnet#5378

Add a new property `AndroidCreateProguardMappingFile` to control the
creation of the proguard mapping file.
This will default to `False` because it does has some impact on the final
apk sizes.

Also Provide a default value for `AndroidProguardMappingFile` when using
`AndroidLinkTool=r8` and `AndroidCreateProguardMappingFile=True`.

Add support for providing meta-data files to `bundletool` when building
the app bundle. This allows developers to provide additional meta-data
such as the proguard mapping file. The new ItemGroup is called
`AndroidAppBundleMetaDataFile`.
@lauxjpn
Copy link
Contributor

lauxjpn commented Jan 20, 2022

For APK builds, the mapping.txt file is currently not copied to the PublishDir when executing dotnet publish.
I therefore run the following target as a fix:

<!-- Copy mapping.txt file to publish directory. -->
<Target Name="PublishAndroidProguardMappingFile"
        AfterTargets="_CalculateAndroidFilesToPublish"
        BeforeTargets="CopyFilesToPublishDirectory"
        Inputs="$(AndroidProguardMappingFile)"
        Outputs="$(PublishDir)$([System.IO.Path]::GetFileName('$(AndroidProguardMappingFile)'))"
        Condition="'$(AndroidProguardMappingFile)' != '' And
                   Exists('$(AndroidProguardMappingFile)') And
                   ($(AndroidPackageFormats.Contains('apk')) Or '$(AndroidPackageFormat)' == 'apk')">
    <ItemGroup>
        <ResolvedFileToPublish Include="$(AndroidProguardMappingFile)"
                               RelativePath="$([System.IO.Path]::GetFileName('$(AndroidProguardMappingFile)'))" />
    </ItemGroup>
</Target>

@jonathanpeppers
Copy link
Member

@lauxjpn can you send a PR for the dotnet publish issue? We don't really have a spec on what it's supposed to do -- we took a guess and copied the .aab and .apk files.

Seems like you could add that mapping.txt file to @(_AndroidFilesToPublish) here:

https://github.com/xamarin/xamarin-android/blob/f93d3d810279e7fad87063043fcc2c38b5c25bee/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.Publish.targets#L22-L30

@dellis1972
Copy link
Contributor

dellis1972 commented Jan 20, 2022

I'm including a fix for the dotnet publish issue iin #6616. For aab files we will embed it in to the aab but for apk we shall just copy the file over.

https://github.com/xamarin/xamarin-android/pull/6616/files#diff-72a69a14e7fbd5d8f65dce108bf7a0eca31fbbffaea6332ee4232ca020298b3dR27

@lauxjpn
Copy link
Contributor

lauxjpn commented Jan 20, 2022

@dellis1972 It might be worth copying the file to the publish directory independent of the used package format, because services like Microsoft AppCenter might depend on it for diagnostics.

According to Android Deobfuscation: Uploading the mapping.txt file, this should indeed be the case:

App Center Portal

  1. Download the mapping.txt file from your app module's build directory
  2. Log into App Center and select your app
  3. In the left menu, navigate to the Diagnostics section
  4. Select Mappings
  5. Click the Upload mappings button in the upper right
  6. Fill in the Version Name and Version Code (these must match that build's Gradle configuration in order for the mapping to work for a particular build)
  7. Upload the mapping.txt file from your app module's build directory.
  8. Click the Save button.

However, for my Android apps in AppCenter, I only see the subsections Issues and Symbols (the latter one referring to Symbolicating Unmanaged Code Crashes, so not to mapping.txt files) under the Diagnostics main section.

Maybe someone from the AppCenter team can clarify this.

dellis1972 added a commit to dellis1972/xamarin-android that referenced this issue Jan 21, 2022
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

@lauxjpn this code https://github.com/xamarin/xamarin-android/pull/6616/files#diff-72a69a14e7fbd5d8f65dce108bf7a0eca31fbbffaea6332ee4232ca020298b3dR27 will always make sure that the mapping.txt file ends up in the publish folder. It will also be auto included in the .aab as well.

jonpryor pushed a commit that referenced this issue Jan 24, 2022
…6616)

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`][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 does not support it.  However, the file will be
copied to `$(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
@ghost ghost locked as resolved and limited conversation to collaborators Jun 3, 2022
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.

8 participants