Skip to content

Commit 7e250a3

Browse files
committed
fixed proguard jdk11 errors
1 parent 42811c5 commit 7e250a3

File tree

1 file changed

+60
-4
lines changed

1 file changed

+60
-4
lines changed

installer/build-release.sh

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,56 @@ if [ ! -f "$PROGUARD_JAR" ]; then
6666
cd "$SCRIPTPATH"
6767
fi
6868

69-
# Create ProGuard config file
70-
cat > target/proguard-release.conf << 'EOF'
69+
# Detect Java version and create appropriate ProGuard config
70+
JAVA_VERSION_STRING=$($JAVA_HOME/bin/java -version 2>&1 | head -1)
71+
echo "Java version string: $JAVA_VERSION_STRING"
72+
73+
# Extract major version number (works for both 1.8.x and 11+ formats)
74+
if [[ $JAVA_VERSION_STRING == *"1.8"* ]]; then
75+
JAVA_VERSION=8
76+
elif [[ $JAVA_VERSION_STRING == *"11."* ]]; then
77+
JAVA_VERSION=11
78+
elif [[ $JAVA_VERSION_STRING == *"17."* ]]; then
79+
JAVA_VERSION=17
80+
elif [[ $JAVA_VERSION_STRING == *"21."* ]]; then
81+
JAVA_VERSION=21
82+
else
83+
# Try to extract version number
84+
JAVA_VERSION=$(echo "$JAVA_VERSION_STRING" | sed -n 's/.*version "\([0-9]*\).*/\1/p')
85+
if [ -z "$JAVA_VERSION" ]; then
86+
JAVA_VERSION=8 # Default fallback
87+
fi
88+
fi
89+
90+
echo "Detected Java major version: $JAVA_VERSION"
91+
92+
# Create ProGuard config file based on Java version
93+
if [ "$JAVA_VERSION" -ge 9 ]; then
94+
# Java 9+ uses modules
95+
cat > target/proguard-release.conf << 'EOF'
96+
-injars installer-fat.jar
97+
-outjars installer-release.jar
98+
99+
-libraryjars <java.home>/jmods/java.base.jmod(!**.jar;!module-info.class)
100+
-libraryjars <java.home>/jmods/java.desktop.jmod(!**.jar;!module-info.class)
101+
-libraryjars <java.home>/jmods/java.xml.jmod(!**.jar;!module-info.class)
102+
-libraryjars <java.home>/jmods/java.logging.jmod(!**.jar;!module-info.class)
103+
-libraryjars <java.home>/jmods/java.prefs.jmod(!**.jar;!module-info.class)
104+
EOF
105+
else
106+
# Java 8 uses rt.jar
107+
cat > target/proguard-release.conf << 'EOF'
71108
-injars installer-fat.jar
72109
-outjars installer-release.jar
73110
74111
-libraryjars <java.home>/lib/rt.jar
75112
-libraryjars <java.home>/lib/jce.jar
76113
-libraryjars <java.home>/lib/jsse.jar
114+
EOF
115+
fi
116+
117+
# Add common ProGuard options to config file
118+
cat >> target/proguard-release.conf << 'EOF'
77119
78120
# Keep main entry point
79121
-keep public class ca.weblite.jdeploy.installer.Main {
@@ -101,6 +143,20 @@ cat > target/proguard-release.conf << 'EOF'
101143
# Keep security/tools classes
102144
-keep class ca.weblite.tools.** { *; }
103145
146+
# Keep JNA classes - they use reflection heavily and have native methods
147+
-keep class com.sun.jna.** { *; }
148+
-keep class * implements com.sun.jna.** { *; }
149+
-keep class * extends com.sun.jna.** { *; }
150+
151+
# Keep JNA callback interfaces
152+
-keep interface * extends com.sun.jna.Callback { *; }
153+
154+
# Keep methods that JNA uses via reflection
155+
-keepclassmembers class * extends com.sun.jna.Structure {
156+
<fields>;
157+
<methods>;
158+
}
159+
104160
# Keep serialization
105161
-keepclassmembers class * implements java.io.Serializable {
106162
static final long serialVersionUID;
@@ -110,8 +166,8 @@ cat > target/proguard-release.conf << 'EOF'
110166
java.lang.Object readResolve();
111167
}
112168
113-
# Keep resources
114-
-adaptresourcefilenames **.properties,**.dll,**.exe,**.png,**.ico,**.jar,**.tiff
169+
# Keep resources including JNA native libraries
170+
-adaptresourcefilenames **.properties,**.dll,**.exe,**.png,**.ico,**.jar,**.tiff,**.so,**.jnilib
115171
-adaptresourcefilecontents **.properties,**.xml
116172
117173
# Don't optimize or obfuscate

0 commit comments

Comments
 (0)