O NDK compila o editor, as libraries e o SDL2_ttf/freetype/libpng/openssl estaticos em libmain.so; o SDL2 vai como libSDL2.so e a activity e a org.libsdl.app.SDLActivity do proprio SDL2 (sem Java nosso e sem Gradle). Do SDK so entram aapt2, d8, zipalign, apksigner e o android.jar, porque o NDK sozinho nao monta nem assina um APK. - packaging/android: build.sh (deps + libmain + apk), AndroidManifest, Java e res do SDL2, README e android.mk (make apk, apk-x86_64, apk-arm64, apk-deps, clean-apk). - android_boot.c: cwd para a pasta de arquivos do app, TINYBLOCKS_APPDIR e copia dos assets da DejaVu e do ca-bundle.crt (no Android SDL_GetBasePath() e NULL e /proc/self/exe nao e o do app). - O hint SDL_IOS_ORIENTATIONS (nome historico) mantem o editor em paisagem, junto com o sensorLandscape do manifesto. - gl e vk ficam de fora (como no Windows); a fonte, os certificados e a busca por TINYBLOCKS_APPDIR tambem valem para o AppImage. Testado no emulador Android 35 (x86_64): abre em paisagem, desenha os blocos e roda o programa de exemplo (x vale = 1..5).
91 lines
3.4 KiB
Java
91 lines
3.4 KiB
Java
package org.libsdl.app;
|
|
|
|
import android.content.Context;
|
|
|
|
import java.lang.Class;
|
|
import java.lang.reflect.Method;
|
|
|
|
/**
|
|
SDL library initialization
|
|
*/
|
|
public class SDL {
|
|
|
|
// This function should be called first and sets up the native code
|
|
// so it can call into the Java classes
|
|
public static void setupJNI() {
|
|
SDLActivity.nativeSetupJNI();
|
|
SDLAudioManager.nativeSetupJNI();
|
|
SDLControllerManager.nativeSetupJNI();
|
|
}
|
|
|
|
// This function should be called each time the activity is started
|
|
public static void initialize() {
|
|
setContext(null);
|
|
|
|
SDLActivity.initialize();
|
|
SDLAudioManager.initialize();
|
|
SDLControllerManager.initialize();
|
|
}
|
|
|
|
// This function stores the current activity (SDL or not)
|
|
public static void setContext(Context context) {
|
|
SDLAudioManager.setContext(context);
|
|
mContext = context;
|
|
}
|
|
|
|
public static Context getContext() {
|
|
return mContext;
|
|
}
|
|
|
|
public static void loadLibrary(String libraryName) throws UnsatisfiedLinkError, SecurityException, NullPointerException {
|
|
loadLibrary(libraryName, mContext);
|
|
}
|
|
|
|
public static void loadLibrary(String libraryName, Context context) throws UnsatisfiedLinkError, SecurityException, NullPointerException {
|
|
|
|
if (libraryName == null) {
|
|
throw new NullPointerException("No library name provided.");
|
|
}
|
|
|
|
try {
|
|
// Let's see if we have ReLinker available in the project. This is necessary for
|
|
// some projects that have huge numbers of local libraries bundled, and thus may
|
|
// trip a bug in Android's native library loader which ReLinker works around. (If
|
|
// loadLibrary works properly, ReLinker will simply use the normal Android method
|
|
// internally.)
|
|
//
|
|
// To use ReLinker, just add it as a dependency. For more information, see
|
|
// https://github.com/KeepSafe/ReLinker for ReLinker's repository.
|
|
//
|
|
Class<?> relinkClass = context.getClassLoader().loadClass("com.getkeepsafe.relinker.ReLinker");
|
|
Class<?> relinkListenerClass = context.getClassLoader().loadClass("com.getkeepsafe.relinker.ReLinker$LoadListener");
|
|
Class<?> contextClass = context.getClassLoader().loadClass("android.content.Context");
|
|
Class<?> stringClass = context.getClassLoader().loadClass("java.lang.String");
|
|
|
|
// Get a 'force' instance of the ReLinker, so we can ensure libraries are reinstalled if
|
|
// they've changed during updates.
|
|
Method forceMethod = relinkClass.getDeclaredMethod("force");
|
|
Object relinkInstance = forceMethod.invoke(null);
|
|
Class<?> relinkInstanceClass = relinkInstance.getClass();
|
|
|
|
// Actually load the library!
|
|
Method loadMethod = relinkInstanceClass.getDeclaredMethod("loadLibrary", contextClass, stringClass, stringClass, relinkListenerClass);
|
|
loadMethod.invoke(relinkInstance, context, libraryName, null, null);
|
|
}
|
|
catch (final Throwable e) {
|
|
// Fall back
|
|
try {
|
|
System.loadLibrary(libraryName);
|
|
}
|
|
catch (final UnsatisfiedLinkError ule) {
|
|
throw ule;
|
|
}
|
|
catch (final SecurityException se) {
|
|
throw se;
|
|
}
|
|
}
|
|
}
|
|
|
|
protected static Context mContext;
|
|
}
|