Android Studio exports strings from support library to APK
Asked Answered
I

2

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.

Imperceptible answered 29/11, 2013 at 7:57 Comment(2)
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 presentJuliettejulina
@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.Imperceptible
I
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.

Imperceptible answered 12/12, 2013 at 8:8 Comment(3)
Great answer. (But these links to samples give HTTP 403 or similar errors.) resConfigs ought to be in the docs (tools.android.com/tech-docs/new-build-system/user-guide), not just mentioned in passing in the release notes.Numen
is there a method to do this in EclipseMinnow
Here's an official example: developer.android.com/studio/build/…Gird
R
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>
Recapitulate answered 19/2, 2021 at 9:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.