258 points · by raybb · 6y ago · 281 comments
Or finally fix the activities and fragment mess?
With full virtualization, the contact surface is restricted to a few low level bits in the kernel along with a few HALs/drivers that need to talk to the host for meaningful/fast I/O, like input/network/graphics, and everything else can be kept stock with no modification. This allows us to ship largely the same binaries that would go on a dedicated Android device and have it be able to run on windows/macos/linux easily, and it's how we've been able to keep up with the pace of yearly Android releases.
Edit: Oh and note that we are totally aware of and bummed out by emulator's increasing resource usage as android version bumps up, to the point we're afraid that the next one will finally be the one that really needs all resources of a modern PC; as such, we're looking into ways to minimize the cpu/ram/disk footprint of the system images, keeping only the bits that are actually needed for testing apps (with Google Play Services, and being better at maintaining/promoting more stock AOSP images in the case where GMS isn't needed)
On all my PCs it is faster to build to device than having to deal with the emulator competing with Android Studio for hardware resources.
Not everyone has Google level budgets for hardware.
Neither of which required anything resembling a latest generation hardware. Try it again before you pretend your experiences years ago are still relevant.
And yeah, as of Android Studio 3.x (was waiting for the official 4.0 release), it was trying to nudge towards using the Google Play Services images pretty hard.
But this is pretty much what Android Emulator is - a fullish VM on a Linux base.
So this is basically the simulator situation, but with easier management of which libraries the guest userspace can dlopen and files to read()/write().
It's much like current Android-on-ChromeOS capabilities where containers are used to isolate where the "guest" userspace libraries are stored, so that it's not necessary to interop well with things like the host version of libc for example.
However, the problems come when considering the interface to the host kernel and hardware. Here are just two of the showstoppers:
1. Android expects to run on a particular range of kernel versions and configs each release. Fidelity is sacrificed to run with a wide range of Linux host kernel configurations. It's also easy for components on the host system such as SELinux to interfere with guest operation (and Android itself expects to use its own version of SELinux...so which one wins in the end?).
2. Further customization in the guest userspace needs to be made to account for needing to interop with a regular Linux system; e.g., input/network/display will be much more code that touches various parts of guest userspace and potentially hurts fidelity versus the VM abstraction where they are fake hardware and no customization of guest userspace is needed.
There are also isolation issues that involve more delicate dances, such as how to prevent runaway resource usage in the container from hogging the whole system (VMs merely waste the #vcpus + RAM dedicated to them; while that can be a lot compared to the host, it's explicitly controllable).
These problems sound less serious on the surface versus porting the Android framework directly to the host OS, but in the end it's basically the same level of essential complexity; containers just let you remove the incidental complexity of guest userspace libraries leaking into your /usr/lib and interop w/ your filesyste.
And once we try to run on non-Linux systems we're back at square one needing to port all userspace code to the host OS (Unless you're running Docker on macOS/Windows in which case you'd be creating a VM again, sacrificing all the benefits of containers versus VMs while keeping the complex customizations).
This is probably why Microsoft is pushing WSL2, ChromeOS skipped Android 10 support and is looking into ARCVM, and anbox is still running Android 7.1.1 (w/ plans to update but skipping releases in the meantime).
I have... an idea.
I don't want to upgrade the PC as I love it the way it is and it's enough for everything else. I feel like I'd like to make a simple app for my phone occasionally (just for fun and to make something in my life easier) but emulation seems impossible.
i'm with you that android emulation is pretty slow, but your machine is reaching near parity with many of the devices that run the platform you're trying to emulate.
it's nearly always the case that an emulator host has to have a significant performance margin over the guest just to account for the inaccuracies/inconsistencies/hacks that are involved in mimicking a system on a dissimilar hardware platform.
Core2Duo was released over 13 years ago, and discontinued over 7 years ago.
Time to think about upgrading before complaining about performance issues. Especially for emulation.
I have to use MacBook 13 (2019) in my current project, and it's having troubles with the emulator. Not sure if it's about the hardware or macOS inefficiencies, but I can't wait to get back to my Linux desktop where the emulator is buttery smooth, almost feels like a part of the system itself.
Unfortunately, there is only an aarch64 emulator for Android 7, which does not start on my system
(Regardless, reimplementing Windows APIs without documentation and writing a simulator for a phone OS are two completely different endeavors.)
The only exception to that is libsystem_{pthread,kernel,platform} because those form the kernel's ABI boundary. Libraries like libc, libdispatch, et al are the iOS build and use the iOS ABI.
An Android app is a Java app using a set of special APIs. Why can't it run on a host JVM given some libraries implementing the same APIs? I'm not interested in the NDK.
If your desktop can't replicate the performance of your phone, it's misconfigured or seriously underspecced.
During typing this comment I nearly lost my mind because my macbook shift key is playing up and other keys are doing key repeats. I think I might go insane, stupid butterfly design
And what issues did you have with activities and fragments?
Oh, on those. Compared to iOS and ViewControllers, they just isn't a comparison. Starting them? Oh, can I do new Activity()? Nope, use this Intent thing. Rotation? Good luck! Passing data around? I have to use a bundle? Why can't I set a variable inside, like any other object?
Just to start. :)
You can just set variables like normal Java just fine. The bundle thing is only necessary to preserve data across process deaths.
That said - I'd highly recommend checking out the Navigation components that are a part of Jetpack. They make standard navigation patterns, including deep linking, a complete breeze.
It's just frustrating that 10 years later, we still have nothing that is remotely capable of the things an iOS ViewController can do.
It would surely be nice to have the option but a good emulator is needed.
Considering the last patch for just one of the games I play was 50+ Gb, it's pretty reasonable...
https://ziglang.org/download/ https://ziglang.org/#Cross-compiling-is-a-first-class-use-ca...
50 million bytes is really a lot of bytes, it's just that everyone has become accustomed to orders-of-magnitude bloat, and doesn't realize the 100x duplication and inefficiency which sneaks into just about every part of computing where it can get away with it.
2. Good to see Google focus on animations finally
3. The CPU profiler looks amazing
The transition to androidx has been slow and painful. But overall Android dev experience is improving consistently
There's a reason we hated Flash-based Web sites, and animation was a huge part of it.
Now I'm considering which is worse: animated UI, or transparent UI. The asinine transparent-UI fad largely and deservedly died in the '00s, with the exception of Apple suddenly jumping on its discredited and defunct bandwagon years later.
Don't see why we need to bring back animated UI either, but I'm happy to consider suggested uses.
Speaking of stacked hierarchies, the rotatable 3-D display of views in a UI might be pretty useful. I like that idea.
With coded constraints you need to do that change code / restart cycle, especially with more complex layouts and SwiftUI isn’t there yet.
Those motion guides look like what Flash used to have, dearly missed.
Sure, HTML 5 can do everything Flash can do but there is nothing even close to that envioronment for making interactive animation and full games.
Compose (Android's swift UI counterpart) also needs to be compiled to see how your change fare.
Even with its preview feature, you need to compile your Compose tree to see how your change look.
This new lib gets a lot of things right, but this one part is a big step back.
That’s interesting, how common is it to write C++ for Android applications, and with Android Studio? I’m not that informed regarding android stuff but I understood that the native development kit wasn’t really that well maintained, making C++ an 2nd class citizen when compared to Java (and maybe Kotlin?).
I would guess it’s mostly used for games?
My one other work-related Android app also used C++, for computer vision-related stuff, 8 years ago. Android Studio/Kotlin/C++ is in my very subjective opinion about 20% better than 2012 Eclipse/Java/C++.
If I wanted to do basically everything in C++, I would strongly consider Qt.
When I tried it about 5 years ago, I ended up dropping Qt and doing Java/C++, because the effort to call Java from Qt wasn't worthwhile.
For example Facebook's Litho is a Java API, and uses a large chunk of the Android SDK's systems. But it also uses a layout engine in C++. This hybrid approach isn't uncommon, and Android Studio has some nice features to work in this mode like being able to follow usages across the JNI boundary and to auto-generate the JNI stubs.
Naturally via this mechanism you can also write portable business code that is exposed via Java bindings library.
Or you invert the logic, and the application is written as a library, with Java/Kotlin just doing the OS connection points and having the NDK logic somehow driving application.
Vulkan and real time audio are also only available via the NDK, to use them from Java/Kotlin you need to write your own bindings.
If you can boot an entire operating system with a single html file, THAT would be impressive.
The current version of jslinux is wasm, but the original was just a few JavaScript files and could easily have been a single HTML file.
The second issue is around the abstractions used to make apps - I'll speak for Android here but I believe iOS is quite similar in outline. In Android, abstractions are incredibly leaky and require you to understand much more about the internal workings than HTML does. I can build a site in HTML without worrying about how the browser implements the functionality - for example, I can make an un-numbered list, or create a list box and populate it with items, fairly easily, even doing so dynamically from JavaScript.
In contrast, on Android, you need to start understanding ListView versus RecyclerView (apparently the latter is better to use?). Then to understand Adapters. Then to figure out how to get content into that ContentAdapter. At some point invariably you'll discover issues with whether your code is running on the UI thread (and blocking the UI from updating while it runs, which is obviously bad), or running off the UI thread (and thus unable to update the UI elements)... You can't (at least in my experience) just get down to focusing on your business logic, without reinventing the wheel a fair bit here. You'll also need to discover the "de-facto go-to library" sometimes, where the built in API isn't good. Bluetooth springs to mind, where I believe most people would recommend using a third party library rather than the included one. That's a discoverability challenge.
I don't think we should take this level of control away from anyone wanting it, but I think it's important we recognise mobile development seems to favour the approach of "bring your own batteries, soldering iron, and flux, as we don't provide any", whereas web has some available batteries and equipment you are free to use, or alternatively to build your own. It would be nice to see some default "batteries" pre-installed, so people can get started without having to learn the details of all the leaky abstractions needed to understand how to get an app to show up and respond to input etc.
And then you have to write all the serialization and back-end support on the server side, or use yet another flavor-of-the-week stack to broker all of the back-and-forth.
I think it will come down to the level of abstraction that works and makes sense, while helping enable building things, though still focusing on the business logic, not the boilerplate.
I guess this is still one of the many un-solved problems!
FWIW, this exact same issue comes up in web development, only it is harder to spawn threads (in this case, web workers) to solve issues.
With Android, you'll probably need to be using UI and non-UI thread work for anything that makes a network request or does more than a "hello world".
And honestly, I'd prefer that an IDE generate a Hello World app with all the random stuff in it that a full-blown app would need, even if it isn't required for Hello World. It makes the learning experience a lot more useful.
As a bonus, all the tools to debug it (even with a device simulator or remotely on a real Android device) are already installed as part of the browser, and the browser itself is a download of less than 100 MB.
The is the classic web vs native debate. What are we optimizing for? Making it as easy as possible for someone with no experience to throw something together? Sure, the web is great for that. I would rather prioritize performance and the user experience.
If I wanted to poke around with some hobby projects, where would be the best place to start from scratch with all the best practices and development tools?
read the kotlin koans (assuming you are not familiar with kotlin), they are the best way to get used to that language if you know java, and kotlin is much more pleasant to use than java
Best practices and tools might be harder, a LOT has changed in the past 7 years.
Maybe https://github.com/ZacSweers/CatchUp as a sample ?
After that, it depends whether your hobby is to write an android app, or if the resulting product is hobby.
if it is the former, Compose is lots of fun and will be a big leap in android development. You can already use the dev version.
MVI has also deeply changed how I code Android apps. Again, maybe not needed for the level of complexity of an hobby app unless you want to toy with something different.
so you have
- the state, only containing pure java/kotlin objects)
- reducers to handle state changes. Basically a reducer is a method that takes a state as input (and often another parameter, like e.g. an user input) and creates another state as output.
- and a model of your ui, that is created from each state.
This works very well to have fully testable business logic (which is where the no Android objects is nice, so tests can just run on the JVM) and think about how both state and view changes (both state and view states are immutable, and are altered by copy).
Again, not necessarily something I say that grandparent absolutely needs, but if they want to try something new, it is there.
Meanwhile in the real world, https://jdk.java.net/14/release-notes
Google could just run OpenJDK on phones and toss all the garbage they built, but they're too proud. The GC and performance of ART isn't anywhere near OpenJDK
Most of the code was already written in Java. So I just used the tool to convert to Kotlin. Then I tried to infer how Kotlin works based on the generated code to write the rest. I don't feel proud about that project.
Good to know for my next Udemy course.
In the community one of the easiest ways to spot if an example is old and probably out dated is if the author wrote it in Java. New things people aren't even bother keeping up the guise that Java is relevant to new things.
Also Kotlin isn't created by Google and I personally would rather see Kotlin come out on top if we are directly comparing it to Swift.
You just need to go checking every now and then the gerrit AOSP checkins, they cherry pick stuff from OpenJDK, every version gets a little piece.
Then they use this half baked support to sell Kotlin versus Java, and cleverly never compare Kotlin to the actual Java versions.
That's why it should not be called Java at all. Sun sued Microsoft for J++ because their implementation was incomplete. Google got away with that. Java is more than language and few classes from the standard library.
Language spec has very limited set of packages generally in java.lang. https://docs.oracle.com/javase/specs/jls/se14/html/index.htm...
Platform API is here https://docs.oracle.com/javase/10/docs/api/overview-summary....
As now everyone will rush to copyright "common" API signatures, and lawsuit troll anyone found in violation of the copyright?
"I see your FOSS uses `parse(string)`. We own the copyright on that API, please buy a license or we'll sue."
So then every API would become i.e. `umvi_parse(string)` to avoid paying. I'm sure all sorts of auto-prefixer tools would pop up to help automate this, but still...
The Oracle argument (and as things currently stand in their case, the accepted argument) is basically that the API taken as a whole can be protected even if each individual function name can't, so you could protect the "Java API" but not "compare(a, b)". The idea of copyright arising from "structure, sequence and organization" is well established in the computing context as well as others (for example, you can hold copyright in a compilation even if the individual things being compiled aren't themselves copyrightable).
Still, API copyright would lead to all sorts of uncertainty at least at first, and certainly puts compatible implementations or reimplementations in the crosshairs, so I'd really prefer an Oracle loss here.
The whole programming landscape would need to be audited.
A number of industry professionals have also made this argument. See Eugene Spafford's amicus brief for an example: http://www.supremecourt.gov/DocketPDF/18/18-956/133474/20200...
By copying Java's APIs in a non-interoperable way, Google has diluted the Java ecosystem and sown confusion amongst users of the language, thus diminished the value of the IP held by Oracle, and Oracle is entitled to damages.
In terms of Android features Android Studio is more than just the android plugins, but if you like the latter then go for it?
Nevertheless, Gradle is currently much more popular than Bazel for Android development so it makes sense that this is where the focus is.
Also I noticed that the final 3.x minor release was much faster on my Mac than any of the others before it. I hope 4.0 keeps or improves the performance.
Most likely they are using one of/combination of: After Effects, Premiere Pro, DaVinci Resolve, iMovie and/or Final Cut Pro as those are the more standard tools in the industry.
Then again, I just started using it. So far I'm pleasantly surprised at its UI. After using the detestable UI in GIMP (and the somewhat hokey-looking one in Audacity), I didn't expect much from open source.
Because it has a nice video editor in it, that's useful for lots of things.
Might be hard to get into if you never used Blender before. But if you've done 3D modelling in Blender, you'll be pleasantly surprised that your intuition of how to move, scale and generally edit stuff works the same in the video editor as in the rest of Blender.
https://developer.android.com/studio/run/emulator-accelerati...
(Edit: On Linux, KVM for AMD should work already; this advice is for Windows hosts only)