Bug 1548635 - Some tweaks for wrench on Android. r=gw
authorKartikaya Gupta <kgupta@mozilla.com>
Thu, 02 May 2019 20:49:07 +0000
changeset 531175 579ea06d0627df7728013d3aede49cfac61c82cd
parent 531174 f32132e0db0fecbb41989bb97630c1ed4c6bbbfd
child 531176 83e1c60d2283bb0141b0d26412db6b0b6b36b48c
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgw
bugs1548635
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1548635 - Some tweaks for wrench on Android. r=gw This makes some minor tweaks: - Use a /sdcard/wrench/ folder for the args and reftests. For me bundling the reftests as assets didn't work (app would panic trying to load those files). Plus it seems better to not always bundle the reftests with the app. - Always dump a full backtrace on Android - Build both x86 and armv7 architectures of wrench into the same APK for better compatibility. - Update documentation. Differential Revision: https://phabricator.services.mozilla.com/D29728
gfx/wr/wrench/Cargo.toml
gfx/wr/wrench/android.txt
gfx/wr/wrench/src/main.rs
--- a/gfx/wr/wrench/Cargo.toml
+++ b/gfx/wr/wrench/Cargo.toml
@@ -44,21 +44,20 @@ mozangle = {version = "0.1.5", features 
 
 [target.'cfg(all(unix, not(target_os = "android")))'.dependencies]
 font-loader = "0.7"
 
 # Configuration information used when building wrench as an APK.
 [package.metadata.android]
 package_name = "org.mozilla.wrench"
 label = "Wrench"
-assets = "reftests"
 android_version = 28
 target_sdk_version = 18
 min_sdk_version = 18
 fullscreen = true
-build_targets = [ "armv7-linux-androideabi" ]
+build_targets = [ "armv7-linux-androideabi", "i686-linux-android" ]
 opengles_version_major = 3
 opengles_version_minor = 0
 [package.metadata.android.application_attributes]
 "android:hardwareAccelerated" = "true"
 [package.metadata.android.activity_attributes]
 "android:screenOrientation" = "unspecified"
 "android:uiOptions" = "none"
--- a/gfx/wr/wrench/android.txt
+++ b/gfx/wr/wrench/android.txt
@@ -1,51 +1,58 @@
 Running Wrench on Android devices.
 ==================================
 
 Setting up the environment:
 ---------------------------
 
 Follow the steps at https://github.com/tomaka/android-rs-glue#setting-up-your-environment, with exceptions:
-    - Instead of downloading the NDK and SDK, reference the ones downloaded by Gecko in ~/.mozbuild/
+    - No need to download the Android NDK and SDK, we will use the ones downloaded by Gecko in ~/.mozbuild/
 
-    - Don't install cargo-apk (currently published version has a bug related to SDK versions, hopefully 0.4.2+ will be published soon).
-      Instead, build it from source:
-        git clone https://github.com/tomaka/android-rs-glue
-        cd android-rs-glue/cargo-apk
-        cargo build
+    - Install both the i686-linux-android and armv7-linux-androideabi rust
+      targets, as the APK will include native libraries with both architectures.
+
+    - Don't install currently published version of cargo-apk (it has a bug related to SDK versions).
+      Instead, install the patched version like so:
+        cargo install --git https://github.com/staktrace/android-rs-glue --branch mozilla_master cargo-apk
 
     - Consider adding ~/.mozbuild/android-sdk-linux/platform-tools to your path, for the adb commands below.
 
 Compiling and running:
 ----------------------
 
     Compile wrench:
         cd wrench
-        <cargo-apk dir>/target/cargo-apk build
+        export ANDROID_HOME=$HOME/.mozbuild/android-sdk-linux # exact path may vary
+        export NDK_HOME=$HOME/.mozbuild/android-ndk-r17b      # exact path may vary
+        export CARGO_APK_GRADLE_COMMAND=$PWD/../../../gradlew
+        cargo-apk build
 
     Install the APK:
         adb install -r ../target/android-artifacts/app/build/outputs/apk/app-debug.apk
 
     Set command line arguments:
         adb shell
-        echo "load reftests/aa/rounded-rects.yaml" >/sdcard/wrench_args
+        mkdir /sdcard/wrench
+        echo "load reftests/aa/rounded-rects.yaml" >/sdcard/wrench/args
         exit
 
+    Push reftests (if you need these files for what you're doing):
+        adb push reftests /sdcard/wrench/
+
     Run the application:
         adb shell am start -n org.mozilla.wrench/rust.wrench.MainActivity
             (or click the icon in the launcher)
 
 Release mode:
 -------------
 
-    Building in release does work, but you need to sign and align the APK manually. We will automate this in future. For now,
-
-    Generate a signing key (once):
-        keytool -genkey -v -keystore wrench-release-key.keystore -alias wrench_key -keyalg RSA -keysize 2048 -validity 10000
+    Building in release does work as well. Use the following steps to compile wrench:
+        cd wrench
+        export ANDROID_HOME=$HOME/.mozbuild/android-sdk-linux # exact path may vary
+        export NDK_HOME=$HOME/.mozbuild/android-ndk           # exact path may vary
+        export CARGO_APK_GRADLE_COMMAND=$PWD/../../../gradlew
+        cargo-apk build --release
+        ../../../mobile/android/debug_sign_tool.py ../target/android-artifacts/app/build/outputs/apk/app-release-unsigned.apk
 
-    Sign the APK:
-        jarsigner -verbose -keystore wrench-release-key.keystore <apk path>/app-release-unsigned.apk wrench_key
-
-    Align the APK:
-        zipalign -f -v 4 <apk path>/app-release-unsigned.apk <apk path>/app-release.apk
-
-    Now the signed APK can be installed - you will probably need to uninstall the debug APK if you have that installed first.
+    Now the APK at ../target/android-artifacts/app/build/outputs/apk/app-release-unsigned.apk
+    should be signed and installable (you may need to uninstall the debug APK first if you
+    have that installed).
--- a/gfx/wr/wrench/src/main.rs
+++ b/gfx/wr/wrench/src/main.rs
@@ -373,17 +373,21 @@ fn rawtest(mut wrench: Wrench, window: &
 
 fn reftest<'a>(
     mut wrench: Wrench,
     window: &mut WindowWrapper,
     subargs: &clap::ArgMatches<'a>,
     rx: Receiver<NotifierEvent>
 ) -> usize {
     let dim = window.get_inner_size();
-    let base_manifest = Path::new("reftests/reftest.list");
+    let base_manifest = if cfg!(target_os = "android") {
+        Path::new("/sdcard/wrench/reftests/reftest.list")
+    } else {
+        Path::new("reftests/reftest.list")
+    };
     let specific_reftest = subargs.value_of("REFTEST").map(|x| Path::new(x));
     let mut reftest_options = ReftestOptions::default();
     if let Some(allow_max_diff) = subargs.value_of("fuzz_tolerance") {
         reftest_options.allow_max_difference = allow_max_diff.parse().unwrap_or(1);
         reftest_options.allow_num_differences = dim.width as usize * dim.height as usize;
     }
     let num_failures = ReftestHarness::new(&mut wrench, window, &rx)
         .run(base_manifest, specific_reftest, &reftest_options);
@@ -395,21 +399,25 @@ fn main() {
     #[cfg(feature = "env_logger")]
     env_logger::init();
 
     let args_yaml = load_yaml!("args.yaml");
     let clap = clap::App::from_yaml(args_yaml)
         .setting(clap::AppSettings::ArgRequiredElseHelp);
 
     // On android devices, attempt to read command line arguments
-    // from a text file located at /sdcard/wrench_args.
+    // from a text file located at /sdcard/wrench/args.
     let args = if cfg!(target_os = "android") {
+        // get full backtraces by default because it's hard to request
+        // externally on android
+        std::env::set_var("RUST_BACKTRACE", "full");
+
         let mut args = vec!["wrench".to_string()];
 
-        if let Ok(wrench_args) = fs::read_to_string("/sdcard/wrench_args") {
+        if let Ok(wrench_args) = fs::read_to_string("/sdcard/wrench/args") {
             for arg in wrench_args.split_whitespace() {
                 args.push(arg.to_string());
             }
         }
 
         clap.get_matches_from(&args)
     } else {
         clap.get_matches()