diff options
author | Sven Gothel <[email protected]> | 2011-08-05 22:13:11 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2011-08-05 22:13:11 +0200 |
commit | d63ca3ad5d2acf20a8ff8f27778ef084b305260c (patch) | |
tree | 8b8335da71d1fd5a2976d65e2b7e538cbe2cb43a /src/android | |
parent | 0f8a1a0d7c6ea2f712f902b57e37cbedc46b1387 (diff) |
Android hacks: ClassLoaderUtil (vie Dex.., w/ native libs) ; Merged big jar ; eglGetDevice(0) fails
Diffstat (limited to 'src/android')
-rw-r--r-- | src/android/com/jogamp/android/launcher/ClassLoaderUtil.java | 82 | ||||
-rw-r--r-- | src/android/com/jogamp/android/launcher/NEWTLauncherVersionActivity.java | 40 |
2 files changed, 90 insertions, 32 deletions
diff --git a/src/android/com/jogamp/android/launcher/ClassLoaderUtil.java b/src/android/com/jogamp/android/launcher/ClassLoaderUtil.java new file mode 100644 index 000000000..746fad745 --- /dev/null +++ b/src/android/com/jogamp/android/launcher/ClassLoaderUtil.java @@ -0,0 +1,82 @@ +/** + * Copyright 2011 JogAmp Community. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ + +package com.jogamp.android.launcher; + +import java.io.File; + +import android.content.Context; +import android.content.pm.PackageManager; +import android.util.Log; +import dalvik.system.DexClassLoader; + +public class ClassLoaderUtil { + private static final String TAG = "JogampClassLoader"; + + public static final String packageGlueGen = "com.jogamp.common"; + public static final String packageJogl = "javax.media.opengl"; + + public static final String dexPathName= "jogampDex"; + public static final String libPathName = "/data/data/com.jogamp.common/lib/:/data/data/javax.media.opengl/lib/"; + + public static synchronized ClassLoader createJogampClassLoaderSingleton(Context ctx, boolean debugOn) { + Log.d(TAG, "S"); + + if(debugOn) { + System.setProperty("jogl.debug", "all"); + System.setProperty("jogamp.debug.JNILibLoader", "true"); + System.setProperty("jogamp.debug.NativeLibrary", "true"); + } + + String apkGlueGen = null; + String apkJogl = null; + + try { + apkGlueGen = ctx.getPackageManager().getApplicationInfo(packageGlueGen,0).sourceDir; + apkJogl = ctx.getPackageManager().getApplicationInfo(packageJogl,0).sourceDir; + } catch (PackageManager.NameNotFoundException e) { + Log.d(TAG, "error: "+e, e); + } + if(null == apkGlueGen || null == apkJogl) { + Log.d(TAG, "not found: gluegen <"+apkGlueGen+">, jogl <"+apkJogl+">"); + return null; + } + + final String cp = apkGlueGen + ":" + apkJogl ; + Log.d(TAG, "cp: " + cp); + + final File dexPath = ctx.getDir(dexPathName, Context.MODE_WORLD_READABLE); + + ClassLoader cl = new DexClassLoader(cp, dexPath.getAbsolutePath(), libPathName, ctx.getClassLoader()); + Log.d(TAG, "cl: " + cl); + // setAPKClassLoader(dexLoader); + + return cl; + } + +} diff --git a/src/android/com/jogamp/android/launcher/NEWTLauncherVersionActivity.java b/src/android/com/jogamp/android/launcher/NEWTLauncherVersionActivity.java index 468beed0b..c07b502fb 100644 --- a/src/android/com/jogamp/android/launcher/NEWTLauncherVersionActivity.java +++ b/src/android/com/jogamp/android/launcher/NEWTLauncherVersionActivity.java @@ -29,6 +29,7 @@ package com.jogamp.android.launcher; import java.lang.reflect.Method; +import dalvik.system.DexClassLoader; import dalvik.system.PathClassLoader; import android.app.Activity; @@ -46,46 +47,21 @@ public class NEWTLauncherVersionActivity extends Activity { Log.d(TAG, "onCreate - S"); super.onCreate(savedInstanceState); - String packageGlueGen = "com.jogamp.common"; - String apkGlueGen = null; - String packageJogl = "javax.media.opengl"; - String apkJogl = null; - String clazzMDName= "jogamp.newt.driver.android.MD"; - Method mdGetInfo = null; - - try { - apkGlueGen = getPackageManager().getApplicationInfo(packageGlueGen,0).sourceDir; - apkJogl = getPackageManager().getApplicationInfo(packageJogl,0).sourceDir; - } catch (PackageManager.NameNotFoundException e) { - Log.d(TAG, "error: "+e, e); - } - if(null == apkGlueGen || null == apkJogl) { - Log.d(TAG, "not found: gluegen <"+apkGlueGen+">, jogl <"+apkJogl+">"); - } else { - String cp = apkGlueGen + ":" + apkJogl ; - Log.d(TAG, "cp: " + cp); - - // add path to apk that contains classes you wish to load - PathClassLoader pathClassLoader = new dalvik.system.PathClassLoader( - cp, - ClassLoader.getSystemClassLoader()); - + String mdInfo = null; + + ClassLoader cl = ClassLoaderUtil.createJogampClassLoaderSingleton(this, true); + if(null != cl) { try { - Class clazzMD= Class.forName(clazzMDName, true, pathClassLoader); + Class clazzMD= Class.forName(clazzMDName, true, cl); Log.d(TAG, "MD: "+clazzMD); - mdGetInfo = clazzMD.getMethod("getInfo"); + Method mdGetInfo = clazzMD.getMethod("getInfo"); + mdInfo = (String) mdGetInfo.invoke(null); } catch (Exception e) { Log.d(TAG, "error: "+e, e); } } - String mdInfo = null; - try { - mdInfo = (String) mdGetInfo.invoke(null); - } catch (Exception e) { - Log.d(TAG, "error: "+e, e); - } tv = new TextView(this); if(null != mdInfo) { tv.setText(mdInfo); |