Skip to content

Commit 2be6e97

Browse files
committed
fix: Make it work on Android by not using APIs from JVM unavailable to Android.
1 parent 348d007 commit 2be6e97

File tree

1 file changed

+11
-2
lines changed
  • src/main/kotlin/app/revanced/patcher/patch

1 file changed

+11
-2
lines changed

src/main/kotlin/app/revanced/patcher/patch/Patch.kt

+11-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import lanchon.multidexlib2.BasicDexFileNamer
1010
import lanchon.multidexlib2.MultiDexIO
1111
import java.io.File
1212
import java.io.InputStream
13+
import java.lang.reflect.Member
14+
import java.lang.reflect.Method
15+
import java.lang.reflect.Modifier
1316
import java.net.URLClassLoader
1417
import java.util.jar.JarFile
1518
import kotlin.reflect.KProperty
@@ -636,7 +639,7 @@ sealed class PatchLoader private constructor(
636639
*/
637640
private val Class<*>.patchFields
638641
get() = fields.filter { field ->
639-
field.type.isPatch && field.canAccess(null)
642+
field.type.isPatch && field.canAccess()
640643
}.map { field ->
641644
field.get(null) as Patch<*>
642645
}
@@ -646,7 +649,7 @@ sealed class PatchLoader private constructor(
646649
*/
647650
private val Class<*>.patchMethods
648651
get() = methods.filter { method ->
649-
method.returnType.isPatch && method.parameterCount == 0 && method.canAccess(null)
652+
method.returnType.isPatch && method.parameterCount == 0 && method.canAccess()
650653
}.map { method ->
651654
method.invoke(null) as Patch<*>
652655
}
@@ -670,6 +673,12 @@ sealed class PatchLoader private constructor(
670673
it.name != null
671674
}.toSet()
672675
}
676+
677+
private fun Member.canAccess(): Boolean {
678+
if (this is Method && parameterCount != 0) return false
679+
680+
return Modifier.isStatic(modifiers) && Modifier.isPublic(modifiers)
681+
}
673682
}
674683
}
675684

0 commit comments

Comments
 (0)