Lymphatus / libcaesium

The Caesium compression library written in Rust (with a C interface)
Apache License 2.0
128 stars 23 forks source link

[Help Wanted] - Android && libcaesium #16

Closed ferencIOS closed 1 year ago

ferencIOS commented 1 year ago

I am trying to compile the lib for Android on MacOS Ventura 13.3.1 - Apple M1.

My idea is to follow the Android Guide, starting from .a files or .java/c files.

First of all I changed the Cargo.toml file:

[...]
[lib]
[...]
crate-type = ["staticlib"]
[...]

Then:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
rustup target add aarch64-linux-android
cargo build --release --target aarch64-linux-android

Result:

  Compiling libdeflate-sys v0.11.0
   Compiling libwebp-sys v0.4.2
   Compiling gifsicle v1.93.0
   Compiling mozjpeg-sys v1.0.6
   Compiling itertools v0.10.5
   Compiling filetime v0.2.21
   Compiling miniz_oxide v0.5.4
   Compiling wild v2.1.0
   Compiling arrayvec v0.7.2
error: failed to run custom build command for `mozjpeg-sys v1.0.6`

Caused by:
  process didn't exit successfully: `[path]/libcaesium/target/release/build/mozjpeg-sys-a12e86570479e512/build-script-build` (exit status: 1)
[...]

Thanks for your help!

Lymphatus commented 1 year ago

Unfortunately the process is a bit more complicated than that. I know for sure it works because I successfully compiled the project for Android and built a demo app on top of it. I don't have an Apple Silicon (just an Intel one) but I remember I managed to get it working following this https://github.com/mozilla/rust-android-gradle

If I remember correctly I had to adjust a few things, but that was a good start. Mine was just an experiment and I did not go any further than building a simple app using the library, but I can get back to the code if you need further assistance.

Just keep in mind that the library is designed to accept an input file path and to write the compressed file into an output path, which is not really well suited for the Android environment due to OS permissions.

ferencIOS commented 1 year ago

Oh thanks! I will try to follow the guide.

If it should be simple I will write the steps that maybe it will be useful to someone else.

ferencIOS commented 1 year ago

Hi!

Starting from the main branch here is a patch for android support.

STEPS

package com.example.caesium4android.caesium

import java.lang.System.*

class CaesiumNative {

    external fun compress(source: String, destination: String): Boolean

    companion object {
        init {
            loadLibrary("caesium")
        }
    }
}
Lymphatus commented 1 year ago

Thanks! This is very similar to what I got during my experiments. I think it's better to have a separate project like libcaesium-android to keep this repository as clean as possible. I've done something similar with https://github.com/Lymphatus/libcaesium-php for PHP. I'll try in the next days.