Skip to content

Instantly share code, notes, and snippets.

@autr
Created June 2, 2020 19:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save autr/afe6c783eac0d8e158545f222398d763 to your computer and use it in GitHub Desktop.
Save autr/afe6c783eac0d8e158545f222398d763 to your computer and use it in GitHub Desktop.
Setup guide for Android Studio and OpenFrameworks 0.11.0
# Android Studio with OF 0.11.0
For this guide I am installing Android Studio, Android SDKs and NDKs, and using the Project Generator to generate projects that compile with Android’s build system, gradle.
## Install Android Studio
Install the latest Android Studio from the [download page](https://developer.android.com/studio) (at the time of writing I am using v4.0)
On the splash screen click Next to all standard installation steps
## Install SDK Version 25 + Build Tools
Navigate to Preferences > Appearance & Behaviour > System Settings > Android SDK
Next click “Show Package Details” and then select SDK version 25.
Now tab over to SDK Tools. Keep “Show Package Details” and deselect all SDK Build-Tools except version 25.
If any NDKs are selected, deselect them (in the next step we install it manually).
## Install NDK Version 15
Download and unzip NDK 15 from the [unsupported NDKs download page](https://developer.android.com/ndk/downloads/older_releases?hl=zh-en) - this is an older NDK but currently the only that works with OpenFrameworks.
## Using the Project Generator
Use the project generator for your operating system; it can be found inside the downloads available from openframeworks.cc , or can be compiled via Github.
NB: when using my 3F repos (Autr) you will need a fork of projectGenerator available here. This is identical to the main PG, but adds a feature for conditional includes of addons (and updates Electron to the latest version). In the Releases tab are pre-compiled apps - if you don’t see one for your OS, please compile it and add back into the repo! This will save everyone time in future :)
Inside the project generator, select Android Studio as your build platform. OpenFrameworks has specific example projects for Android which are located in the examples/android folder.
## Gradle + Build Settings
After opening an example project, Gradle may automatically run and give you error messages. Instead link the NDK by editing the local.properties file and adding the line:
```
ndk.dir=/path/to/where/you/unzipped/android-ndk-r15c
```
You can also do the same at any time by clicking File > Project Structure > SDK Location. The SDK location points to a folder of SDK installations, which your `bundle.gradle` selects from. The NDK location points directly to the unzipped folder of NDK 15.
Next test and build the Gradle settings by clicking the icon that looks like a rat hiding behind a diagonal arrow.
If you receive errors about “mips64el-linux-android”, this is likely from the wrong NDK version.
It’s also best to ignore any popups telling you to update Gradle or install updates to Android Studio.
## Compile with Emulator
During installation, a virtual device may have been installed. If not, click the dropdown next to the Run button, and click Open AVD Manager.
Here you can set up a emulated Android phone. For mine, I chose Android Version 10.0 (API 29) and Pixel XL, so that I can fantasise about owning an unnecessarily-large telephone.
When compiling, you may receive error messages about APKs, or the app doesn’t run to begin with. This is most likely from compiling for the wrong processor.
Click Build > Select Build Variant to test out different processors, for example x86, arm64 and arm7.
For my gigantic Pixel XL, it was x86.
## Turn It Off and On Again
Sometimes trashing caches will solve an error. This includes:
Build > Clean
`sudo rm -rf ~/.gradle`
File > Invalidate Caches + Restart
✨🤖✨
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment