Skip to content

Commit

Permalink
Fixed `org.xml.sax.SAXException: FWK005 parse may not be called while…
Browse files Browse the repository at this point in the history
… parsing` (#16)
  • Loading branch information
gmazzo committed Apr 25, 2024
1 parent 99325f3 commit 7afc016
Showing 1 changed file with 2 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ import javax.xml.xpath.XPathFactory
internal object ManifestReader {
private const val ANDROID_NS = "http://schemas.android.com/apk/res/android"

private val docBuilder = DocumentBuilderFactory.newInstance()
private val docBuilderFactory = DocumentBuilderFactory.newInstance()
.apply { isNamespaceAware = true }
.newDocumentBuilder()

private val xPath = XPathFactory.newInstance().newXPath().apply { namespaceContext = AndroidNamespaceContext }
private val getPackageName = xPath.compile("/manifest/@package")
Expand All @@ -26,7 +25,7 @@ internal object ManifestReader {
private val getExports = xPath.compile("//*[@android:exported='true']")

fun parse(manifest: File): Manifest {
val source = docBuilder.parse(manifest)
val source = docBuilderFactory.newDocumentBuilder().parse(manifest)
val packageName = getPackageName.evaluate(source).takeUnless { it.isBlank() }
val minSDK = getMinSDK.evaluate(source).toIntOrNull()
val targetSDK = getTargetSDK.evaluate(source).toIntOrNull()
Expand Down

0 comments on commit 7afc016

Please sign in to comment.