I have checked that on 2 devices and 1 emu, I can't change the language of my app anymore using localization. even when I do that manually, even when I go back using git to commits where it was tested and working good. The implementation is good, it was working for months but it is not working for debug and release version. It just picked the main language which is English.
I can still change the language from android studio and preview this before running the app, but when I run the app on any device I can't change it anymore.
What I have tried?
- running the app on multiple devices
- go back to previous commits where it was tested (it was working good, but now not working anymore)
- checking the implementation and trying to change that and give that hardcoded values
- checking gradle (I am not good with gradle, I think here is the problem)
until now I didn't figure out where is the problem. Can u please tell me what all the reasons that could involved localization in android? I have been working for about a week but I give up, I have to ask now.
- here is gradle code (I have undo the changes about lintOptions and still doesn't work)
plugins {
id 'com.android.application'
}
android {
compileSdk 32
defaultConfig {
applicationId "com.company.app"
minSdk 21
targetSdk 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildToolsVersion '33.0.0'
buildFeatures {
viewBinding true
}
flavorDimensions 'default'
productFlavors {
free {
dimension 'default'
applicationIdSuffix 'free'
}
paid {
dimension 'default'
applicationIdSuffix 'paid'
}
}
sourceSets{
free{
res{
srcDir 'src/free/res'
}
java{
srcDir 'src/free/java'
}
}
paid{
res{
srcDir 'src/paid/res'
}
java{
srcDir 'src/paid/java'
}
}
}
useLibrary 'org.apache.http.legacy'
packagingOptions {
resources {
excludes = ['META-INF/DEPENDENCIES', 'META-INF/NOTICE', 'META-INF/LICENSE', 'META-INF/LICENSE.txt', 'META-INF/NOTICE.txt']
}
}
namespace 'com.company.app'
}
dependencies {
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
def room_version = "2.4.2"
def lifecycle_version = "2.6.0-alpha01"
//room
implementation "androidx.room:room-runtime:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version"
// ViewModel
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
// viewModelProvider
implementation "androidx.fragment:fragment-ktx:1.5.2"
// LiveData
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"
implementation "androidx.lifecycle:lifecycle-service:$lifecycle_version"
// Annotation processor
annotationProcessor "androidx.lifecycle:lifecycle-compiler:$lifecycle_version"
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
// google sign in
implementation 'com.google.android.gms:play-services-auth:20.3.0'
// google drive
implementation 'com.google.api-client:google-api-client:2.0.0'
implementation 'com.google.auth:google-auth-library-oauth2-http:1.3.0'
implementation ('com.google.apis:google-api-services-drive:v3-rev20220815-2.0.0')
}
- Java Code
Locale languageToSwitch = new Locale("nl");
Locale.setDefault(languageToSwitch);
Resources res = getBaseContext().getResources();
DisplayMetrics dm = Resources.getSystem().getDisplayMetrics();
Configuration config = res.getConfiguration();
config.locale = languageToSwitch;
res.updateConfiguration(config, dm);
recreate();
CodePudding user response:
I tried to invalidate the caches but it didn't work, It is solved after removing the project and android Studio and then cloned it again from github.
If u know why that happens tell me please.