This week I started extending DLC Manager to support Play Store.
For handling the downloading of on-demand games, Google has provided two SDKs – one for native (C/C++) and another one for Java/Kotlin.
At first, I was going with native play asset SDK. This SDK consists of some header files (like asset_pack.h
), a .cmake
file, and shared (.so
) and static (.a
) libraries. The .cmake
file has helper functions that add shared/static libraries to the project. Using native play asset SDK caused me some troubles – it required us to include these SDK-specific includes in our build system, which might not be an easy task. However, the major reason I had to switch to using Java SDK was – developers will need to download manually and set up the native SDK. I could probably add the complete SDK itself in our ScummVM repository to save some setup time, but that will be around 400 MB.
So, we decided to take the “easy and maintainable” approach – Just use the Play Asset SDK for Java. There’s no need to manually download the SDK, and we only require to add a new dependency (com.google.android.play:asset-delivery:2.1.0
) in our Android’s build.gradle. Then we can simply use all its functions (like fetch() that requests download) in java. However, it is not that easy since we need to call these functions from C++.
That’s where JNI (Java Native Interface) comes into play. It acts as a bridge between Java code and Native (C/C++) code. Using JNI, we can call any method of an object implemented in Java from C++ or vice versa.
Currently, in Java, I am creating a new AssetPackManager’s object using AssetPackManagerFactory’s getInstance() static method, and from C++, I am trying to call its function using JNI and getting its response. The response would be a jobject
type. Initially, I thought I could handle this returned jobject
in my C++ code (i.e. manipulate it to return the C++ function’s expected return type) but it seems to be difficult. Lephilousophe suggested me to handle those DLC-related functions on Java side first. So, I would have a simple API that I can call from C++ that can return something simple (like String
) instead of something complex (like AssetPackLocation
).
As a side note, there was also some problem with my code that made builds on Mac and Windows fail. I was also able to fix it. But I still need to fix my commit history for failing builds.