Skip to content
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

How to android build? #68

Open
iCloudsPWASaaS opened this issue Feb 21, 2022 · 20 comments
Open

How to android build? #68

iCloudsPWASaaS opened this issue Feb 21, 2022 · 20 comments

Comments

@iCloudsPWASaaS
Copy link

Hi, is it possible for android apk build and act as an android localhost Web server?

@terreng
Copy link
Owner

terreng commented Feb 21, 2022

Interesting idea, thanks for the suggestion! If we were able to build for Android, then the program would be able to run on Chromebooks too through the Google Play Store.

What do you think @ethanaobrien? We can build a lightweight web based UI for the app using Cordova, which I am very familiar with. We would have to figure out how to best run a web server in the background on Android, and how to port over the logic for it.

@ethanaobrien
Copy link
Collaborator

It'd be pretty cool, we'd probably only need to re-write the base handler, everything else should theoretically plug in (assuming we can still use the nodejs libraries)

@terreng
Copy link
Owner

terreng commented Feb 21, 2022

@ethanaobrien I recently tried building the app using Tauri instead of Electron. The UI works great because Tauri uses a web view, but the actual server backend doesn't work because Tauri uses a Rust backend, not Node like Electron does. The advantage to using Rust is that it cuts memory usage in half. Together with using a system web view instead of shipping with Chromium, Tauri app installers can be as small as 3 MB! They launch faster too.

The reason I bring this up is because I understand that Android supports Rust also. So, in theory, if we rewrote the web server code into Rust, we could achieve significantly smaller app size, smaller memory usage, and faster launch time on Windows/macOS, and then we could also port it all over to an Android app which could run on Chrome OS. Tauri also say they plan to add support for compiling for Android and iOS in the future, because it doesn't support it yet, but we can use Cordova in the meantime.

I don't know of any practical way that we could use the Nodejs code and libraries in an Android app. Nodejs and Electron in general probably isn't the ideal choice for an app like this one, which is a sentiment that I believe kzahel expressed. I think Tauri and Rust could be a better long term choice.

Please let me know your thoughts on this. Do you think converting the web server logic into Rust would be a good idea, and would it be something you'd be interested in doing? Of course, we can still launch the first version with Electron and then consider a transition later.

@ethanaobrien
Copy link
Collaborator

I think it'd be cool to do, and efficient, I just don't know rust so thatd be a setback

@terreng
Copy link
Owner

terreng commented Feb 21, 2022

I think it'd be cool to do, and efficient, I just don't know rust so thatd be a setback

I don't know Rust either. I've been playing around with it, and my initial impressions are that it's somewhere in-between C and a language called SML.

I had a go at converting humanFileSize into Rust. Here's what it looks like:

fn main() {
    println!("{}", humanFileSize(340850.0));
}

fn humanFileSize(mut bytes: f32) -> String {
    let thresh = 1024.0;
    if bytes.abs() < thresh {
        return format!("{} B", bytes);
    }
    
    let units = ["KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"];
    let mut u = -1 as i32;
 
    loop {
        bytes /= thresh;
        u += 1;
        if !((bytes.abs() * 10.0).floor() / 10.0 >= thresh && u < (units.len() as i32) - 1) { break; }
    }
    
    return format!("{} {}", bytes, units[u as usize]);
}

Obviously there's a learning curve, but it wasn't too difficult to figure out the Rust syntax. I don't think converting the existing logic code into Rust is going to be very difficult. I think the challenging part will be figuring out how to actually create a web server and file system in Rust, although I'm sure that both of these things have already been done and there might be libraries we could use.

Do you have interest and time to learn Rust?

@iCloudsPWASaaS
Copy link
Author

iCloudsPWASaaS commented Feb 21, 2022

Hi, do you think this can help -
https://code.janeasystems.com/nodejs-mobile/getting-started-cordova

Do you think node js api can be communicate as below -

const cordova = require('cordova-bridge');

cordova.channel.on('message', function (msg) {
  console.log('[node] received:', msg);
  cordova.channel.send('Replying to this message: ' + msg);
});

**And from cordova index.js**

function channelListener(msg) {
    console.log('[cordova] received:' + msg);
}

function startupCallback(err) {
    if (err) {
        console.log(err);
    } else {
        console.log ('Node.js Mobile Engine Started');
        nodejs.channel.send('Hello from Cordova!');
    }
};

function startNodeProject() {
    nodejs.channel.setListener(channelListener);
    nodejs.start('main.js', startupCallback);
    // To disable the stdout/stderr redirection to the Android logcat:
    // nodejs.start('main.js', startupCallback, { redirectOutputToLogcat: false });
};

@terreng
Copy link
Owner

terreng commented Feb 21, 2022

@WebScaffolder Thanks for the idea! I believe this might work, however it would greatly increase the app size (from around 5 MB to around 100 MB), and it would run in the JavaScript context which would be problematic for running in the background. I think if we instead ran the web server from the native side, it would be able to run in the background without the UI needing to be loaded.

@ethanaobrien
Copy link
Collaborator

Time would be a crunch especially with school and yeah. Once we find a library for http sockets and the filesystem I'd sit down to learn rust. I've been really busy lately so sorry if I havent been as active.

@terreng
Copy link
Owner

terreng commented Feb 21, 2022

I've been really busy lately so sorry if I havent been as active.

No worries. I will keep looking in to Tauri and Rust.

@iCloudsPWASaaS
Copy link
Author

iCloudsPWASaaS commented Feb 22, 2022

Meanwhile can we build with cordova, i think just need to lunch app using cordova but need to figure out nodejs in background so that codova can start node js server from config. require('electron') should be remove for app. let me know.

@terreng
Copy link
Owner

terreng commented Feb 22, 2022

meanwhile can we build with cordova, i think just need to lunch app using cordova but need to figure out nodejs in background so that codova can start node js server from config. require('electron') should be remove for app. let me know.

I'm having difficulty understanding what you said. I have no immediate plans to build an Android version of this program using Cordova, but it may be something we pursue in the future.

@iCloudsPWASaaS
Copy link
Author

iCloudsPWASaaS commented Feb 22, 2022

Hi, Cordova is not necessary but do you think we can use app, BrowserWindow from electron, lets say I can install Termux - node environment and run index.js..do you think electron's app method work here? There can be a simple solution, lets fix it.

@terreng
Copy link
Owner

terreng commented Feb 22, 2022

Hi, Cordova is not necessary but do you think we can use app, BrowserWindow from electron, lets say I can install Termux - node environment and run index.js..do you think electron's app method work here? There can be a simple solution, lets fix it.

Electron does not support mobile. Also, any solution that would involve the user needing to download Termux cannot be considered simple. There are existing web server apps on the Google Play store, and while none of them have functionality that aligns with the features of Simple Web Server, I'm sure one of them would work in the meantime. That said, I still would like to bring this app to mobile, but I'll need to keep looking in to the best way to make that happen.

@iCloudsPWASaaS
Copy link
Author

Hi,

Please check below -
https://github.com/warren-bank/Android-NodeJS-Frontend

I can able to run index.js after removing electron using https://play.google.com/store/apps/details?id=io.tempage.dorynode&hl=en but it's not open source though.

Rust u may use for memory facility and all but java project Android-NodeJS-Frontend can be customize for this project which can save time.

remember neither rust or cordova can give you node environment as built in way.

Let me know your thought.

@terreng
Copy link
Owner

terreng commented Feb 22, 2022

Rust u may use for memory facility and all but java project Android-NodeJS-Frontend can be customize for this project which can save time.

The only thing the app needs Node for right now is the web server, which shouldn't be running from the frontend. I don't think finding a way to use Nodejs on Android is going to be an effective approach, for app size and memory usage reasons.

remember neither rust or cordova can give you node environment as built in way.

Rust can't provide a node environment, that's true, but the goal is to not use a node environment in the first place.

I have no doubt that it's possible to port the existing code to Android using Nodejs, but at the moment I am looking to find a better and more efficient way to achieve the same result. I don't currently have plans to use node in any capacity in a mobile environment.

@ethanaobrien
Copy link
Collaborator

@terreng
I think our main focus should be first the UI. It (in my opinion) is normally the most difficult part in most languages

@iCloudsPWASaaS
Copy link
Author

iCloudsPWASaaS commented Feb 24, 2022

open source -
https://github.com/warren-bank/Android-NodeJS-Frontend

non commercial -
I can able to run index.js after removing electron using https://play.google.com/store/apps/details?id=io.tempage.dorynode&hl=en but it's not open source though.

As I said UI is ready, just need to connect WSC with it and we can build for Windows with ant and gradle for android.

@iCloudsPWASaaS
Copy link
Author

And same time think about IOS as well - win, android, ios compitability neceessary for completing this project i hope.

@iCloudsPWASaaS
Copy link
Author

iCloudsPWASaaS commented Oct 11, 2022 via email

@terreng
Copy link
Owner

terreng commented Oct 11, 2022

Can we not develop whole project using Cordova 7 ?

I am very familiar with Cordova. Unfortunately it doesn't solve the issue here. Simple Web Server is made up of two parts: the web-based user interface, and the web server code. Cordova would make it easy to run the user interface on Android or iOS, but it that's only half of the app. The other half, the actual web server code, currently runs with Node.js, and can't be ported as easily.

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

No branches or pull requests

3 participants