Live data from Hacker News

Rawdrawandroid – Build Android apps without any Java, in C and Make

github.com

151–157 of 157 posts

Re: Rawdrawandroid – Build Android apps without any Java, in C and Make

#151

C is neat but something like python may be simpler to work with for most programmers. I wonder if anyone here has experience with Kivy and KivyMD libraries for python. The code is simple and self explanatory. class RectangleFlatButton(TouchRippleBehavior, Button): primary_color = get_color_from_hex("#EB8933") def on_touch_down(self, touch): collide_point = self.collide_point(touch.x, touch.y) if collide_point: touch.…

I built a simple kivy app a few years. Working with kivy and testing on my (linux) dev machine was great. Even side loading to test on my phone using the kivy launcher wasn't too bad. The pain point was that building APKs that the play store would accept was an ordeal and then when they change requirements you have to hope the kivy folks update their build tools in time to recompile with a new version of the NDK befo…

Thank you. Wasn't aware of that.

Re: Rawdrawandroid – Build Android apps without any Java, in C and Make

#152

Earlier quoted context omitted.

(I assume by "Linux" you mean a distribution like Arch/Debian/Fedora/Ubuntu/… since, as the sibling says, Android also runs Linux.) > That will break the back of the duopoly and also make things like this so much easier. …and so much less secure by giving every application access to everything in my home dir. No, thank you.

Restricting app filesystem access is easily doable with Flatpak, Firejail, systemd-run, etc. Hardware support and UX are much bigger problems.

AFAIK the sandbox on Android is quite a bit stronger than your run-of-the-mill container (starting with every app running under a different UID[0], apps having very restricted access to the screen buffer[1], et cetera).

But it's not really about sandbox security and file system access. The issue is that the more walls you erect and the tighter you make your sandbox, the harder you will make it for apps to access system resources for legitimate purposes. This is where Android shines as it provides a huge, fine-grained API for apps to access system resources while still making sure they only access what they're allowed to access. On Linux we don't even have that fine-grained an API, let alone the same level of fine-grained control. You either grant an application access to your bluetooth/wifi/… device or you don't.

What's more, all Android apps and their UI have been built around this permission-based system these days. Compare this to Linux where applications still assume they have access to everything by default and you have to work very hard to confine an application while making sure it's still usable and the user is not thrown off by weird error messages.

In other words: The strength of Android (and iOS) is that they built in a tight & fine-grained capability-based system from the get-go and also solved the UI challenges that went along with that. These days, they can count on an entire ecosystem of applications that expect to live (and are usable) in that sandbox.

Regular Linux distributions are lightyears away from that. Personally, I really hope SpectrumOS[2] will make a dent here.

[0]: https://source.android.com/docs/security/app-sandbox

[1]: https://source.android.com/docs/core/permissions/restricted-...

[2]: https://spectrum-os.org/

Re: Rawdrawandroid – Build Android apps without any Java, in C and Make

#153
post #143

Earlier quoted context omitted.

I appreciate your response. My original post was a rant for sure, but let me reply to your comments. > You want project Valhalla, or more specifically Value Objects, which are in preview [0]. If you really want the highest performance related to cache accesses, you want to arrange things as SoA (struct of arrays) anyway, which has approx 0 object overhead and doesn't require Value Objects. SoA requires unboxed arrays…

FWIW, I spend a lot of my time writing low-level code, but more for desktop/server machines and less-so for mobile. > SoA requires unboxed arrays, otherwise it defeats the purpose. I may have been wrong about int[] being boxed Yeah, that's wrong. Primitive arrays aren't "boxed". An int[] is not an Integer[], and no boxing is performed unless you ask for it. SoA is fine in Java. > the fact that ints still auto-promote…

> Yeah, that's wrong. Primitive arrays aren't "boxed". An int[] is not an Integer[], and no boxing is performed unless you ask for it. SoA is fine in Java.

Yes, I botched that one, agreed.

> It's pretty easy to avoid boxing if you don't want it. They are separate types after all. Even so, Android lint has an inspection for it, and Intellij (presumably Android Studio too?) has an inspection you can turn on to detect it [1]. If you're running afoul of autoboxing, it's probably mostly in collections-based code and you'll want something like fastutil [2].

Autoboxing is a contradiction of "It's pretty easy to avoid boxing". It's specifically egregious for any place where you need performance guarantees.

> I don't understand this. You aren't using more than "native size" on any platform in any language without some sort of emulated Big* type.

Because you don't have unsigned integers (or arithmetic). So, for example, if you're playing with a 16-bit unsigned value, then you need a 32-bit signed integer to hold the 16 bits you care about (and you can kind of pretend you have 16-bit unsigned arithmetic.) But if you need a native-sized unsigned integer, you're out of luck.

> Implementations typically have both escape analysis and a nursery generation for this. This works well in a desktop/server environment.

Not on Google's VM the last time I tried. Shit went on the heap and the "concurrent" GC would then stall the entire application for ~1s every ~10s.

> I'm knee-deep in GDX and LWJGL, right now, but again not in a mobile context. I used to hang out in the Java gaming forums with the folks who originated LWJGL (e.g. cas).

I used to be on #LWJGL on Freenode, but it seems the guys moved to Discord or something.

By the way, we haven't talked about how horrible the JNI is, which requires you to wrap every C function so that you can pass around the JNIEnv handle and to manually marshal data structures to/from, like you're writing fucking Lua bindings or something. The right way to do FFI is the Haskell way, where you just call the function and get compiler support for auto-marshalling data structures (and, if you want, you can get your Haskell program to build and statically link the C library from source; no need to compile separately using another build tool and then dynamically load a shared lib.) Even C# does it better than Java. So in the use case where you have optimized C code and the rest of the application in Java, even the bridge itself is a pain in the ass to write.

Re: Rawdrawandroid – Build Android apps without any Java, in C and Make

#154
post #143

Earlier quoted context omitted.

I appreciate your response. My original post was a rant for sure, but let me reply to your comments. > You want project Valhalla, or more specifically Value Objects, which are in preview [0]. If you really want the highest performance related to cache accesses, you want to arrange things as SoA (struct of arrays) anyway, which has approx 0 object overhead and doesn't require Value Objects. SoA requires unboxed arrays…

> Vector API In all fairness, simd in C++ and portable-simd in Rust are both in preview. Not that there is a lack of alternate options there but still. The languages that do have these APIs stable are Swift, C#, Mojo, Zig and Julia if I’m not mistaken. Stability means different things for some of these as Mojo and Zig are young languages.

C++ compilers today already auto-vectorize simple loops, even without manual unrolling. For manual SIMD, I agree a built-in type would be best to abstract over the 10 different HW APIs.

Re: Rawdrawandroid – Build Android apps without any Java, in C and Make

#155
post #154

Earlier quoted context omitted.

> Vector API In all fairness, simd in C++ and portable-simd in Rust are both in preview. Not that there is a lack of alternate options there but still. The languages that do have these APIs stable are Swift, C#, Mojo, Zig and Julia if I’m not mistaken. Stability means different things for some of these as Mojo and Zig are young languages.

C++ compilers today already auto-vectorize simple loops, even without manual unrolling. For manual SIMD, I agree a built-in type would be best to abstract over the 10 different HW APIs.

This is true, but it is also very brittle and cannot kick in where compiler cannot assert that e.g. source and destination do not alias, where it might change semantics or where there might be side-effects that the compiler cannot hoist out of the loop body on your behalf.

Which is why most code that really cares about optimal HW utilization is vectorized explicitly - it's problematic to assert against potential regressions between compiler versions and addressing them is just as brittle.

Re: Rawdrawandroid – Build Android apps without any Java, in C and Make

#156

Earlier quoted context omitted.

Restricting app filesystem access is easily doable with Flatpak, Firejail, systemd-run, etc. Hardware support and UX are much bigger problems.

AFAIK the sandbox on Android is quite a bit stronger than your run-of-the-mill container (starting with every app running under a different UID[0], apps having very restricted access to the screen buffer[1], et cetera). But it's not really about sandbox security and file system access. The issue is that the more walls you erect and the tighter you make your sandbox, the harder you will make it for apps to access syst…

I'm not tech enough to challenge you on that but in practice most apps demand far more than they need and users generally click yes. If I don't I get annoying reminders every time and feature restrictions. Like my app that comes with smart watch. At some point I guess most will say take it can stop bothering.

I don't follow what you mean by "give or don't" isn't that how Android works? Like I give file system or drive access to some app so it can pick pictures. Do I know what else it does with that permission?! Just have to trust.

Re: Rawdrawandroid – Build Android apps without any Java, in C and Make

#157

Earlier quoted context omitted.

AFAIK the sandbox on Android is quite a bit stronger than your run-of-the-mill container (starting with every app running under a different UID[0], apps having very restricted access to the screen buffer[1], et cetera). But it's not really about sandbox security and file system access. The issue is that the more walls you erect and the tighter you make your sandbox, the harder you will make it for apps to access syst…

I'm not tech enough to challenge you on that but in practice most apps demand far more than they need and users generally click yes. If I don't I get annoying reminders every time and feature restrictions. Like my app that comes with smart watch. At some point I guess most will say take it can stop bothering. I don't follow what you mean by "give or don't" isn't that how Android works? Like I give file system or driv…

> users generally click yes

I agree that's an issue but I would say it's a separate one. At least in Android these days you don't have to agree to everything upfront (during installation) but you can choose the permissions you want to grant one by one later during runtime. E.g. when the app wants to access the camera, it asks you for access right there and then and you can also only give it one-time access. That's already been a big UX and security improvement and I'm sure this can be improved even further.

> Like I give file system or drive access to some app so it can pick pictures.

In past versions of Android yes. Nowadays, however, in order for the app to access select photos it no longer needs the general file system access permission. The file picker has become a system component, and by picking photos you grant the app access to the selected files and the selected files only. Of course if the app is, say, a photo gallery app, then it will probably still need access to your entire camera folder (or even the entire file system), not just individual files. In such cases, I at least will probably review the app a bit more carefully.

> Do I know what else it does with that permission?! Just have to trust.

That's always the case when you grant permissions to someone or something. At least, the more fine-grained your permission system is, the more control you have, and the easier it will be for you to build that trust.

In my case I usually disable internet access[0] for apps by default, so that even if they need access to, say, my entire file system, they won't be able to send my files anywhere or do anything shady. Only for select apps that I've reviewed carefully I might also enable internet access.

Either way, I hope we can agree that Android gives you a lot more control over what you allow your apps to do than Linux. In Linux I have to blindly trust all apps at once. It's all or nothing.

[0]: I use GrapheneOS. In regular Android the internet permission is no longer exposed to the user, I think.

Post reply on HN