sandwich
Posts: 39
Joined: Fri Oct 16, 2020 5:57 am

Android programming is possible (there's a catch)

Tue Nov 24, 2020 9:32 pm

Many threads and blog entries have given people a false impression that you might be able to use the Raspberry pi to write Android code and build APKs.
This is not the case in the usual sense, because although you can install various broken parts of the Android SDK from the Debian project, you cannot install Android Studio which is critical for active development especially because nowadays it contains the SDK manager, which is needed to auto-download various up-to-date required tools like gradle. Without the latter, you won't have sufficient certificate checking to build code via the command line.

That said, there is one totally different way to use Android Studio on the Raspberry pi. You're not going to like it. It is very slow. It requires the following steps:

0. Obtain the Raspberry pi 4, 8GB model and put a fan on it.
1. Install 64-bit Raspberry pi OS on a MicroSD of about 64GB and boot that.
2. Install the latest Qemu. To ensure best performance, build it yourself with all compiler optimizations.
3. Create a 32GB blank hard drive .img file with qemu-img.
4. Run Qemu for x86_64, giving it 2 or 3 cores and at least 4GB of RAM, and install your favorite Intel distro from an ISO file. (Whichever version is newest.)
5. Boot it up, and use Firefox within the x86_64 emulation to download Android Studio for Linux from Google and install it in /usr/lib.
6. Run studio.sh and let it update itself (it will take a few hours).

What this will provide you is a very slow emulation of an Intel Linux computer, running perhaps 1/100th of normal speed.
The x86_64 emulation by aarch64 appears to be not very efficient and it doesn't help that the Pi has small CPU caches.

In my opinion, this approach to running Android Studio is only useful for compiling existing apps into APK files, not for active development unless you are an extremely patient person.
It will take hours to build any sophisticated app, but this may be preferable to buying an Intel-based computer depending on your situation.
Last edited by sandwich on Tue Dec 01, 2020 5:32 pm, edited 1 time in total.

User avatar
Imperf3kt
Posts: 4231
Joined: Tue Jun 20, 2017 12:16 am
Location: Australia
Contact: Twitter

Re: Android programming is possible (there's a catch)

Wed Nov 25, 2020 4:12 am

What about the MIT app inventor 2?
https://summerofcode.withgoogle.com/arc ... 813534208/

Last I looked (~2016) it had an online version as well.

As a side note, I build Android apps with gradle (on an x86_64 PC) without Android Studio, I've never needed AS.
55:55:44:44:4C
52:4C:52:42:41

Rose tinted glasses are difficult to see through.

sandwich
Posts: 39
Joined: Fri Oct 16, 2020 5:57 am

Re: Android programming is possible (there's a catch)

Wed Nov 25, 2020 5:25 am

Imperf3kt wrote:
Wed Nov 25, 2020 4:12 am
What about the MIT app inventor 2?
https://summerofcode.withgoogle.com/arc ... 813534208/
That appears to be IoT specific. What most people want to do is write apps for phones.
As a side note, I build Android apps with gradle (on an x86_64 PC) without Android Studio, I've never needed AS.
That's what I tried to do, but the gradle that comes with Debian is too old and the build process wanted to download a newer one. However it couldn't because the code certificate didn't exist and the only way to create that is with sdkmanager, which is not included in any of the Android packages from arm64 debian.

hippy
Posts: 9188
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Android programming is possible (there's a catch)

Wed Nov 25, 2020 12:37 pm

sandwich wrote:
Wed Nov 25, 2020 5:25 am
Imperf3kt wrote:
Wed Nov 25, 2020 4:12 am
What about the MIT app inventor 2?
https://summerofcode.withgoogle.com/arc ... 813534208/
That appears to be IoT specific. What most people want to do is write apps for phones.
MIT App Inventor 2 itself is not IoT specific and is what I have used for my own-written apps which run on my phone.

The downside is that it's constrained by what it provides for and in how it works so does have some limitations. 'Drag and drop' visual programming is not to everyone's taste. Its big advantage though is, being cloud and browser based, it requires no installation on the host.

https://appinventor.mit.edu

I do know some people who have used MIT App Inventor for commercial development but most would use Android Studio. If anyone does require Android Studio I would suggest a Pi is not the right tool for the job.

sandwich
Posts: 39
Joined: Fri Oct 16, 2020 5:57 am

Re: Android programming is possible (there's a catch)

Thu Nov 26, 2020 3:53 am

hippy wrote:
Wed Nov 25, 2020 12:37 pm
Drag and drop' visual programming is not to everyone's taste.
Egad, that's what it is. Yeah I'll steer clear of that.

As for real Android programming, I agree it requires Android Studio running on a fast machine. If the Debian people were to port the full set of tools to aarch64 then it would be acceptably fast I think on a Pi 4. They seem to be unaware that even command-line Android development is broken on aarch64.

hippy
Posts: 9188
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Android programming is possible (there's a catch)

Thu Nov 26, 2020 11:51 am

sandwich wrote:
Thu Nov 26, 2020 3:53 am
hippy wrote:
Wed Nov 25, 2020 12:37 pm
Drag and drop' visual programming is not to everyone's taste.
Egad, that's what it is. Yeah I'll steer clear of that.
I don't like visual programming either but I am happy to suffer that in this case because it works and is far simpler to set-up and use than other options. It's fine for apps which don't have to do a lot.

It is possible to have an entirely textual equivalent of MIT App Inventor 2 blocks, generate something AI2 can import from that text, possibly even call their back-end compiler directly. That would be my route to a useful halfway house for Pi users. I developed proof of concept code which could convert blocks to text but the rest is still on my To Do list.

sandwich
Posts: 39
Joined: Fri Oct 16, 2020 5:57 am

Re: Android programming is possible (there's a catch)

Thu Nov 26, 2020 8:20 pm

hippy wrote:
Thu Nov 26, 2020 11:51 am
I developed proof of concept code which could convert blocks to text but the rest is still on my To Do list.
I think it would be better if Debian were to finish what they started.
For instance currently the latest API available is for Android 7.
And the build-tools package they provide is too old for gradle to accept, which is why gradlew tries to download a new one but it can't because the license can't be verified, which is in turn because sdkmanager is missing.
So even from the command line it is impossible to write code for Android on the Pi.

~~

At any rate, I have proven what is possible. I can build APK files from Android source code. This may be useful not just for programming but also for building open source apps e.g. like you find on F-Droid.

More tips:
1. Make sure whatever Linux distro you use is the latest. Older distros are often incompatible with Android Studio.
2. It is far better to build from the command line e.g. ./gradlew build
3. The APK that you can install on your Android device will be the Debug version, not Release.

Return to “Android”