dotnet / android

.NET for Android provides open-source bindings of the Android SDK for use with .NET managed languages such as C#
MIT License
1.93k stars 528 forks source link

Android 11: queries in Manifest prevent app from building, if package name has "-" or "_" #5004

Open inikityuk opened 4 years ago

inikityuk commented 4 years ago

Steps to Reproduce

  1. Add "queries" tag into AndroidManifest.xml

  2. Add two packages into "queries" tag with "-"(hyphen) and "_"(underscore)

    <queries> <package android:name="com.company.namewith-hyphen" /> <package android:name="com.company.namewith_undescore" /> </queries>

  3. Build

This is Xamarin Android template app with updated AndroidManifest.xml file to replicate issue (just build) Android11QueryIssue.zip

Expected Behavior

According to https://developer.android.com/studio/build/application-id "_"(underscore) is valid symbol, so expectation is ability to build the app without any problems.

"-"(hyphen) is not recommended, but still valid if you going to create packageID for new project, also historically it wasn't enforced, so some apps have it as well.

Actual Behavior

Build fail and complain about package name

Version Information

=== Visual Studio Community 2019 for Mac ===

Version 8.7.1 (build 15) Installation UUID: 69445bf9-eca9-46ce-a7b7-d8dc63705483 GTK+ 2.24.23 (Raleigh theme) Xamarin.Mac 6.18.0.23 (d16-6 / 088c73638)

Package version: 612000090

=== Mono Framework MDK ===

Runtime: Mono 6.12.0.90 (2020-02/d3daacdaa80) (64-bit) Package version: 612000090

=== Roslyn (Language Service) ===

3.7.0-6.20371.12+917b9dfae12e3b6cb266a3c062fb20a1e9d5fb06

=== NuGet ===

Version: 5.7.0.6702

=== .NET Core SDK ===

SDK: /usr/local/share/dotnet/sdk/3.1.302/Sdks SDK Version: 3.1.302 MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/6.12.0/lib/mono/msbuild/Current/bin/Sdks

=== .NET Core Runtime ===

Runtime: /usr/local/share/dotnet/dotnet Runtime Versions: 3.1.6 2.1.20

=== Xamarin.Profiler ===

Version: 1.6.15.68 Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Updater ===

Version: 11

=== Apple Developer Tools ===

Xcode 11.6 (16141) Build 11E708

=== Xamarin.Mac ===

Xamarin.Mac not installed. Can't find /Library/Frameworks/Xamarin.Mac.framework/Versions/Current/Version.

=== Xamarin.Android ===

Version: 11.0.0.3 (Visual Studio Community) Commit: xamarin-android/d16-7/aca845b Android SDK: /Users/inikityuk/Library/Developer/Xamarin/android-sdk-macosx Supported Android versions: 5.0 (API level 21) 5.1 (API level 22) 6.0 (API level 23) 7.0 (API level 24) 7.1 (API level 25) 8.0 (API level 26) 8.1 (API level 27)

SDK Tools Version: 26.1.1 SDK Platform Tools Version: 30.0.4 SDK Build Tools Version: 29.0.3

Build Information: Mono: 83105ba Java.Interop: xamarin/java.interop/d16-7@1f3388a ProGuard: Guardsquare/proguard/proguard6.2.2@ebe9000 SQLite: xamarin/sqlite/3.32.1@1a3276b Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-7@017078f

=== Microsoft OpenJDK for Mobile ===

Java SDK: /Users/inikityuk/Library/Developer/Xamarin/jdk/microsoft_dist_openjdk_1.8.0.25 1.8.0-25 Android Designer EPL code available here: https://github.com/xamarin/AndroidDesigner.EPL

=== Android SDK Manager ===

Version: 16.7.0.13 Hash: 8380518 Branch: remotes/origin/dev/jmt/d16-7readconfig~2 Build date: 2020-07-23 22:38:02 UTC

=== Android Device Manager ===

Version: 16.7.0.18 Hash: 4b44bc1 Branch: remotes/origin/d16-7 Build date: 2020-07-23 22:38:26 UTC

=== Xamarin Designer ===

Version: 16.7.0.492 Hash: f5afe667d Branch: remotes/origin/d16-7-vsmac Build date: 2020-07-10 18:42:54 UTC

=== Xamarin.iOS ===

Version: 13.20.2.2 (Visual Studio Community) Hash: 817b6f72a Branch: d16-7 Build date: 2020-07-18 18:45:00-0400

=== Build Information ===

Release ID: 807010015 Git revision: b2b8f289ffca8f28c585e9137d193c92462cbf14 Build date: 2020-08-07 10:38:31-04 Build branch: release-8.7 Xamarin extensions: b2b8f289ffca8f28c585e9137d193c92462cbf14

=== Operating System ===

Mac OS X 10.15.6 Darwin 19.6.0 Darwin Kernel Version 19.6.0 Sun Jul 5 00:43:10 PDT 2020 root:xnu-6153.141.1~9/RELEASE_X86_64 x86_64

Log File

Android11QueriesIssue_Build.log

moljac commented 4 years ago

@inikityuk Thanks for your time and reporting this.

dellis1972 commented 4 years ago

The error about the hyphen is being raised by aapt2 itself (the underscore is fine). If this is a bug it will be upstream in the google tooling, in aapt2 itself.

The documentation states that packageNames must be

All characters must be alphanumeric or an underscore [a-zA-Z0-9_].

So that does not include a hyphen. So while it might have been valid in the past it seems that it is no longer valid now.

For reference the code path this is hitting ends up in this method https://android.googlesource.com/platform/frameworks/base.git/+/master/tools/aapt2/link/ManifestFixer.cpp#96

When ends up calling https://android.googlesource.com/platform/frameworks/base.git/+/master/tools/aapt2/text/Unicode.cpp#80

You can see the unit tests they run here https://android.googlesource.com/platform/frameworks/base.git/+/master/tools/aapt2/text/Unicode_test.cpp#44. These do not include a hyphen as part of the valid set of characters.

This isn't something we can fix or work around as aapt2 is core to how app resources are processed for android.

My recommendation would be to raise a bug with google.

jonathanpeppers commented 4 years ago

One further point is that we automatically emit queries if targetSdkVersion >= 30:

https://github.com/xamarin/xamarin-android/blob/e61ff790ca524ac173be3965fbbad510d8303b43/src/Xamarin.Android.Build.Tasks/Utilities/ManifestDocument.cs#L828-L837

So if you have a packageName with a hyphen you would hit this, I guess?

I think we remove this code in #4762, though.

jonathanpeppers commented 4 years ago

Nevermind, this doesn't put the app's packageName here, just the shared runtimes.

inikityuk commented 4 years ago

The error about the hyphen is being raised by aapt2 itself (the underscore is fine). If this is a bug it will be upstream in the google tooling, in aapt2 itself.

The documentation states that packageNames must be

All characters must be alphanumeric or an underscore [a-zA-Z0-9_].

So that does not include a hyphen. So while it might have been valid in the past it seems that it is no longer valid now.

For reference the code path this is hitting ends up in this method https://android.googlesource.com/platform/frameworks/base.git/+/master/tools/aapt2/link/ManifestFixer.cpp#96

When ends up calling https://android.googlesource.com/platform/frameworks/base.git/+/master/tools/aapt2/text/Unicode.cpp#80

You can see the unit tests they run here https://android.googlesource.com/platform/frameworks/base.git/+/master/tools/aapt2/text/Unicode_test.cpp#44. These do not include a hyphen as part of the valid set of characters.

This isn't something we can fix or work around as aapt2 is core to how app resources are processed for android.

My recommendation would be to raise a bug with google.

Thank you for your time guys.

@dellis1972 If issue was raised with "aapt2" itself, could you post a link here? that we can track progress. Did you raise issue with "_"(underscore) internally with Google or I will have to do it?