My project is an application that supports In-App Language Switching. The app bundle I packaged can be installed directly through the bundletool tool to correctly display the language set by the system, and the apk directly installed can also display the language set by the system correctly, but when I download from Google When play downloads my app (app bundle uploaded by google play), my app does not display the language set by the system, but the language corresponding to my country. All installation methods can be in the app after installation Switch language normally, how should I solve this problem。
my gradle config:
android {
defaultConfig {
...
multiDexEnabled true
...
ndk {
abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
}
resConfigs "en-rUS", "zh-rCN", "zh-rTW"
}
bundle{
language{
enableSplit false
}
}
}
This problem has been solved. The reason is that the allowBackup attribute is configured as true in the Application attribute in the AndroidMainfest file. Change it to false. In the case of true, google service will back up the app configuration file, but I don’t know exactly what files to back up and how the backup is done. In addition, based on the problems I encountered in the process of using multiple languages, some tips for switching between multiple languages in the app are given.
Tip 1: For androidx.appcompat.appcompat dependency, it is best to use version 1.0.2, other versions will cause the in-app switching of multiple languages on some phones
Tip 2: bundle{
language{
enableSplit false
}
}
If you need to switch multiple languages in the app, it is recommended to change this attribute to false, only for bundle packages.
Tip 3: Remember to configure
resConfigs "ms-rMY", "zh-rCN", "zh-rTW"
Otherwise, multi-language resources may not be packaged in the apk when packaging
Finally, my build.gradle configuration file
android{
defaultConfig{
bundle{
language{
enableSplit false
}
}
resConfigs "ms-rMY", "zh-rCN", "zh-rTW"
}
}
dependencies{
implementation group: 'androidx.appcompat', name: 'appcompat', version: "1.0.2"
}
Related
Android app bundle upload failed with error
Invalid SplitApkBundle. The bundle targets unknown languages: [gr]
Android Studio version 3.5
I tried
Clean & rebuild
Invalidate cache/restart
I had the same issue.
Invalid SplitApkBundle. The bundle targets unknown languages:[cb]
I solved by setting DSL to stop aapt package building the wrong language targets.
My app supports English and Chinese, therefore resConfigs only needs en and zh.
defaultConfig {
...
resConfigs "en", "zh-rTW", "zh-rCN"
}
Apply this to Android{}
bundle {
density {
// Different APKs are generated for devices with different screen densities; true by default.
enableSplit true
}
abi {
// Different APKs are generated for devices with different CPU architectures; true by default.
enableSplit true
}
language {
// This is disabled so that the App Bundle does NOT split the APK for each language.
// We're gonna use the same APK for all languages.
enableSplit false
}
}
in my case i was because i was using facebook account kit see wells answer it helped me out , i am in lining it here for future references
bundle {
density {
// Different APKs are generated for devices with different screen densities; true by default.
enableSplit true
}
abi {
// Different APKs are generated for devices with different CPU architectures; true by default.
enableSplit true
}
language {
// This is disabled so that the App Bundle does NOT split the APK for each language.
// We're gonna use the same APK for all languages.
enableSplit false
}
}
I had the same issue after downgrading facebook login implimentation to 5.8 it's fixed
implementation 'com.facebook.android:facebook-login:5.8.0'
In my case, I was working with Localization and Translation also. It worked. no more code.
Put this code in app-level build.gradle.
android {
bundle {
language {
enableSplit = false
}
}
...
}
I'm facing the same issue, I guess it is related to some resources added for Facebook's Account Kit (specifically the values inside /res/values-cb/values-cb.xml) I've tried uploading a version without this SDK and the playstore proccessed it properly
Switching to Facebook sdk version 5.13.0 solved the problem for me.
implementation 'com.facebook.android:facebook-login:5.13.0'
Android app bundle upload failed with error
Invalid SplitApkBundle. The bundle targets unknown languages: [gr]
Android Studio version 3.5
I tried
Clean & rebuild
Invalidate cache/restart
I had the same issue.
Invalid SplitApkBundle. The bundle targets unknown languages:[cb]
I solved by setting DSL to stop aapt package building the wrong language targets.
My app supports English and Chinese, therefore resConfigs only needs en and zh.
defaultConfig {
...
resConfigs "en", "zh-rTW", "zh-rCN"
}
Apply this to Android{}
bundle {
density {
// Different APKs are generated for devices with different screen densities; true by default.
enableSplit true
}
abi {
// Different APKs are generated for devices with different CPU architectures; true by default.
enableSplit true
}
language {
// This is disabled so that the App Bundle does NOT split the APK for each language.
// We're gonna use the same APK for all languages.
enableSplit false
}
}
in my case i was because i was using facebook account kit see wells answer it helped me out , i am in lining it here for future references
bundle {
density {
// Different APKs are generated for devices with different screen densities; true by default.
enableSplit true
}
abi {
// Different APKs are generated for devices with different CPU architectures; true by default.
enableSplit true
}
language {
// This is disabled so that the App Bundle does NOT split the APK for each language.
// We're gonna use the same APK for all languages.
enableSplit false
}
}
I had the same issue after downgrading facebook login implimentation to 5.8 it's fixed
implementation 'com.facebook.android:facebook-login:5.8.0'
In my case, I was working with Localization and Translation also. It worked. no more code.
Put this code in app-level build.gradle.
android {
bundle {
language {
enableSplit = false
}
}
...
}
I'm facing the same issue, I guess it is related to some resources added for Facebook's Account Kit (specifically the values inside /res/values-cb/values-cb.xml) I've tried uploading a version without this SDK and the playstore proccessed it properly
Switching to Facebook sdk version 5.13.0 solved the problem for me.
implementation 'com.facebook.android:facebook-login:5.13.0'
How to fix the warning below? Are there any alternatives to 'auto'?
Warning:DSL element 'ProductFlavor.resConfigs' has a value 'auto' which is obsolete and has not been replaced. It will be removed at the end of 2018
android {
...
flavorDimensions "device", "paid", "market"
productFlavors {
phone {
// Phone config version for the application
resConfigs ("auto")
dimension "device"
matchingFallbacks = ['mobile']
}
...
}
...
}
This is the error after updating to Android Studio 3.1:
Based on the official advise here the best thing to do is removing the tag entirely if you support all the languages or supply an array with the language's code your app supports like:
resConfigs "en", "de", "it", "fr" // etc. etc.
More info:
This is one of the resources optimization proposed by the official documentation here so i decided to test this flag with those FirebaseUI dependencies in a sample project
implementation "com.firebaseui:firebase-ui-auth:$firebase_ui_version"
implementation "com.firebaseui:firebase-ui-database:$firebase_ui_version"
implementation "com.firebaseui:firebase-ui-storage:$firebase_ui_version"
creating the debug APK with both the options and those are the results:
Using resConfigs "auto" the debug APK was: 3,793 KB
Using resConfigs "en" (so 1 language only) the debug APK was: 3,294 KB
This means that with all the string resources for all the languages of those dependencies I got only ~500KB of size increase. That's something you could reason about, you definitely should make a test with the dependencies you use and see if the size increase is negligible or not and consequently decide to provide the list of supported languages or remove the resConfigs option.
PS: If you are using Android FirebaseUI this was one of the suggested optimizations, I've created an issue here about the thing and this has been solved immediately by the awesome guy called SUPERCILEX
auto is no longer supported because it created a number of issues with multi-module projects. Instead, you should specify the locale that your app supports. Android plugin 3.1.0 and higher ignore the auto argument, and Gradle packages all string resources your app and its dependencies provide.
com.android.tools.build:gradle:3.2.0-alpha08 BaseFlavor.java
* <p><b>Note:</b> <code>auto</code> is no longer supported because it created a number of
* issues with multi-module projects. Instead, you should specify the locale that your app
* supports, as shown in the sample above. Android plugin 3.1.0 and higher ignore the <code>auto
* </code> argument, and Gradle packages all string resources your app and its dependencies
* provide.
Dears,
I read in many blog posts that multidex apps startup is slower than normal apps.
My app uses a lot of libraries that exceed 64k methods so I use multidex. But when I use proguard in release build, the final apk becomes less than 64k methods
So My question is: Can I enable multidex in Android debug build only so I don't have runtime error? and disable multi dex in release build as I don't need it?
If yes, how ?
If No, Is Android smart enough to speedup startup as it should recognize that app didn't exceed 64k even if it is multi dex app ?
Yes, you can. When you declare your buildTypes include multidex only for debug:
buildTypes {
release {
multiDexEnabled false
}
debug {
multiDexEnabled true
}
}
Instead of enabling multidex only for debug, you can change your min sdk version to 21 only for debug so gradle can speed up dexing with ART:
android {
productFlavors {
// Define separate dev and prod product flavors.
dev {
// dev utilizes minSDKVersion = 21 to allow the Android gradle plugin
// to pre-dex each module and produce an APK that can be tested on
// Android Lollipop without time consuming dex merging processes.
minSdkVersion 21
}
prod {
// The actual minSdkVersion for the application.
minSdkVersion 14
}
}
...
buildTypes {
release {
runProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
}
dependencies {
compile 'com.android.support:multidex:1.0.0'
}
http://developer.android.com/tools/building/multidex.html
suggested methods are not needed anymore as android studio became "smart enough".
In fact, it will now give you a warning when you use minSdkVersion 21 (the old way) to speed up build time with dex:
You no longer need a dev mode to enable multi-dexing during
development, and this can break API version checks less...
In the past, our documentation recommended creating a dev product
flavor with has a minSdkVersion of 21, in order to enable multidexing
to speed up builds significantly during development. That workaround
is no longer necessary, and it has some serious downsides, such as
breaking API access checking (since the true minSdkVersion is no
longer known.) In recent versions of the IDE and the Gradle plugin,
the IDE automatically passes the API level of the connected device
used for deployment, and if that device is at least API 21, then
multidexing is automatically turned on, meaning that you get the same
speed benefits as the dev product flavor but without the downsides.
Yes, it even works with the multidex support library for Android versions prior to Lollipop with a little trick.
First specify multiDexEnabled for the debug build in build.gradle:
buildTypes {
...
debug {
...
multiDexEnabled true
}
}
Then create an AndroidManifest.xml file under src/debug.
src/debug/AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application
android:name="android.support.multidex.MultiDexApplication"
tools:replace="android:name"/>
</manifest>
That should do the trick. If your app uses a custom application class then you have to create a subclass of your application class and specify the name of that subclass in the manifest.
The application subclass should look like this:
public class MyDebugApplication extends MyApplication {
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}
Im facing this problem which seems im not able to solve. Here is scenario:
Im building apk which uses gradle dependency and this dependency is architecture specific so for apk for x86 i need different dependency and for arm different as well.
I solved it with product flavors:
productFlavors {
dev { ... }
develx86 { ... }
production { ... }
productionx86 { ... }
}
So then i defined dependency like this:
develCompile 'dependency_for_arm'
develx86Compile 'dependency_for_x86'
This works good. But recently i had to add to my application an usage of renderscript. I did it in this way:
renderscriptTargetApi 22
renderscriptSupportModeEnabled true
And after this when i uploaded apk on Google Play it says it's apk is suitable with arm, x86. I don't know how this is possible. As you can think it will crash on device with different CPU (if i generated apk for arm and user will execute it on x86 app will crash).
So i decited to use ABI splits:
splits {
abi {
enable true
reset()
include 'armeabi', 'x86'
universalApk false
}
}
//Ensures architecture specific APKs have a higher version code
//(otherwise an x86 build would end up using the arm build, which x86 devices can run)
ext.versionCodes = [armeabi:0, x86:1]
import com.android.build.OutputFile
android.applicationVariants.all { variant ->
// assign different version code for each output
variant.outputs.each { output ->
int abiVersionCode = project.ext.versionCodes.get(output.getFilter(OutputFile.ABI)) ?: 0
output.versionCodeOverride = android.defaultConfig.versionCode + abiVersionCode
}
But now when i see generated apk files, my dependency which is flavor-specific is not included into apk and apk will crash when i open section which uses API from this dependency.
Do someone know how to solve this issue? Or someone know why Google Play says that apk is for both architectures when i included renderscript? (Without it it works properly but i need renderscript).
Thank you for your time. I will appreciate any help.
If you look inside your APK, under lib folder, you should see that renderscript support mode added libs for other architectures than the one you're supporting.
You can keep your earlier configuration with ABI-specific flavors.
But in order to ensure that no libs for other architectures are included, try adding abiFilters to your flavors:
productFlavors {
dev { ... ndk.abiFilters 'armeabi-v7a' }
develx86 { ... ndk.abiFilters 'x86' }
production { ... ndk.abiFilters 'armeabi-v7a' }
productionx86 { ... ndk.abiFilters 'x86' }
}
Sorry I cannot comment inline yet.
What's in the apk, especially in res/raw/ and lib/?
Also, are you using gradle-plugin 2.1.0? (since you are using renderscriptTargetApi 22), have you tried Build-Tools 23.0.3?