Android Studio exports strings from support library to APK

你说的曾经没有我的故事 提交于 2019-11-27 04:19:08

问题


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:

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.


回答1:


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:

  • Gradle samples
  • Basic sample
  • Release notes

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



来源:https://stackoverflow.com/questions/20280872/android-studio-exports-strings-from-support-library-to-apk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!