Excluding Android resources? (SOLVED)

Once again it’s me and my admob extension having problems with the build process.

I’ve updated google play services and other related libs in the extension to the current versions and Defold fails to build it because of conflicting resources.

Failed building Android resources to R.java: /var/folders/hz/pn_wgvvs5gs9t_2zkchyd0w80000gn/T/bob_bundle_tmp2404027679367473102/res/values/values.xml:70: error: Attribute "fontProviderFetchStrategy" already defined with incompatible format.
/var/folders/hz/pn_wgvvs5gs9t_2zkchyd0w80000gn/T/4101015115134236277/res/com.android.support.support-compat-27.1.1/values/values.xml:9: Original attribute defined here.
/var/folders/hz/pn_wgvvs5gs9t_2zkchyd0w80000gn/T/bob_bundle_tmp2404027679367473102/res/values/values.xml:85: error: Attribute "fontProviderFetchTimeout" already defined with incompatible format.
/var/folders/hz/pn_wgvvs5gs9t_2zkchyd0w80000gn/T/4101015115134236277/res/com.android.support.support-compat-27.1.1/values/values.xml:14: Original attribute defined here.
/var/folders/hz/pn_wgvvs5gs9t_2zkchyd0w80000gn/T/bob_bundle_tmp2404027679367473102/res/values/values.xml:95: error: Attribute "fontStyle" already defined with incompatible format.
/var/folders/hz/pn_wgvvs5gs9t_2zkchyd0w80000gn/T/4101015115134236277/res/com.android.support.support-compat-27.1.1/values/values.xml:17: Original attribute defined here.

The problem is with the support-compat library, more specifically it’s resources.
I already have

excludeJars: ["(.*)/google-play-services.jar", "(.*)/android-support-v4.jar"]

in my appmanifest, what do I need to add here to exclude support-compat jar and resources? I’ve tried excluding everything with “(.*).jar”, didn’t seem to work either.

If my understanding of bob.jar is correct, than everything inside bob.jar/lib/android-res.zip gets copied into APK without any exclude rules, am I correct?

If so, can we add excludeRes or something into the appmanifest? Or make excludeJars to also exclude these resources?

We plan to break up the Android build so that Google Play Services is in a separate extension. And move push to a native extension. This will make it easier to reason about and solve issues such as the one you’ve encountered. Until this is done I think maybe @sven and @AGulev may have some ideas?

It’s not critical at the moment, deleted by hand conflicting values.

With the release of our facebook extension, we added some new mechanics in order to make it all work. And in old tradition, our documentation hasn’t caught up yet.

Here’s an example of the ext.manifest using one of the common android keywords.

  • aaptExtraPackages - extra package name that shoukld be generated
  • aaptExcludePackages - Regexp (or exact names) of packages to exclude
  • aaptExcludeResourceDirs - Regexp (or exact names) of resource dirs to exclude

The package names bob.jar currently adds automatically:

  • com.google.android.gms
  • com.google.android.gms.common

The resource dirs that bob.jar currently adds automatically

  • res/com.android.support.support-compat-27.1.1
  • res/com.android.support.support-core-ui-27.1.1
  • res/com.android.support.support-media-compat-27.1.1
  • res/com.google.android.gms.play-services-base-16.0.1
  • res/com.google.android.gms.play-services-basement-16.0.1
  • res/com.google.firebase.firebase-messaging-17.3.4

With the last two keywords, you should be able to exclude the built in package names/resource dirs.

4 Likes

I’ve created a ticket to update the docs this week.

3 Likes

Can’t make it work, still the same error. Here is my ext.manifest
https://hastebin.com/xopokafosu.http

Anything I am doing wrong?

Hmm, I would have expected it to work.
I hope I have time to look into it today.

1 Like

I have a PR waiting for review by Mathias: https://github.com/defold/doc/pull/56

1 Like

@sergey.lerg

Here’s some example code to remove package names and resource dirs.

platforms:
    android:
        bundle:
            aaptExtraPackages: ['com.facebook', 'com.facebook.common']
            aaptExcludePackages: ['com.google.android.gms']
            aaptExcludeResourceDirs: ['.*(\/res\/com\.android\.support\.support-media-compat-27\.1\.1)']  

When I previously said “exact name” for resource dirs, it was in fact the fullpath name, which is difficult to know since it’s a temp directory.

I also created the regexp using regex101, which I think is the best interactive tool to create and debug rexexps.

4 Likes

A new day, a new error. Thanks for the explained syntax, got further now.

Now I am getting

Failed building Android resources to R.java: ERROR: In <declare-styleable> FontFamilyFont, unable to find attribute android:fontVariationSettings
ERROR: In <declare-styleable> FontFamilyFont, unable to find attribute android:ttcIndex

Two errors about attributes fontVariationSettings and ttcIndex.
But if we take a look at res/values/values.xml https://pastebin.com/yYSWU60y you can see that there are specified these attributes (line 121).

Now if I go ahead and comment out both of them I get next cryptic error:

warning: [options] bootstrap class path not set in conjunction with -source 1.6
java.lang.RuntimeException: Translation has been interrupted
	at com.android.dx.command.dexer.Main.processAllFiles(Main.java:608)
	at com.android.dx.command.dexer.Main.runMultiDex(Main.java:366)
	at com.android.dx.command.dexer.Main.run(Main.java:275)
	at com.android.dx.command.dexer.Main.main(Main.java:245)
	at com.android.dx.command.Main.main(Main.java:106)
Caused by: java.lang.InterruptedException: Too many errors
	at com.android.dx.command.dexer.Main.processAllFiles(Main.java:600)
	... 4 more

Any thoughts?

1 Like

Huh, that seems really weird.
I mean, if it does find the key, why is it complaining about it…

As for the cryptic message, I don’t really know either :confused:

I’ll have to think a little bit so see if I can figure out a reason.
UNfortunately I don’t have time to look into that until next week (beta release day today, and we’re on holiday tomorrow)

3 Likes

New information.
I was able to build by specifying app manifest from the extension (excluding jars the old way), removing

 aaptExcludePackages: ["com.google.android.gms", "com.google.android.gms.common"]

from the ext.manifest and deleting

<attr name="android:fontVariationSettings"/>
<attr name="android:ttcIndex"/>

From values.xml

So looks like it’s not working as expected. aaptExcludePackages excludes packages that I want to add in the extension, not only from the base engine.

2 Likes

Ah, yes. That would explain it.
I can take a look at the code to see if I can fix it.
We also have a ticket for moving com.google.android.gms.** to an extension, to make it even easier to reason about.

2 Likes

I am all eager for the proper dependency system, moving all google stuff away into extension is definitely the way to go.

2 Likes

New info. I’ve reorganized the res folder into several subfolders and now Defold manges to build an APK on macOS. Still errors on Windows, but with a different error, about missing Theme.IAPTheme.

I’m looking into this, not 100% sure yet but it looks like a path separator issue. :thinking:

3 Likes

We don’t have any resources in the engine itself starting Defold 1.2.162

4 Likes