2424import java .util .Arrays ;
2525import java .util .List ;
2626import java .util .Map ;
27- import java .util .concurrent .ExecutionException ;
2827
2928import pojlib .API ;
3029
@@ -78,11 +77,8 @@ public static ArrayList<File> locateLibs(File path) {
7877 return returnValue ;
7978 }
8079
81- public static void initJavaRuntime () {
82- dlopen (findInLdLibPath ("libjli.so" ));
83- if (!dlopen ("libjvm.so" )){
84- dlopen (jvmLibraryPath +"/libjvm.so" );
85- }
80+ public static boolean initJavaRuntime () {
81+ dlopen (findInLdLibPath ("server/libjvm.so" ));
8682 dlopen (findInLdLibPath ("libverify.so" ));
8783 dlopen (findInLdLibPath ("libjava.so" ));
8884 dlopen (findInLdLibPath ("libnet.so" ));
@@ -91,9 +87,15 @@ public static void initJavaRuntime() {
9187 dlopen (findInLdLibPath ("libawt_headless.so" ));
9288 dlopen (findInLdLibPath ("libfreetype.so" ));
9389 dlopen (findInLdLibPath ("libfontmanager.so" ));
94- for (File f : locateLibs (new File (runtimeDir + "/lib" ))) {
95- dlopen (f .getAbsolutePath ());
90+ dlopen (findInLdLibPath ("libjli.so" ));
91+
92+ String dlerr = dlerror ();
93+ if (dlerr .contains (runtimeDir )) {
94+ Logger .getInstance ().appendToLog ("ERROR! Could not dlopen libraries! " + dlerr );
95+ return false ;
9696 }
97+
98+ return true ;
9799 }
98100
99101 public static void redirectAndPrintJRELog () {
@@ -154,11 +156,15 @@ public static void setJavaEnvironment(Activity activity, MinecraftInstances.Inst
154156 //envMap.put("APP_HOME", Constants.USER_HOME);
155157 envMap .put ("TMPDIR" , activity .getCacheDir ().getAbsolutePath ());
156158 envMap .put ("VR_MODEL" , API .model );
157- envMap .put ("POJLIB_RENDERER" , "LightThinWrapper" );
159+ envMap .put ("POJLIB_RENDERER" , "MobileGLUES" );
160+ envMap .put ("MG_DIR_PATH" , activity .getFilesDir () + "/mg" );
158161
159162 envMap .put ("LD_LIBRARY_PATH" , LD_LIBRARY_PATH );
160163 envMap .put ("PATH" , activity .getFilesDir () + "/runtimes/JRE/bin:" + Os .getenv ("PATH" ));
161164
165+ File mg = new File (activity .getFilesDir () + "/mg" );
166+ mg .mkdirs ();
167+
162168 File customEnvFile = new File (Constants .USER_HOME , "custom_env.txt" );
163169 if (customEnvFile .exists () && customEnvFile .isFile ()) {
164170 BufferedReader reader = new BufferedReader (new FileReader (customEnvFile ));
@@ -184,18 +190,21 @@ public static void setJavaEnvironment(Activity activity, MinecraftInstances.Inst
184190 }
185191
186192 // Called before game launch to ensure all files are present and correct
187- public static void prelaunchCheck (Activity activity , MinecraftInstances .Instance instance ) throws IOException , ExecutionException , InterruptedException {
193+ public static boolean prelaunchCheck (Activity activity , MinecraftInstances .Instance instance ) throws Throwable {
194+ runtimeDir = activity .getFilesDir () + "/runtimes/JRE" ;
195+ JREUtils .relocateLibPath (activity );
196+ setJavaEnvironment (activity , instance );
197+
188198 UnityPlayerActivity .installLWJGL (activity );
189199 Installer .installJVM (activity );
190200 Installer .installClient (MinecraftMeta .getVersionInfo (instance .versionName ), Constants .USER_HOME ).get ();
191201 Installer .installLibraries (MinecraftMeta .getVersionInfo (instance .versionName ), Constants .USER_HOME ).get ();
192202 Installer .installAssets (MinecraftMeta .getVersionInfo (instance .versionName ), Constants .USER_HOME ).get ();
203+
204+ return initJavaRuntime ();
193205 }
194206
195207 public static int launchJavaVM (final Activity activity , final List <String > JVMArgs , MinecraftInstances .Instance instance ) throws Throwable {
196- JREUtils .relocateLibPath (activity );
197- setJavaEnvironment (activity , instance );
198-
199208 final String graphicsLib = loadGraphicsLibrary ();
200209 List <String > userArgs = getJavaArgs (activity , instance );
201210
@@ -209,12 +218,10 @@ public static int launchJavaVM(final Activity activity, final List<String> JVMAr
209218 ActivityManager .MemoryInfo ami = new ActivityManager .MemoryInfo ();
210219 manager .getMemoryInfo (ami );
211220 long availMem = (ami .availMem -ami .threshold )/(1024 *1024 );
212- availMem *= 0.8 ; // Lossy, but should work...
213221 long allocatedRam = Math .max (availMem , 1536 );
214222
215223 Logger .getInstance ().appendToLog ("QuestCraft: Setting JVM memory to " + allocatedRam + "MB" );
216224
217-
218225 userArgs .add ("-Xms" + 1024 + "M" );
219226 userArgs .add ("-Xmx" + allocatedRam + "M" );
220227 }
@@ -242,9 +249,6 @@ public static int launchJavaVM(final Activity activity, final List<String> JVMAr
242249 userArgs .addAll (JVMArgs );
243250 System .out .println (JVMArgs );
244251
245- runtimeDir = activity .getFilesDir () + "/runtimes/JRE" ;
246-
247- initJavaRuntime ();
248252 chdir (instance .gameDir );
249253 userArgs .add (0 ,"java" ); //argv[0] is the program name according to C standard.
250254
@@ -366,7 +370,7 @@ public static ArrayList<String> parseJavaArguments(String args){
366370 * @return The name of the loaded library
367371 */
368372 public static String loadGraphicsLibrary (){
369- return "libltw .so" ;
373+ return "libmobileglues .so" ;
370374 }
371375
372376 public static native long getEGLContextPtr ();
@@ -375,6 +379,7 @@ public static String loadGraphicsLibrary(){
375379 public static native int chdir (String path );
376380 public static native void logToLogger (final Logger logger );
377381 public static native boolean dlopen (String libPath );
382+ public static native String dlerror ();
378383 public static native void setLdLibraryPath (String ldLibraryPath );
379384
380385 static {
0 commit comments