Skip to content

[Android] Use CFFIXED_USER_HOME for bundle path #2520

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 14, 2019

Conversation

Molanda
Copy link
Contributor

@Molanda Molanda commented Sep 25, 2019

For Android, the main bundle path is set to the executable directory, which is something like /system/bin/app_process32. As a result, things like localized strings do not work.

This PR allows the bundle path to be set by the CFFIXED_USER_HOME environmental variable.

In my case, I set this in the Kotlin (or Java) initialization code as follows...

Os.setenv("CFFIXED_USER_HOME", mainActivity.filesDir.path, true)

I then copy the files from the asset manager into the files directory. This includes Info.plist which configures the bundle identifier and development region, and en.lproj/Localizable.strings which contain the English strings.

Once these are in place, I can call NSLocalizedString to get the localized string.

@Molanda Molanda changed the title Use CFFIXED_USER_HOME for bundle path on Android [Android] Use CFFIXED_USER_HOME for bundle path Oct 1, 2019
@Molanda
Copy link
Contributor Author

Molanda commented Oct 21, 2019

Courtesy ping.

@parkera parkera requested review from millenomi and phausler October 25, 2019 20:05
@Molanda
Copy link
Contributor Author

Molanda commented Nov 6, 2019

Any comments on this one? It should be consistent with other areas configured for Android.

@drodriguez
Copy link
Contributor

I never seen the /system/bin/app_process32 when starting executables directly. Does that only happen when the Swift code is embedded into an apk and the code is used through JNI?

@swift-ci please test

@Molanda
Copy link
Contributor Author

Molanda commented Nov 13, 2019

Here is a good description from StackExchange:

However, for all the android apps, that's just /system/bin/app_process32 or /system/bin/app_process64 ie the same executable as the main/zygote process (itself started by init).

That process will just fork children process which will then load the java classes making up an Android app, without exec()ing any extra binary.

The command lines you see in the output of ps (/proc/PID/cmdline) are just "faked" as usual by overwriting the argv block -- see here.

This commit is written so if there is no wrapper Java/Kotlin code setting CFFIXED_USER_HOME and loading Foundation, the original code path will determine the bundle path.

@drodriguez
Copy link
Contributor

Yes, that's what I imagined, that it was the original process for zygote. I don't see anything wrong in the code, and should only affect Android. The failure in macOS seems unrelated. Let's see if it goes away.

@swift-ci please test macOS platform

@Molanda
Copy link
Contributor Author

Molanda commented Nov 14, 2019

Thank you for looking the code over and running the tests.

@drodriguez
Copy link
Contributor

I think it is good to merge. I think the problem in macOS is unrelated, or I cannot see how this change can affect SwiftPM at all.

@drodriguez drodriguez merged commit 3e57ba1 into swiftlang:master Nov 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants