WebView for Android Built from Chromium Source - Keyboard Doesn't Work

1,055 views
Skip to first unread message

Amit

unread,
Feb 20, 2017, 2:26:23 AM2/20/17
to Chromium-discuss

I am working on a project where I need to utilize a customized WebView. I have setup a test environment using a Android 7.0 code base. I followed the instructions (https://www.chromium.org/developers/how-tos/build-instructions-android-webview) and built a system webview APK. To make sure the WebView works fine, I tested some webpages inside an app using WebView. The web pages load fine, but I observe an issue when I have to fill web page forms (containing <input> fields) inside the WebView. When I click on an <input> field, the keyboard doesn't show up. I describe below the steps I followed to setup the test environment and some observations I have.

How test environment was setup:


I did the environment setup using instructions spread across the links:

https://www.chromium.org/developers/how-tos/build-instructions-android-webview
https://www.chromium.org/developers/how-tos/android-build-instructions
https://www.chromium.org/developers/gn-build-configuration
https://chromium.googlesource.com/chromium/src/+/master/docs/linux_build_instructions.md

Steps were as as follows:
  1. Downloaded chromium source using (download date - Feb 14): fetch --nohooks android
  2. gclient runhooks
  3. gn args out/Default (set arguments as in instructions)
  4. src/build/install-build-deps-android.sh
  5. gclient sync
  6. . build/android/envsetup.sh
  7. gn gen out/Release --args='target_os="android"'
  8. Modified out/Release/args.gn to add : target_cpu = "arm64"
  9. ninja -C out/Release system_webview_apk

The above steps generated SystemWebView.apk.

How APK was installed on Android device:


The existing app (com.android.webview) on the device was a system app, so adb uninstall didn't work. Not sure whether system app would be a necessity, I signed the new SystemWebView.apk using my AOSP source's platform key. I then followed these steps:
  1. adb root
  2. adb remount
  3. adb shell stop
  4. adb shell rm -rf /system/app/webview
  5. adb shell start
  6. adb install -r -d SystemWebView.apk
Other observations related to environment setup:
  1. For some reason, once I finish installing the new APK, the libwebviewchromium32.relro and libwebviewchromium64.relro files in /data/misc/shared_relro/ get deleted. To do the test, I had to adb push them.
  2. The native library (.so) name is different from what I expected. I checked the original webview.apk on device, and its lib folder had the library name libwebviewchromium.so, but the new APK has the name libwebviewchromium.cr.so. I'm not sure if this can cause an issue, but I do observe an inconsistency because the AndroidManifest.xml of the APK generated from chromium contains the following entry:
<meta-data android:name="com.android.webview.WebViewLibrary" android:value="libwebviewchromium.so"/>


Torne (Richard Coles)

unread,
Feb 20, 2017, 8:34:31 AM2/20/17
to amitah...@gmail.com, Chromium-discuss
On Mon, 20 Feb 2017 at 07:26 Amit <amitah...@gmail.com> wrote:

I am working on a project where I need to utilize a customized WebView. I have setup a test environment using a Android 7.0 code base. I followed the instructions (https://www.chromium.org/developers/how-tos/build-instructions-android-webview) and built a system webview APK. To make sure the WebView works fine, I tested some webpages inside an app using WebView. The web pages load fine, but I observe an issue when I have to fill web page forms (containing <input> fields) inside the WebView. When I click on an <input> field, the keyboard doesn't show up. I describe below the steps I followed to setup the test environment and some observations I have.

I don't know why you're having this problem - it's not something I've seen. But I have some general comments on your process:
 

How test environment was setup:


I did the environment setup using instructions spread across the links:

https://www.chromium.org/developers/how-tos/build-instructions-android-webview
https://www.chromium.org/developers/how-tos/android-build-instructions
https://www.chromium.org/developers/gn-build-configuration
https://chromium.googlesource.com/chromium/src/+/master/docs/linux_build_instructions.md

Steps were as as follows:
  1. Downloaded chromium source using (download date - Feb 14): fetch --nohooks android
  2. gclient runhooks
  3. gn args out/Default (set arguments as in instructions)
Setting the arguments for the out/Default directory has no effect if you don't actually use that directory to build. You need to pick just one output directory and use the same one consistently - you've mixed up your build arguments so only a few of them apply. 
  1. src/build/install-build-deps-android.sh
  2. gclient sync
  3. . build/android/envsetup.sh
  4. gn gen out/Release --args='target_os="android"'
  5. Modified out/Release/args.gn to add : target_cpu = "arm64"
You haven't actually done a release build - the name of the directory doesn't do anything by itself. The default is debug, so you've produced a debug build here. You need to set the gn arguments for the actual output directory you're using. "gn args" automatically generates the ninja files after you edit the arguments, so normally the way people do this is just run "gn args out/whatever", set the arguments, and then build. There's no need to manually run "gn gen" (the ability to set the arguments here is intended for scripts).
  1. ninja -C out/Release system_webview_apk

The above steps generated SystemWebView.apk.

How APK was installed on Android device:


The existing app (com.android.webview) on the device was a system app, so adb uninstall didn't work. Not sure whether system app would be a necessity, I signed the new SystemWebView.apk using my AOSP source's platform key.

It doesn't need to be installed in the system image as long as it's signed with the same key as the one that is. You can just install it as a normal upgrade if you sign it with the correct key. What you did will also work, though.
 
I then followed these steps:
  1. adb root
  2. adb remount
  3. adb shell stop
  4. adb shell rm -rf /system/app/webview
  5. adb shell start
  6. adb install -r -d SystemWebView.apk
Other observations related to environment setup:
  1. For some reason, once I finish installing the new APK, the libwebviewchromium32.relro and libwebviewchromium64.relro files in /data/misc/shared_relro/ get deleted. To do the test, I had to adb push them.
It's normal for these files to be deleted when a new WebView is installed; a background task will then recreate them when possible. Pushing copies of them from another place will never actually work, because the files are specific to a particular WebView binary and also to a particular boot of the device (their contents changes every time you reboot the phone), so if you restored a backup it won't really use the files. It's fine for these files to be missing, WebView will still load just fine. 
  1. The native library (.so) name is different from what I expected. I checked the original webview.apk on device, and its lib folder had the library name libwebviewchromium.so, but the new APK has the name libwebviewchromium.cr.so. I'm not sure if this can cause an issue, but I do observe an inconsistency because the AndroidManifest.xml of the APK generated from chromium contains the following entry: 
<meta-data android:name="com.android.webview.WebViewLibrary" android:value="libwebviewchromium.so"/>

Because your build was a debug build, it defaulted to doing a component build, which builds many separate .so files and packages them all into the APK, all with the extension .cr.so. This kind of build is a bit quicker to build (especially when you've changed just a few files), but runs slower and uses more memory on the device. Component builds work fine and the fact that the metadata tag refers to a different library name doesn't matter - it will fail to preload the library with RELRO sharing because this doesn't work with component builds (this is also why the .relro files don't get regenerated), but actually loading it will work fine.

For production use you want to do a release, non-component build, but for testing this should work and is not causing any problems you might be having.
 

--
--
Chromium Discussion mailing list: chromium...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-discuss

Amit

unread,
Feb 22, 2017, 9:59:02 AM2/22/17
to Chromium-discuss, amitah...@gmail.com

I tried a more recent AOSP branch (7.1) and it worked fine. I don't know why the old 7.0 didn't work.

I have another question related to the test environment. I want to ask how can gn & ninja be used to rebuild webview APK. Right now I use:

gn args out/Default
ninja -C out/Default system_webview_apk

The above  builds the SystemWebView APK. Then if I want to make a change to the source and then recompile the source, I repeat the above steps. The compilation is shorter this time, but the final APK doesn't contain my changes. How can I do a rebuild containing source code changes without having to do a clean build again ?

Thanks.

Christian Biesinger

unread,
Feb 22, 2017, 10:06:14 AM2/22/17
to amitah...@gmail.com, Chromium-discuss
Your steps should work and you don't even need the GN command the second time. Are you sure that you modified a file that's used by Android?

Christian

Torne (Richard Coles)

unread,
Feb 22, 2017, 10:08:24 AM2/22/17
to amitah...@gmail.com, Chromium-discuss
On Wed, 22 Feb 2017 at 14:59 Amit <amitah...@gmail.com> wrote:
I tried a more recent AOSP branch (7.1) and it worked fine. I don't know why the old 7.0 didn't work.

I have another question related to the test environment. I want to ask how can gn & ninja be used to rebuild webview APK. Right now I use:

gn args out/Default
ninja -C out/Default system_webview_apk

The above  builds the SystemWebView APK. Then if I want to make a change to the source and then recompile the source, I repeat the above steps. The compilation is shorter this time, but the final APK doesn't contain my changes. How can I do a rebuild containing source code changes without having to do a clean build again ?

It's not necessary to repeat setting/editing the arguments; they're persistent, and ninja will automatically regenerate the ninja files if needed before starting the build. That should work, though; you aren't doing anything wrong, and just running ninja exactly as you did for the original build will rebuild everything that is affected by files you have changed. If the final APK doesn't contain your changes, then maybe you didn't change what you thought you did? What specifically did you change, and how are you testing it after it builds?

Amit

unread,
Feb 22, 2017, 11:01:33 AM2/22/17
to Chromium-discuss, amitah...@gmail.com

I added some log statements inside chromium. At first I repeated both steps and tried running the APK. The logs didn't print. I then did a clean build, and the logs printed fine.

I will try your approach of just running ninja for a rebuild and will get back to you if it works.

Thanks.

Amit

unread,
Feb 22, 2017, 12:14:20 PM2/22/17
to Chromium-discuss, amitah...@gmail.com
I tried running just ninja and the rebuild works fine.

Thanks

Torne (Richard Coles)

unread,
Feb 22, 2017, 1:32:54 PM2/22/17
to amitah...@gmail.com, Chromium-discuss
Rerunning gn will not cause a problem (it's just unnecessary), so that shouldn't have made any difference. I suspect you did something else different without realising it..
Reply all
Reply to author
Forward
0 new messages