Skip to content

Revisit how the Android port works. - #20912

Merged
bors-servo merged 6 commits into
servo:masterfrom
paulrouget:androidv2
Jul 31, 2018
Merged

bors-servo merged 6 commits into
servo:masterfrom
paulrouget:androidv2

Conversation

@paulrouget

@paulrouget paulrouget commented Jun 4, 2018 •

Copy link
Copy Markdown
Contributor

Fix #20855
Fix #18625
Fix #21147

Before polishing and making sure everything works fine (like the VR code, the android-x86 version, the non-android version of the lib, …), I'd like to get some early feedback on the approach.

I recommend reviewing commit by commit.

To test, just follow the regular steps:

    ./mach build -d --android
    ./mach package --dev --android builds servo.apk
    ./mach install --dev --android && ./mach run --android

  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix #__ (github issue number if applicable).
  • There are tests for these changes OR
  • These changes do not require tests because _____

This change is Reviewable

Comment thread ports/libsimpleservo/README.md Outdated
@@ -0,0 +1,3 @@
This is a basic wrapper around Servo. While libservo itself (/components/servo/) offers a lot of flexibility,
libsimpleservo (/ports/libsimpleservo/) tries to make it easier to embed Servo, without much configuration needed.
It is limited to only one view (no tabs, no multiple renering area).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/renering area/rendering areas/

@jdm jdm added the S-awaiting-review There is new code that needs to be reviewed. label Jun 4, 2018
@jdm jdm self-assigned this Jun 4, 2018

@jdm jdm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a really useful improvement :D

Comment thread ports/libsimpleservo/build.rs Outdated
use std::path::Path;

fn main() {
println!("cargo:rerun-if-changed=build.rs");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that if the build script itself (or one of its dependencies) changes, then it's rebuilt and rerun unconditionally, so cargo:rerun-if-changed=build.rs is almost always redundant (unless you want to ignore changes in all other files except for build.rs).

From https://doc.rust-lang.org/cargo/reference/build-scripts.html

Comment thread ports/libsimpleservo/src/api.rs Outdated

struct ResourceReader(Box<ReadFileTrait>);
unsafe impl Send for ResourceReader {}
unsafe impl Sync for ResourceReader {}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is scary. What if we store Box<ReadFileTrait + Send + Sync> instead?

@jdm jdm added S-needs-code-changes Changes have not yet been made that were requested by a reviewer. and removed S-awaiting-review There is new code that needs to be reviewed. labels Jun 4, 2018
@highfive highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-needs-code-changes Changes have not yet been made that were requested by a reviewer. labels Jun 18, 2018
@paulrouget

paulrouget commented Jun 19, 2018 •

Copy link
Copy Markdown
Contributor Author

Note to self:

  • make sure /ports/servo still works
  • test Android x86
  • missing support for Event::Suspended
  • test VR
  • test non-Android x86 (add example or port ports/servo to libsimpleservo (can be followup))
  • build ServoView and Surface code in a AAR file along the APK (for Crow and Klar) (can be followup)
  • remove android_injected_glue from all over and dependencies if possible not necessary anymore

@paulrouget

Copy link
Copy Markdown
Contributor Author

x86 build still works as long as EGL 3 is available.

screen shot 2018-06-19 at 08 21 48

@paulrouget

paulrouget commented Jun 19, 2018 •

Copy link
Copy Markdown
Contributor Author

WebVR build segfaults:

com.mozilla.servo A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0xc in tid 17599 (WebVRThread), pid 17357 (m.mozilla.servo)

@paulrouget

Copy link
Copy Markdown
Contributor Author

@MortimerGoro I might need your help here.

I get a crash in self.service.get_displays() (components/webvr/webvr_thread.rs) which is a rust-webvr method. I'm building with --features googlevr. It works well on master, but with this current PR it segfaults.

This PR changes how Servo runs on Android. Instead of using an empty Android app and load Servo via Glutin, we have a proper Android app that use a GLSurfaceView and load servo as a library and make some calls via JNI. I don't know what get_displays does, do you have any hint of what could go wrong? When can get_displays crash?

In the meantime, I will compile with my own version of rust-webvr see if I can find precisely where it crashes.

@jdm / @MortimerGoro also, in general, do you know how to get a rust stack trace on Android when it crashes?

@MortimerGoro

MortimerGoro commented Jun 19, 2018 •

Copy link
Copy Markdown
Contributor

@paulrouget I suspect that the crash is related to JNI calls which get the activity this way: android::get_app().activity

Could you check that android::get_app() is not null && the activity has a correct value?. If not we'll need to implement a different way to get it or expose a method in rust-webvr to set it from servo.

@MortimerGoro

MortimerGoro commented Jun 19, 2018 •

Copy link
Copy Markdown
Contributor

@paulrouget have you checked if WebGL works ok? IIRC GLSurfaceView was not a very friendly API to create shared contexts

@paulrouget

Copy link
Copy Markdown
Contributor Author

@MortimerGoro WebGL works.

@paulrouget

Copy link
Copy Markdown
Contributor Author

You were right. I'll try to figure out how to fix this.

@paulrouget

Copy link
Copy Markdown
Contributor Author

@MortimerGoro I don't use android rs glue. Should I? Does it even make sense for a library?

If I don't, what's the alternative? We could add some embedder methods to access the activity. Would that be enough?

@MortimerGoro

Copy link
Copy Markdown
Contributor

I think that the best way would be to get rid of android-rs-glue, and pass the JNI JavaVM and Activity pointers to rust-webvr (e.g. in the constructor or initialization methods).

@jdm

jdm commented Jun 19, 2018

Copy link
Copy Markdown
Member

To answer the question about stack traces, I do the following:

  • copy the logcat output that includes the crash information and unresolved symbols to a temporary file log
  • run ndk-stack -sym target/armv7-linux-androideabi/debug/apk/jniLibs/armeabi-v7a/ -dump log
    (it might be necessary to pass target/armv7-linux-androideabi/debug/apk/obj/local/armeabi-v7a/lib/ for the sym directory instead; I forget which is correct at the moment)

@jdm jdm removed the S-awaiting-review There is new code that needs to be reviewed. label Jun 19, 2018
@bors-servo

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #20421) made this pull request unmergeable. Please resolve the merge conflicts.

@highfive highfive added the S-needs-rebase There are merge conflict errors. label Jun 19, 2018
@paulrouget

Copy link
Copy Markdown
Contributor Author

@MortimerGoro,

I think that the best way would be to get rid of android-rs-glue

Entirely? Looks like it's used extensively.

@paulrouget

paulrouget commented Jun 20, 2018 •

Copy link
Copy Markdown
Contributor Author

@MortimerGoro what if I initialize the android glue manually (calling main2) by setting ANDROID_APP manually?

@paulrouget

Copy link
Copy Markdown
Contributor Author

what if I initialize the android glue manually (calling main2) by setting ANDROID_APP manually?

I tried, but struggling. My approach is, in Java, get the application via:

mApp = ((Activity) context).getApplication();
// mApp is not null

passed to Rust:

init(.., app: JObject, ..) {
    unsafe {
        android_injected_glue::ANDROID_APP = app.into_inner() as *mut android_injected_glue::ffi::android_app;
    }
    // get_app().activity crashes
}

@SimonSapin

Copy link
Copy Markdown
Member

@bors-servo r-

I’d prefer the argument escaping to be fixed before landing, but if you feel strongly this is better left to a follow-up feel free to r+ again.

@paulrouget

Copy link
Copy Markdown
Contributor Author

We are going to run into a timeout as we are waiting on a logcat message that will never arrive because the new port doesn't redirect stdout to logcat.

There are few ways to do that:

Relevant: #19999

For now, I think the best thing to do is to use alert instead of log for the test. This is already delegated to the embedder so it's a very easy fix. And file a follow-up to redirect stdout to logcat.

I'll look at this tomorrow.

@bors-servo

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #21250) made this pull request unmergeable. Please resolve the merge conflicts.

@paulrouget

paulrouget commented Jul 31, 2018 •

Copy link
Copy Markdown
Contributor Author

I managed to solve the logcat issue, but now, apparently, the servo event loop is not working in headless mode. I'm trying to figure out what's going on.

Edit: nope, issue on my side.

@paulrouget

paulrouget commented Jul 31, 2018 •

Copy link
Copy Markdown
Contributor Author

@SimonSapin addressed your comments. Using JSON now.

Can you please check the 2 last commits?

Also, I made it so that window.alert redirect the logcat, fixing the initial problem. It's not ideal, I'd like console.log to do the same thing, but we do not delegate console.log to the embedder. Not a problem for now, but we will need to fix this: #19999 (comment)

@paulrouget

Copy link
Copy Markdown
Contributor Author

@bors-servo r=jdm,mortimergoro,simonsapin

1 similar comment
@jdm

jdm commented Jul 31, 2018

Copy link
Copy Markdown
Member

@bors-servo r=jdm,mortimergoro,simonsapin

@bors-servo

Copy link
Copy Markdown
Contributor

📌 Commit a923e8b has been approved by jdm,mortimergoro,simonsapin

@jdm

jdm commented Jul 31, 2018

Copy link
Copy Markdown
Member

@bors-servo r=jdm,mortimergoro,simonsapin

@bors-servo

Copy link
Copy Markdown
Contributor

📌 Commit 6a31864 has been approved by jdm,mortimergoro,simonsapin

@bors-servo

Copy link
Copy Markdown
Contributor

⌛ Testing commit 6a31864 with merge 95b54ca...

@bors-servo

Copy link
Copy Markdown
Contributor

☀️ Test successful - android, android-x86, arm32, arm64, linux-dev, linux-rel-css, linux-rel-wpt, mac-dev-unit, mac-rel-css1, mac-rel-css2, mac-rel-wpt1, mac-rel-wpt2, mac-rel-wpt3, mac-rel-wpt4, windows-msvc-dev
Approved by: jdm,mortimergoro,simonsapin
Pushing 95b54ca to master...

@Darkspirit

Copy link
Copy Markdown
Contributor

This PR deleted occurrences of android_params.
Should apparently unused file /resources/android_params now be deleted, too?

@paulrouget

Copy link
Copy Markdown
Contributor Author

This PR deleted occurrences of android_params.
Should apparently unused file /resources/android_params now be deleted, too?

Likely. Can you file a dedicated issue for that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Update to a recent version of Gradle and to SDK 27 Implement a proper Android port android: why is the binary that large (200Mb and 600Mb)

10 participants