Xamarin-android: [AAPT2] Merge local and dependencies Resources conflicting

Created on 20 Sep 2018  路  8Comments  路  Source: xamarin/xamarin-android

Steps to Reproduce

  1. Create a new Android project
  2. Enable aapt2
  3. Install any NuGet package that depends on Xamarin.GooglePlayServices.Basement
  4. Configure google-services.json with build action of GoogleServicesJson
  5. Have any Resource on app (layout, string, animation), but lets add an empty anim/simple_animation.xml <set></set>
  6. Add the following lines on MainActivity.OnCreate:
            var animation = Resource.Animation.simple_animation;
            var gcm = Resource.String.gcm_defaultSenderId;

A.1 - Clean the project and Rebuild
A.2 - Resource.String.gcm_defaultSenderId exist but Resource.Animation.simple_animation doesn't.

B.1 - Edit anim/simple_animation.xml (add an empty line at the end or any other valid change) and Save
B.2 - Resource.String.gcm_defaultSenderId is missing but now Resource.Animation.simple_animation exists.

C.1 - Install Xamarin.Firebase.Analytics
C.2 - Repeat step on B
C.3 - Delete the Resource.String.gcm_defaultSenderId so you can build
C.4 - Run the app
C.5 - Initialization issue with Didn't find class "com.google.android.gms.R$string" on path: DexPathList[[zip file "/data/app/com.testing.TestAapt2-OenTlsPjUVvkgdqQhDSGUw==/base.apk"],nativeLibraryDirectories=[/data/app/com.testing.TestAapt2-OenTlsPjUVvkgdqQhDSGUw==/lib/arm64, /system/fake-libs64, /data/app/com.testing.TestAapt2-OenTlsPjUVvkgdqQhDSGUw==/base.apk!/lib/arm64-v8a, /system/lib64, /system/vendor/lib64]]

D.1 - Additional: Try the same as C with the Facebook login button.

Test project:
conflict_test_aapt2.zip

Expected Behavior

Both Resource.String.gcm_defaultSenderId and Resource.Animation.simple_animation should exist.

Actual Behavior

XOR Resource.String.gcm_defaultSenderId, Resource.Animation.simple_animation

Additional Information

This issue don't seem to be exclusive to GooglePlayServices or AAPT2.

Not exclusive to GooglePlayServices: I've experienced a similar problem with Xamarin.Facebook.Android and a custom binding for https://github.com/MiguelCatalan/MaterialSearchView

Not exclusive to AAPT2, but on the extreme on AAPT2 - I can't tell if the issue is the same, but for more context: When using the old aapt we get get random runtime issues after a AXML file change about missing resources on GooglePlayServices, Facebook login button and MaterialSearchView.

When using aapt issues A and B would never happen, but issue C is totally random after editing a AXML file.

When enabling aapt2 issues A, B and C are constants.

On our main project we have Multidex enabled. The Test Project provided before don't need it to trigger the problem.

When using aapt or aapt2 I've noticed that the obj folder is recreated 2 or 3 times after I delete it - my clean strategy involves closing VS4M, killing mono_sgen64, aapt and java. Then delete obj and bin folders.

Issue C for GooglePlayServices is reported here https://github.com/xamarin/GooglePlayServicesComponents/issues/69

Version Information

=== Visual Studio Community 2017 for Mac ===

Version 7.6.6 (build 17)
Installation UUID: 9a5b91cf-e5ce-4027-8e14-daa7b5b84c3a
Runtime:
Mono 5.12.0.301 (2018-02/4fe3280bba1) (64-bit)
GTK+ 2.24.23 (Raleigh theme)
Xamarin.Mac 4.4.1.178 (master / eeaeb7e6)

Package version: 512000301

=== NuGet ===

Version: 4.3.1.4445

=== .NET Core ===

Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
2.1.2
2.1.1
2.0.5
2.0.0
1.1.2
1.0.5
SDK: /usr/local/share/dotnet/sdk/2.1.302/Sdks
SDK Versions:
2.1.302
2.1.301
2.1.4
2.0.2
2.0.0
1.0.4
MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/5.12.0/lib/mono/msbuild/15.0/bin/Sdks

=== Xamarin.Profiler ===

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

=== Apple Developer Tools ===

Xcode 10.0 (14320.25)
Build 10A255

=== Xamarin.Mac ===

Version: 4.6.0.14 (Visual Studio Community)
Hash: 1a6e2786
Branch:
Build date: 2018-08-28 00:12:06-0400

=== Xamarin.iOS ===

Version: 12.0.0.15 (Visual Studio Community)
Hash: 84552a46
Branch: xcode10
Build date: 2018-09-17 21:54:33-0400

=== Xamarin.Android ===

Version: 9.0.0.20 (Visual Studio Community)
Android SDK: /Users/flash/Library/Developer/Xamarin/android-sdk-macosx
Supported Android versions:
4.0.3 (API level 15)
4.1 (API level 16)
4.4 (API level 19)
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: 28.0.1
SDK Build Tools Version: 28.0.2

Java SDK: /Users/flash/Library/Developer/Xamarin/jdk/microsoft_dist_openjdk_1.8.0.9
openjdk version "1.8.0-9"
OpenJDK Runtime Environment (build 1.8.0-9-microsoft-b00)
OpenJDK 64-Bit Server VM (build 25.71-b00, mixed mode)

Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Xamarin Inspector ===

Version: 1.4.3
Hash: db27525
Branch: 1.4-release
Build date: Mon, 09 Jul 2018 21:20:18 GMT
Client compatibility: 1

=== Build Information ===

Release ID: 706060017
Git revision: 822323b5f6295b271d4c9bfaca4129f90ec41f38
Build date: 2018-09-18 20:19:40+00
Build branch: release-7.6-xcode10
Xamarin extensions: a83eb4b7ad9174ac2e705f2c4257ecd15688ba97

=== Operating System ===

Mac OS X 10.13.6
Darwin 17.7.0 Darwin Kernel Version 17.7.0
Thu Jun 21 22:53:14 PDT 2018
root:xnu-4570.71.2~1/RELEASE_X86_64 x86_64

=== Enabled user installed extensions ===

Internet of Things (IoT) development (Preview) 7.5

Log File

R.txt files: One for when the local resources win and the other for when the external dependencies win.
rtxtFiles.zip

App+Library Build Under Investigation bug

All 8 comments

@dellis1972 his examples above seem like good test cases.

It sounds like there are a few ways that $(AndroidUseAapt2) is breaking w/ incremental builds?

The problem here is on the first build the compiled.flata archive only contains

Archive:  compiled.flata
 Length   Method    Size  Cmpr    Date    Time   CRC-32   Name
--------  ------  ------- ---- ---------- ----- --------  ----
     400  Stored      400   0% 01-01-1980 01:00 8ade13a7  values_goog_svcs_json.arsc.flat
--------          -------  ---                            -------
     400              400   0%                            1 file

which suggests that something is overwriting the compiled.flata archive created by _CompileResources.

Investigating further.

Found the problem. The _CompileAndroidLibraryResources target is processing the directory for the GooglePlayServicesJson items. And as a result its creating a compiled.flata archive in the same place as the main Resource directory compiled.flata archive is located. As a result the _CompileResources never runs.

Well it might do on a secondary build. or if a Resource item is updated.

Thanks for the quick resolution of this issue =).

Any idea when this change will hit beta or alpha channels? I'd like to test it. If not in a short future I'll try to build it myself.

@Flash3001 Looks like this was cherry-picked to d15-9, so it should be in the next preview. Not sure when that will be shipping but it shouldn't be too long.

is this issue in vs16 ? It seems still not fixed. Can not use aapt2 until it's fixed.

@softlion can you open a new issue with the error message (and diagnostic build logs) of what you are seeing on 2019?

The fix for this issue was in VS 2017 15.9, so I think you could be seeing something new.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

glintpursuit picture glintpursuit  路  4Comments

mathiasnielsen picture mathiasnielsen  路  4Comments

EmilAlipiev picture EmilAlipiev  路  3Comments

jonpryor picture jonpryor  路  4Comments

EDMIStephen picture EDMIStephen  路  4Comments