Skip to content

Commit

Permalink
try add jre21 support
Browse files Browse the repository at this point in the history
revert if I can't get this working
  • Loading branch information
SolDev69 committed Apr 3, 2024
1 parent 39ed02c commit 4619843
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 2 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ jobs:
branch: buildjre17
name: jre17-pojav

- name: Get JRE21
uses: dawidd6/action-download-artifact@v2
with:
workflow: build.yml
path: app_pojavlauncher/src/main/assets/components/jre-new
workflow_conclusion: success
repo: PojavLauncherTeam/android-openjdk-build-multiarch
branch: buildjre21
name: jre21-pojav

- uses: gradle/gradle-build-action@v2
with:
gradle-version: 7.6.1
Expand Down
99 changes: 99 additions & 0 deletions app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/JRE21Util.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package net.kdt.pojavlaunch;

import static net.kdt.pojavlaunch.Architecture.archAsString;

import android.app.Activity;
import android.content.res.AssetManager;
import android.util.Log;

import net.kdt.pojavlaunch.multirt.MultiRTUtils;
import net.kdt.pojavlaunch.multirt.Runtime;
import net.kdt.pojavlaunch.value.launcherprofiles.LauncherProfiles;
import net.kdt.pojavlaunch.value.launcherprofiles.MinecraftProfile;

import java.io.IOException;

public class JRE21Util {
public static final String NEW_JRE_NAME = "Internal-21";

public static boolean checkInternalNewJre(AssetManager assetManager) {
String launcher_jre21_version;
String installed_jre21_version = MultiRTUtils.__internal__readBinpackVersion(NEW_JRE_NAME);
try {
launcher_jre21_version = Tools.read(assetManager.open("components/jre-new-21/version"));
}catch (IOException exc) {
//we don't have a runtime included!
return installed_jre21_version != null; //if we have one installed -> return true -> proceed (no updates but the current one should be functional)
//if we don't -> return false -> Cannot find compatible Java runtime
}
if(!launcher_jre21_version.equals(installed_jre21_version)) // this implicitly checks for null, so it will unpack the runtime even if we don't have one installed
return unpackjre21(assetManager, launcher_jre21_version);
else return true;
}

private static boolean unpackjre21(AssetManager assetManager, String rt_version) {
try {
MultiRTUtils.installRuntimeNamedBinpack(
assetManager.open("components/jre-new-21/universal.tar.xz"),
assetManager.open("components/jre-new-21/bin-" + archAsString(Tools.DEVICE_ARCHITECTURE) + ".tar.xz"),
"Internal-21", rt_version);
MultiRTUtils.postPrepare("Internal-21");
return true;
}catch (IOException e) {
Log.e("jre21Auto", "Internal JRE unpack failed", e);
return false;
}
}
public static boolean isInternalNewJRE(String s_runtime) {
Runtime runtime = MultiRTUtils.read(s_runtime);
if(runtime == null) return false;
return NEW_JRE_NAME.equals(runtime.name);
}

/** @return true if everything is good, false otherwise. */
public static boolean installNewJreIfNeeded(Activity activity, JMinecraftVersionList.Version versionInfo) {
//Now we have the reliable information to check if our runtime settings are good enough
if (versionInfo.javaVersion == null || versionInfo.javaVersion.component.equalsIgnoreCase("jre-legacy"))
return true;

LauncherProfiles.load();
MinecraftProfile minecraftProfile = LauncherProfiles.getCurrentProfile();

String selectedRuntime = Tools.getSelectedRuntime(minecraftProfile);

Runtime runtime = MultiRTUtils.read(selectedRuntime);
if (runtime.javaVersion >= versionInfo.javaVersion.majorVersion) {
return true;
}

String appropriateRuntime = MultiRTUtils.getNearestJreName(versionInfo.javaVersion.majorVersion);
if (appropriateRuntime != null) {
if (jre21Util.isInternalNewJRE(appropriateRuntime)) {
jre21Util.checkInternalNewJre(activity.getAssets());
}
minecraftProfile.javaDir = Tools.LAUNCHERPROFILES_RTPREFIX + appropriateRuntime;
LauncherProfiles.load();
} else {
if (versionInfo.javaVersion.majorVersion <= 21) { // there's a chance we have an internal one for this case
if (!jre21Util.checkInternalNewJre(activity.getAssets())){
showRuntimeFail(activity, versionInfo);
return false;
} else {
minecraftProfile.javaDir = Tools.LAUNCHERPROFILES_RTPREFIX + jre21Util.NEW_JRE_NAME;
LauncherProfiles.load();
}
} else {
showRuntimeFail(activity, versionInfo);
return false;
}
}

return true;
}

private static void showRuntimeFail(Activity activity, JMinecraftVersionList.Version verInfo) {
Tools.dialogOnUiThread(activity, activity.getString(R.string.global_error),
activity.getString(R.string.multirt_nocompatiblert, verInfo.javaVersion.majorVersion));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public static void launchMinecraft(final AppCompatActivity activity, MinecraftAc
if(Architecture.is32BitsDevice())
{
LifecycleAwareAlertDialog.DialogCreator dialogCreator = (dialog, builder) ->
builder.setMessage("Warning: using a 32bit device is no longer supported in modern versions, updates after 1.20.4 (24w13a/24w14potato) will not work!")
builder.setMessage("Warning: using a 32bit device is no longer supported in modern versions, updates after 1.20.4 (24w13a/24w14potato) may not work as intended!")
.setPositiveButton(android.R.string.ok, (d, w)->{});

if(LifecycleAwareAlertDialog.haltOnDialog(activity.getLifecycle(), activity, dialogCreator)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import net.kdt.pojavlaunch.JAssets;
import net.kdt.pojavlaunch.JMinecraftVersionList;
import net.kdt.pojavlaunch.JRE17Util;
import net.kdt.pojavlaunch.JRE21Util;
import net.kdt.pojavlaunch.R;
import net.kdt.pojavlaunch.Tools;
import net.kdt.pojavlaunch.mirrors.DownloadMirror;
Expand Down Expand Up @@ -203,7 +204,7 @@ private boolean downloadAndProcessMetadata(Activity activity, JMinecraftVersionL
throw new IOException("Unable to read Version JSON for version " + versionName);
}

if(activity != null && !JRE17Util.installNewJreIfNeeded(activity, verInfo)){
if(activity != null && !JRE17Util.installNewJreIfNeeded(activity, verInfo) && !JRE21Util.installNewJreIfNeeded(activity, verInfo)){
return false;
}

Expand Down
1 change: 1 addition & 0 deletions app_pojavlauncher/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@
<string name="preference_vsync_in_zink_title">Allow V-Sync with Zink</string>
<string name="preference_vsync_in_zink_description">Allows the launcher to use internal system APIs to enable V-Sync for Zink. Turn this off if your launcher suddenly crashes with Zink after a system update.</string>
<string name="exception_failed_to_unpack_jre17">Failed to install JRE 17</string>
<string name="exception_failed_to_unpack_jre21">Failed to install JRE 21</string>
<string name="newdl_starting">Reading game metadata…</string>
<string name="newdl_downloading_metadata">Downloading game metadata (%s)</string>
<string name="newdl_downloading_game_files">Downloading game files… (%d/%d, %.2f MB)</string>
Expand Down

0 comments on commit 4619843

Please sign in to comment.