I'm trying to localize an app that uses Native C++. Most of the codes written in C++ and all strings/text was in certain build flag. E.g LANG_JP // For japanese
I've created an on-demand dynamic module to my project namely "module_jp". The difference between the base module and dynamic module would be that in module_jp's build.gradle it will has an extra cpp flag.
**module_jp's build.gradle**
plugins {
id 'com.android.dynamic-feature'
}
android {
...
defaultConfig {
...
externalNativeBuild {
cmake {
cppFlags "-fno-rtti -DLUTF8 -DLANG_JP" // Added extra flag here LANG_JP
}
}
}
In addition to this, I also created separate CMakeLists.txt to create new library namely (libnative-activity-jp.so)
**module_jp's CMakeLists.txt**
...
add_library( # Sets the name of the library.
native-activity-jp
# Sets the library as a shared library.
SHARED
...
...
target_include_directories(
native-activity-jp PRIVATE
${PLAYCORE_LOCATION}/include
)
...
target_link_libraries( # Specifies the target library.
native-activity-jp
...
My app starts by asking the user what language it prefers. After that on main Activity, it will load what library the user prefers. For example, if the user prefer JP, it will call System.LoadLibrary("native-activity-jp"); If English, it will just load the base library. System.LoadLibrary("native-activity");
// LanguageSelectionActivity
// This function open the native activity to start the normal process
private void StartMainActivity(String LanguageCode) {
if (LanguageCode.equals("en")) System.loadLibrary("native-activity");
else System.loadLibrary("native-activity-" + szLanguageCode);
// Initialize intent to start the normal activity
Intent intent = new Intent(getApplicationContext(), NativeActivity.class);
startActivity(intent);
finish();
}
The Problem All seems fine when testing locally. When user select jp, it will just show the exact app with translated JP text taken from C++ source files. However when uploaded in Google's Closed Testing(Alpha) and Internal App Sharing, logs shows that module_jp was indeed installed and it is loading "libnative-activity-jp.so" but it still showing EN translation which tells me that "libnative-activity.so" was loaded first.
I've tried to investigate the issue by
- First I've checked the list of splitcompat installed at the device by running adb backup command and extracted the backup. I confirmed that libnative-activity-jp.so was indeed extracted correctly and was saved in the device directory (data/data//splitcompat/##/native-libraries)
- I also used that same "libnative-activity-jp.so" and tested it locally and it shows the JP translation
- I also changed the module delivery type from "On-Demand" to "Install-Time" and it works perfectly when testing in Closed Testing(Alpha) and Internal App Sharing.
Questions
- Does the base native library always loaded first even if System.LoadLibrary("native-activity") wasn't called?
- Why does it works completely correct when setting that module to install-time but not on-demand?