359 points · by doodlesdev · 2y ago · 147 comments
I've stopped counting how many times I came back to an Android project after only a few months, only to have Android Studio force me to update Gradle and dependencies and whatnot, and break everything.
* Of course one could blame me for not learning the ins and outs of the build system!
Unfortunately this doesn't actually protect you from that since you still have to deal with that for both the actual "make an APK" step as well as the Java bindings for critical features.
This. And people are surprised that many just wrap websites as apps on Android.
Try and do it. if you run into a deal breaking issue with PWA features, then wrap it in a minimalist app shell.
Best case: everything works on Android and iOS and it's also a website.
Worst case: you will end up doing some platform specific code and dealing with the app stores like you were going to do anyway.
Average Case: everything will work on android and some things will be broken on iOS.
VSCode isn't bad but disliking Android Studio just feels like you started with it and didn't want to learn a different tool.
It's a native Android app (Kotlin) which isn't developed using Android Studio. Gradle only.
In other cases, updating Gradle won't give any problem. You can build the APK fine. Debugging the build system is annoying :D
This used to be 5-6 years back. These days it is very stable.
I actually _like_ Java, so it's not that I hate Android, but frankly, I have no idea what it is even doing downloading and generating gigabytes of crap with inscrutable huge log files. Most of my applications' Java/GUI parts are no more complex than a hello world -- many times I find it easier to just rewrite them from scratch than even try "upgrading" them using Android Studio.
The Android tooling is basically a textbook definition of oversized enterprisey software. I really wish there was just a frigging (resource) compiler, linker and maybe packer that I could invoke from the command line in simple steps.
As a Gradle veteran, I've written in detail about this previously:
https://news.ycombinator.com/item?id=38875936
TL;DR: Gradle is too powerful (which is fun and seems valuable at first!) with too many footguns. Combine this with the mandatory update migrations and you're literally signing up for future pain compared to using a lower change-rate build tool like Maven. Do you really need to run arbitrary commands to build your app? If so, take a deep gaze in the mirror and reflect on what you're doing with your life.
Had it not been for Android replacing Ant with Gradle, and most folks wouldn't even remember Gradle.
Gradle is not too powerful, it builds a build graph based on the .gradle file, and the building itself happens imperatively — but the actual execution is static, based on that fixed build graph. This configuration is cached and subsequent executions will all refer to this static graph to know what requires rebuilding.
This is the minimum required complexity/generality for a build system that is not “hardcoded” for a given task (e.g. to a degree maven, but cargo, go’s build tool etc all can only compile their respective languages on their own. “Plugins” can let them do more, but at that point plugins have to re-develop all the functionality of a build system - caching and parallelization), and as I mentioned there really are only a handful of tools capable of that.
As for valid criticisms of gradle - it’s API historically experiencing constant breakages, used to be dependent on JDK version (and lagged behind for a long time due to Groovy), which is more or less fixed now with toolchains, and the model not being clear enough for people not wanting to dive deep. E.g. I can count on a single hand how many people knows that doFirst/doLast should be used for the actual task itself, anything else will happen at the config build time which is not what you want.
Proguard is fun too, with how it'll carve out or break chunks of functional code if you don't spell out precisely what shouldn't get deleted/obfuscated.
Each time I have to touch it, it results in problems... Oh, you updated JDK? Gradle won't work. There is new Gradle? Tough luck it will break your build..
And with Maven it can update and the build keeps working just fine.
To that end I mostly ignore prompt "update gradle!" in Android Studio to avoid any issues...
Wait till you want to build anything reasonable.
All libraries for Android are in Java and/or Kotlin. If you have to write all of them in C then best of luck doing anything meaningful.
What kind of libraries? Anything related to SSO. Anything related to Material design. Anything related to any ancillary services that you want to integrate with e.g. Google services.
The structure is (using [dirname] notation for directories)
[Repo Root]
...git and github files, READMEs...
[Flappy Bird]
... project files, keystore, build.bat ...
[App]
[build]
... I'm ok with tools making a mess here as long as outputs is tidy ...
[outputs/apk]
..the actual .apk
[src]
[main] this seems a little off, main contains libs and resources
Android_Manifest.xml Yep ok, I'll rant about that later, that's its own thing
[assets] all good
[res] Wait what? that's like a synonym for assets, (but for a different layer)
[libs] Hang on, these are .so files. built libs should be in the build dir
[jni] This looks like what src or src/main should have had inside it
So ignoring the outer layer for the README etc. which isn't needed for an Android app, Just encapsulation for presentation. Arguably the same applies for the next layer too. I feel like the contents of App could be placed in here at no loss.I'd Shuffle it around to make [Flappy Bird] contain [main] and [build]. move [libs] to [build/libs] rename [jni] to [src].
If you had an architecture like that then the one-true-build-system should be a command line tool that you can point at [main] and it does what [Flappy bird]/build.bat does only with auto detection of the installed tools, optional config file overrides, optional commandline overrides.
AndroidManifest is another issue entirely I'd like something that invisibly converted something sane to XML and I'd never see it again, but I'll grin and bear it. A decent validator and maybe I'd like a standalone AndroidManifest editor that knew what everything did and could provide appropriate boilerplate.
After typing this up (mostly as organizing my thoughts), I actually think you could have a relatively painless way to make Android Apps.
Ideally tools should support, not dictate. For instance, if you were building a simple source only app with no assets, a good tool should be able to be pointed at, say, a main.c file in the directory and be able to use the contents of the directory containing main.c for other required files and work with no special extra configuration. Supporting a structure to keep things clean is great, Imposing one(whether you use the features it offers or not) is poor.
I might take a look at the NDK and see if it can be circumvented.
The few times there wasn't a plugin to do what I needed, I've managed to roll a custom one pretty easily.
When Vite breaks you're completely screwed though. Find a different way to do it or wait until a patch comes out. Vite internals are nigh impossible to fix on your own.
Dissatisfied with the state of the vendor SDK for CH32V003 microcontrollers (ultra-cheap RISC-V MCUs), he created his own [1], which is a pleasure to use. He also has a header-only RISC-V emulator that runs Linux (and Doom!) [2], and hacked an ESP32 to emit valid LORA frames with clever use of aliasing [3].
[1] https://github.com/cnlohr/ch32v003fun
the ndk is meant for writing little bits of c to speed things up in a classic java android application.
this is a pretty cool hack that allows for opengl apps to be written in straight c that run full screen and have limited access to things like keyboards, adc inputs or usb.
it does not include a reimplementation of the android frameworks in c and the ndk provides limited access for ndk code to interact with them.
the main use case seems to be supporting a program for live audio reactive visuals based on extraction of chroma.
It's not even a hack. Android NDK added that way back in like gingerbread, it's just a NativeActivity. https://developer.android.com/ndk/samples/sample_na
This is just a small framework on top of that. It's not doing anything "new"
I'm doing a desktop app meant to be as cross compatible as possible and the only reasonable way to do it (without sending yourself into build config hell) is with opengl.
And it is! Hah.
Looking briefly at the makefile, I think they might have avoided Gradle, though it calls other tools written in Java.
I'd love to see a way to build a Flutter app without Gradle.
unzip somewhere, set path variable
> yes | sdkmanager --licenses && sdkmanager "platform-tools" && sdkmanager "ndk-bundle" && sdkmanager "build-tools;33.0.0" "platforms;android-33"
Yes, you can just grab the zip files. For example like this: https://www.hanshq.net/command-line-android.html#sdk
You generally don't need to touch gradle at all with flutter. Is your issue about having to install gradle onto your machine, even if you don't use it directly?
(I used to work on it, or at least tried to before giving up in frustration.)
Out of interest, what blockers did you encounter using Flutter? For me it was much better than native android in terms of development, but it could depend on the usecase.
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.grab(self)
self.ripple_show(touch)
return True
return False
def on_touch_up(self, touch):
if touch.grab_current is self:
touch.ungrab(self)
self.ripple_fade()
return True
return False
class MainApp(App):
def build(self):
screen = Builder.load_string(KV)
screen.add_widget(
RectangleFlatButton(
text="Hello, World",
pos_hint={"center_x": 0.5, "center_y": 0.5},
size_hint=(None, None),
size=(dp(110), dp(35)),
ripple_color=(0.8, 0.8, 0.8, 0.5),
)
)
return screenMainApp().run()
I just remember working with Libgdx back in the days. A game framework made for Android. It however was cleverly designed in that you could just run it on desktop by changing which implementations were used for drawing/sounds/assets. Very nice to work with, could just recompile the app in seconds and test, even hot swap, compared to the other way of building an apk, installing, launching etc which took minutes per iteration.
Also made a simple project on github to show how to do a "loading screen", aka not just freeze while it loads but have a progress bar and interactivity. Somehow it still gets random stars a decade later.
> 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.
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-...
In other words: lightweight, useful, cheap - pick two.
(Then gradually rewrite the core in Zig.)
https://github.com/libsdl-org/SDL/blob/main/docs/README-andr...
And all for what? To satisfy a hobby itch that has no practical benefit? The problem of app developers is almost never the language. Hell, look at how popular web apps are even though JavaScript is the worst language in any sort of widespread usage. The platform is what gets people excited (or frustrated), not a language.
They hit jackpot with Kubernetes and Docker taking off after their pivot to Go.
I wake up every morning and thank God that Flutter exists. I can target Android without dealing with building on years and years of sloppy work.
Sunk-cost fallacy x politics leads to this never being fixed. I don't think Google can fix it, unless hardware fails entirely. There's been years-long politics that culminated in the hardware org swallowing all the software orgs, and each step along the way involved killing off anything different.
Can they eventually throw away Android and replace it with Fuchsia? In the reporting about Fuchsia that I read ages ago, it sounded like it was intended to be an Android replacement but, looking into it again just now, it seems more like an embedded OS for other non-smartphone hardware -- maybe with some (aspirational?) claims of utility on smartphones and tablets.
The problem with replacing a UI toolkit - any toolkit - is that any change to the toolkit requires modification of all software, including third-party software. Typically, when an OS wants to provide a new toolkit, they wrap the existing toolkit in new code. For example, on macOS, UIKit wraps AppKit, and on all Apple platforms SwiftUI is a wrapper around AppKit and UIKit (depending on platform). On Windows, every UI toolkit ultimately is creating "windows" as they are understood by USER[0], which creates corresponding objects in CSRSS and/or the NT kernel, which can then be used to draw on or attach to a GPU. The lowest level UI abstraction either OS provides is the objects supported by their oldest toolkit, and the lowest level programming language you can write apps in is whatever can call it.
Linux is a bit different, because it inherits its windowing model from X11. X shipped with no default toolkit and a stable window server protocol that apps could program against directly, in an era where most GUI OSes[1] didn't have 'servers' or 'protocols'. You populated resource files and called the relevant function calls to make things happen, and those function calls became sacrosanct. Even Windows NT couldn't escape this; it still used USER despite USER being years older than NT.
The best you can do is shim the library - write something more lower level than the old junk and then rewrite the old library in terms of the new one. This is what Xwayland does to make X apps work on Wayland; and it's what Apple did (mostly) with Carbon to give a transition path to Mac OS 8/9 apps on OS X. Google could, say, ship a new Android toolkit that doesn't use Java bindings, and then make Android's Java toolkit a shim to the new native toolkit. However, this still means you have to keep the shim around forever, at least unless you want to start having flag dates and cut-offs. For context, Apple didn't kill Carbon until macOS 10.15 Catalina, and if they hadn't refused to ship Carbon on 64-bit Intel, it probably would still be in macOS today.
[0] An interesting consequence of this is that disabling "legacy input" in games turns off the ability to move the application window since all that code is intimately coupled to every app that has to open a top-level (i.e. not a widget) window.
[1] At the time that would be XEROX Star, the Lisa, and the Macintosh
[2] This is also why Apple will never, ever ship an iPad that can run macOS software in any capacity. Even if they were forced to allow root access and everything else macOS can do. The entire point of the iPad is to force software developers to rewrite their apps for touch, and I suspect their original intent was for the Macintosh to go away like the Apple ][ did.
That "everything" contains a pretty big gap.
Just gonna leave this here: https://safecpp.org/draft.html#the-call-for-memory-safety
P.S. Was discussed on HN recently: https://news.ycombinator.com/item?id=41528124
P.P.S. The author has a great YT channel with awesome embedded systems projects: https://www.youtube.com/playlist?list=PLDRymMFQl3Nktk_pjlUP_...
Check out this blog on zig memory safety: https://www.scattered-thoughts.net/writing/how-safe-is-zig/
(Not my blog, just a blog I found that discusses zig)
Zig is not at 1.0 yet so its a bit behind rust from what iv seen online. One I manage to get C under my belt and get good at writing los level stuff in that language, I might attempt to learn rust or zig.
I'd expect Zig to be an easier deal here, with its zero-impedance interface with C.
Sure, harder, but not really all that difficult. Run bindgen over the NDK headers and see what happens. Sure, for ergonomics you'll want to write safe Rust wrappers. After that's done once, it's done.
> Rust has fewer cross-compile targets.
Not really an issue here. Rust supports all the targets Android runs on. Natively, even:
$ rustup target list | grep android
aarch64-linux-android
arm-linux-androideabi
armv7-linux-androideabi
i686-linux-android
thumbv7neon-linux-androideabi
x86_64-linux-androidC++ <-> Rust is much more annoying.
It would be silly to write low-level software in Java, or high-level software (with exceptions for software which would require a low-level language) in C.
#include <android/configuration.h>
#include <android/looper.h>
#include <android/native_activity.h>