23

Recently i switched from Eclipse to Android Studio. I have a project with multiple module dependencies. One dependency is the support library appcompat, included like this:

dependencies {
    compile "com.android.support:appcompat-v7:19+"
}

In the Android docs i found out that this library needs to be imported with resources, which seem to work OK. I use the library in my project without problems.

The problem is, when i build an APK and run aapt, the outpus says:

locales: '--_--' 'de' 'nl' 'pl' 'sl' 'fr' 'cs' 'es' 'it' 'ca' 'da' 'fa' 'ja' 'nb' 'af' 
'bg' 'th' 'fi' 'hi' 'vi' 'sk' 'uk' 'el' 'tl' 'am' 'in' 'ko' 'ro' 'ar' 'hr' 'sr' 'tr' 
'lt' 'pt' 'hu' 'ru' 'zu' 'lv' 'sv' 'iw' 'sw' 'fr_CA' 'lo_LA' 'en_GB' 'et_EE' 'ka_GE' 
'km_KH' 'zh_HK' 'hy_AM' 'zh_CN' 'en_IN' 'mn_MN' 'es_US' 'pt_PT' 'zh_TW' 'ms_MY'

But this is not true, my app supports only the first 8 listed languages. When i upload this apk to Play, it's showing me the changes to the previous version(build with eclipse), and it says that i have added 47 languages, but again, this is not true. Screenshot from Play devconsole: Screenshot from Play devconsole

I found this similar issue on Google code, but there is no response, i wish to solve this because i have to upload my new APK to Play.

Any idea how to get rid of these 47 other languages, while the library must stay imported with resources, to work properly?

UPDATE: On Google code they say that this is expected for now and they were looking to add a way to select what you want to include in the apk.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Primoz990
  • 1,716
  • 2
  • 20
  • 34
  • why it is problematic for you really? if your main code does not support certain language, framework will fall back to default strings, which still using translated strings for the library if they are present – Marcin Orlowski Jan 09 '14 at 11:15
  • 3
    @Marcin: The only problem is that the Play Store thinks that my app supports these all languages. I know that the app will work normally with fallback to the default strings. – Primoz990 Jan 09 '14 at 12:10

2 Answers2

26

At code.google.com they say that the gradle plugin has a option to restrict resources, since version 0.7.0 is released.

Note at version 0.7.0 Release notes:

New option on product Flavor (and defaultConfig) allow filtering of resources through the -c option of aapt

  • You can pass single value (resConfig) or multiple values (resConfigs) through the DSL.
  • All values from the default config and flavors get combined and passed to aapt.
  • See "basic" sample.

Here is some sample code to put in the build.gradle file of your project:

android {
    defaultConfig {
        resConfigs "en", "de", "es" //Define languages that your app supports.
    }
}

I spent a lot of time to find the "Basic sample"...could be a link in the release notes :/ so there are the links:

NOTE: Version 0.7.x requires Android Studio 0.4.+ and Gradle 1.9.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Primoz990
  • 1,716
  • 2
  • 20
  • 34
  • 2
    Great answer. (But these links to samples give HTTP 403 or similar errors.) `resConfigs` ought to be in the docs (http://tools.android.com/tech-docs/new-build-system/user-guide), not just mentioned in passing in the release notes. – Jerry101 Dec 12 '14 at 23:08
  • is there a method to do this in Eclipse – pt123 Apr 29 '15 at 03:30
  • 3
    Here's an official example: https://developer.android.com/studio/build/shrink-code.html#unused-alt-resources – Sam Nov 20 '16 at 02:41
0

Xamarin.Android solution may help someone facing this problem. Problem occurs also if you use Google Play Services. Add the following to Android project .csproj with supported app languages

<PropertyGroup>
     <AndroidUseAapt2>true</AndroidUseAapt2>
     <AndroidAapt2LinkExtraArgs>-c de,el,es,fr,it</AndroidAapt2LinkExtraArgs>
</PropertyGroup>
backspace83
  • 342
  • 4
  • 10