Looking for some guidance on how Android Apps are built


#1

I’m trying to wrap my head around how Cinder is building the Android apps and I’m pretty confused
It seems like it’s doing some really wacky non-standard stuff.
Is there documentation apart from the wiki?

I get how the libcinder.a is generated with the NDK tools in Cinder/proj/android/
(it looks like some version of the old android-cmake)
It’s basically a fancy toolchain file

But what I don’t get what’s happening afterwards (granted I’m just working off of the Tutorials on google’s webpages)
Looking at
Cinder/samples/BasicApp/androidstudio/BasicApp/build.gradle
Cinder/samples/BasicApp/androidstudio/BasicApp/app/build.gradle

It seems to be running this binary we just have floating around in the repo
Cinder/tools/android/CinderAppBuild/repo/cinderappbuild-1.0.jar

And then there is this strange cinder {..} block which I guess is doing the building of the App?

It doesn’t seem to conform to the old ndk-build tool, nor the new CMake method. With the latest versions of Android you can simply have gradle files point at CMake files and have it build everything for you - so I feel like it shouldn’t be this messy. But I could be really missing what’s going on.

I’d be willing to help clean it up, but I’d need a few pointers to get started - b/c I don’t know what I’m looking at :slight_smile:


Android Building on Windows Host
#2

It seems you have an impression that the Android build process is broken. Unless something drastically changed since I last touched the Android branch, I have to disagree. Android branch is missing some features, compared to the ios one, but I remember getting it build my app in an hour or so starting from scratch and having no experience with Android. If you post more specific questions and info (error logs), maybe somebody could help to get you started.

008


#3

For background information, the android build configuration was written when Android Studio barely / incompletely supported building C++ directly with gradle. So Hai (@chaoticbob) wrote a gradle plug-in that would overcome the limitations and get things rolling. I believe the intention has always been that it would go away once Android Studio matured enough to build cinder apps as they are meant to be - primarily C++ with java as needed for communication with the java only portions of the android sdk. As you can see from this fairly old and likely outdated wiki page, latest Android Studio was at version 1.3 when the port was initially written, whereas I’m seeing here that 2.3 was just released.

Moving to present day, most of the initial work for the android build system hasn’t seen updates as the authors are working on other platforms at the moment. Before we released 0.9.1, we made a significant effort to unify the cmake build system across all platforms and while this happened for android as well, it didn’t receive much testing which is why it remains considered at an ‘experimental’ state - the C++ side is fine and known to work, but the build configuration, especially concerning gradle, is known to need updates. This could use some support from skilled programmers working with android on a regular basis. @eight_io, It’s great to hear you’re having success with it in the current form, I was under the impression that there are at least a couple path issues that need to be resolved in master branch.

I also think that @Andrea has made some progress in updating some of these configuration files, as mentioned on this forum (see here) - I hope we can get this integrated at some point.

cheers,
Rich


#4

Thanks for the archeological context @rich.e :grin: That’s exactly what I was looking for.
Digging through the configurations and scripts I figured the history was something like that :relaxed:

Like you said, the CMake system in Cinder is already set up to be built with the Android NDK, so I’m going to muck around with gradle and try to get it to build using CMake directly (instead of linking to a “prebuilt” libcinder). I’ll let you guys know if I make any good progress, but on the face of it - it shouldn’t be too hard b/c the NativeActivity is written and everything is there. Unfortunately I can’t see the internals of cinderappbuild-1.0.jar, but hopefully it’s not doing any magic


#5

Yes I’ve been reading about Android Studio’s new CMake support (here and here), very promising! Actually, in order to rebuild libcinder entirely for android, the current setup requires you to do two steps - 1) build libcinder.a using cmake from the command line and 2) open up the android studio / gradle project (in this folder) and build the libcinder-[debug/release].aar files that end up here. This second step is not currently necessary because we’ve checked in the .aar binary files, but obviously this isn’t ideal.

Which got me thinking, would it be possible to combine both these steps into the Android Studio build process now? Initially I had hoped we could build the .aar files from the main cmake file, but seeing that Android Studio now has decent support for hybrid java + C++ projects using CMake, I wonder if we couldn’t manage both from Android Studio. It’d sure be nice to be able to remove those .aar files, as currently it’s a bit obscure how you need to go about modifying libcinder’ java stuff.

Unfortunately I can’t see the internals of cinderappbuild-1.0.jar, but hopefully it’s not doing any magic

Hm, not sure what cinderappbuild-1.0.jar is, that might be something related to the custom gradle plug-in? In any event, might be best to start with a fresh java + C++ template from the latest Android Studio version, and then reference the existing CMakeLists.txt files that come with the samples, for example. To me that’d be ideal setup for android user apps, anyway. And, fingers crossed, debugging C++ with LLDB would finally work.


Android build on macOS
#6

Thank you so much @rich.e , and sorry for the late reply

Yeah, those are the links that got me started on this rabbit hole.
This one too provides a bit more information

Thanks for pointing out the “proj/android/libcinder_java/” directory. I’ve been trying to twist gradle’s arms to build with Cmake, but I think it’s this directory where there is a fundamental incompatibility with the new build system. Reading the documentation it sounds like Android Studio with the new CMake support really requires all the C++ code globbed into one lib that is linked to in-one-go. So not a libcinder.a, but a libcinder_and_your_app.a . But my understanding is that right now we do it in 2 separate steps. First the “proj/android/libcinder_java/” stuff builds libcinder with some Java glue and then the app’s C++ is built with some Java glue - and then finally we stick it all together. On a high level this actually seems more sensible, but it actually ends up not working with the system (or maybe I’m just not doing it right :slight_smile:)

So I think the Java stuff needs to be rewritten and greatly simplified. Gradle should just include the CMakeLists.txt for the app (which will in turn include(/path/to/libcinder’s/CMakeLists.txt/and/any/other/cmakebuilt/libraries/it/uses) ). This all gets built with the NDK tools into one fat lib and then Android Studio would do all the NDK/JNI hooks to /cinder/android/app/CinderNativeActivity.cpp (b/c that remains the entry point to the app)

Unfortunately this is a bit beyond me b/c I haven’t written Java in more than 5 years haha. I’ll try poke around a bit more, but hopefully someone a little more knowledgeable about the Android ecosystem can clean this up. It’s a bit of a shame b/c 95% of the work has already been done and all the piece are there :yum:


#7

Hi geokan,

did you get anywhere with that? Did you narrow down the problem at all? I though I might have a stab.


#8

No, sorry. I didn’t know enough about Android development to finish it and I moved on to other projects. If you make any progress please let me know :slight_smile: I’d really be interested in having this working