From a8f3701e92280cc236c61c02fd0cd99a1f5fc9e0 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Tue, 3 Dec 2019 03:46:14 +0300 Subject: [PATCH] android: implement better way to get JNI libraries directory --- android/src/su/xash/engine/XashActivity.java | 29 +++++++++++++++++--- android/src/su/xash/fwgslib/FWGSLib.java | 10 +++++++ 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/android/src/su/xash/engine/XashActivity.java b/android/src/su/xash/engine/XashActivity.java index 380ad3d7..7c566a0f 100644 --- a/android/src/su/xash/engine/XashActivity.java +++ b/android/src/su/xash/engine/XashActivity.java @@ -487,11 +487,24 @@ public class XashActivity extends Activity { mEngineReady = true; } + private boolean setupEnvironment() { Intent intent = getIntent(); - final String enginedir = getFilesDir().getParentFile().getPath() + "/lib"; - + + String enginedir; + + try + { + ApplicationInfo ai = FWGSLib.getApplicationInfo(this, null, 0); + enginedir = ai.nativeLibraryDir; + } + catch(Exception e) + { + e.printStackTrace(); + enginedir = getFilesDir().getParentFile().getPath() + "/lib"; + } + String argv = FWGSLib.getStringExtraFromIntent( intent, "argv", mPref.getString( "argv", "-dev 3 -log" ) ); String gamelibdir = FWGSLib.getStringExtraFromIntent( intent, "gamelibdir", enginedir ); String gamedir = FWGSLib.getStringExtraFromIntent( intent, "gamedir", "valve" ); @@ -519,10 +532,15 @@ public class XashActivity extends Activity { { fGDBSafe = true; Log.e( TAG, "GDBSafe mode enabled!" ); - } + } + + Log.d( TAG, "argv = " + argv ); + Log.d( TAG, "gamedir = " + gamedir ); + Log.d( TAG, "basedir = " + basedir ); + Log.d( TAG, "enginedir = " + enginedir ); + Log.d( TAG, "gamelibdir = " + gamelibdir ); mArgv = argv.split( " " ); - if( mUseRoDir ) { @@ -541,10 +559,12 @@ public class XashActivity extends Activity { setenv( "XASH3D_GAMELIBDIR", gamelibdir, true ); setenv( "XASH3D_GAMEDIR", gamedir, true ); setenv( "XASH3D_EXTRAS_PAK1", getFilesDir().getPath() + "/extras.pak", true ); + Log.d( TAG, "enginepak = " + getFilesDir().getPath() + "/extras.pak" ); String pakfile = intent.getStringExtra( "pakfile" ); if( pakfile != null && pakfile != "" ) setenv( "XASH3D_EXTRAS_PAK2", pakfile, true ); + Log.d( TAG, "pakfile = " + ( pakfile != null ? pakfile : "null" ) ); String[] env = intent.getStringArrayExtra( "env" ); if( env != null ) @@ -553,6 +573,7 @@ public class XashActivity extends Activity { { for( int i = 0; i + 1 < env.length; i += 2 ) { + Log.d(TAG, "extraEnv[" + env[i] + "] = " + env[i + 1]); setenv( env[i], env[i + 1], true ); } } diff --git a/android/src/su/xash/fwgslib/FWGSLib.java b/android/src/su/xash/fwgslib/FWGSLib.java index 944ac6df..ef988381 100644 --- a/android/src/su/xash/fwgslib/FWGSLib.java +++ b/android/src/su/xash/fwgslib/FWGSLib.java @@ -256,5 +256,15 @@ public class FWGSLib } } + public static ApplicationInfo getApplicationInfo(Context ctx, String pkgName, int flags) throws PackageManager.NameNotFoundException + { + PackageManager pm = ctx.getPackageManager(); + + if( pkgName == null ) + pkgName = ctx.getPackageName(); + + return pm.getApplicationInfo(pkgName, flags); + } + public static final int sdk = Integer.valueOf(Build.VERSION.SDK); }