diff --git a/play-validations/memory-footprint/build.gradle b/play-validations/memory-footprint/build.gradle index 9b0766b..5569e4b 100644 --- a/play-validations/memory-footprint/build.gradle +++ b/play-validations/memory-footprint/build.gradle @@ -27,7 +27,7 @@ dependencies { implementation 'com.google.code.gson:gson:2.11.0' implementation 'com.google.guava:guava:33.3.1-jre' implementation 'commons-cli:commons-cli:1.5.0' - implementation 'com.android.tools.apkparser:binary-resources:31.7.3' + implementation 'com.android.tools.apkparser:binary-resources:32.2.1' implementation 'com.github.xgouchet:AXML:v1.0.1' implementation("com.android.tools.build:aapt2-proto:8.7.3-12006047") implementation("com.google.protobuf:protobuf-java:4.29.3") diff --git a/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/AndroidResourceLoader.kt b/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/AndroidResourceLoader.kt index 9844c6d..9b349eb 100644 --- a/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/AndroidResourceLoader.kt +++ b/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/AndroidResourceLoader.kt @@ -17,9 +17,9 @@ package com.google.wear.watchface.dfx.memory import com.google.common.io.Files -import com.google.devrel.gmscore.tools.apk.arsc.BinaryResourceFile -import com.google.devrel.gmscore.tools.apk.arsc.BinaryResourceValue +import com.google.devrel.gmscore.tools.apk.arsc.ResourceFile import com.google.devrel.gmscore.tools.apk.arsc.ResourceTableChunk +import com.google.devrel.gmscore.tools.apk.arsc.ResourceValue import java.io.IOException import java.io.InputStream import java.nio.file.Path @@ -116,9 +116,9 @@ object AndroidResourceLoader { return typeChunks .flatMap { it.entries.values.asSequence() } .filter { RESOURCE_TYPES.contains(it.typeName()) } - .filter { it.value().type() == BinaryResourceValue.Type.STRING } + .filter { it.value()?.type() == ResourceValue.Type.STRING } .map { entry -> - val path = stringPool.getString(entry.value().data()) + val path = stringPool.getString(entry.value()!!.data()) val data = apkFile.getInputStream(ZipEntry(path)).readBytes() AndroidResource( entry.parent().typeName, @@ -132,7 +132,7 @@ object AndroidResourceLoader { @JvmStatic fun loadResourceTable(inputStream: InputStream): ResourceTableChunk { - val resources = BinaryResourceFile.fromInputStream(inputStream) + val resources = ResourceFile.fromInputStream(inputStream) val chunks = resources.chunks if (chunks.isEmpty() || chunks[0] !is ResourceTableChunk) { throw IOException("no res table chunk") diff --git a/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/AndroidResourceResolver.kt b/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/AndroidResourceResolver.kt index b61f75b..955b280 100644 --- a/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/AndroidResourceResolver.kt +++ b/play-validations/memory-footprint/src/main/java/com/google/wear/watchface/dfx/memory/AndroidResourceResolver.kt @@ -17,8 +17,9 @@ package com.google.wear.watchface.dfx.memory import com.android.aapt.Resources -import com.google.devrel.gmscore.tools.apk.arsc.BinaryResourceValue import com.google.devrel.gmscore.tools.apk.arsc.ResourceTableChunk +import com.google.devrel.gmscore.tools.apk.arsc.ResourceValue +import java.lang.RuntimeException import java.nio.file.Path import javax.xml.parsers.DocumentBuilderFactory @@ -70,18 +71,18 @@ object AndroidResourceResolver { visited: Set ): String { if (visited.contains(resourceId)) { - throw java.lang.RuntimeException("Cyclic resource reference detected for ID $resourceId") + throw RuntimeException("Cyclic resource reference detected for ID $resourceId") } val packageId = (resourceId ushr 24) and 0xFF val typeId = (resourceId ushr 16) and 0xFF val entryId = resourceId and 0xFFFF val pkg = resourceTable.packages.firstOrNull { it.id == packageId } - ?: throw java.lang.RuntimeException("Package not found for ID $packageId") + ?: throw RuntimeException("Package not found for ID $packageId") val typeChunks = pkg.typeChunks.filter { it.id == typeId } if (typeChunks.isEmpty()) { - throw java.lang.RuntimeException("Type not found for ID $typeId") + throw RuntimeException("Type not found for ID $typeId") } val newVisited = visited + resourceId @@ -91,21 +92,21 @@ object AndroidResourceResolver { if (entry != null) { val value = entry.value() if (value != null) { - if (value.type() == BinaryResourceValue.Type.INT_DEC || - value.type() == BinaryResourceValue.Type.INT_HEX) { + if (value.type() == ResourceValue.Type.INT_DEC || + value.type() == ResourceValue.Type.INT_HEX) { return value.data().toString() - } else if (value.type() == BinaryResourceValue.Type.STRING) { + } else if (value.type() == ResourceValue.Type.STRING) { return resourceTable.stringPool.getString(value.data()) - } else if (value.type() == BinaryResourceValue.Type.REFERENCE || - value.type() == BinaryResourceValue.Type.DYNAMIC_REFERENCE) { + } else if (value.type() == ResourceValue.Type.REFERENCE || + value.type() == ResourceValue.Type.DYNAMIC_REFERENCE) { return resolveResourceValue(resourceTable, value.data(), newVisited) } else { - throw java.lang.RuntimeException("Unsupported resource value type: ${value.type()}") + throw RuntimeException("Unsupported resource value type: ${value.type()}") } } } } - throw java.lang.RuntimeException("Entry not found for ID $entryId") + throw RuntimeException("Entry not found for ID $entryId") } @JvmStatic