google / watchface

Apache License 2.0
30 stars 3 forks source link

Memory Footprint Evaluator - Cannot invoke "java.io.InputStream.readAllBytes()" #48

Open Chippi opened 2 months ago

Chippi commented 2 months ago

I've been trying to fix this issue for a long time, but I'm out of ideas.

Java version java 17.0.12 2024-07-16 LTS

I've built the memory footprint tool using ./gradlew :memory-footprint:jar.

Then I've tried to run the command for my own watch face format apk and also for samples in https://github.com/android/wear-os-samples/tree/main/WatchFaceFormat. The APK's was built using the command ./gradlew assembleDebug

java -jar ./memory-footprint.jar --watch-face app-debug.apk --schema-version 2 --ambient-limit-mb 10 --active-limit-mb 100 --apply-v1-offload-limitations --estimate-optimization

But I always get this error.

Starting memory footprint test with app-debug.apk
�??�??�??�?? Something went wrong. Please retry or seek assistance.�??�??�??�??
Cannot invoke "java.io.InputStream.readAllBytes()" because the return value of "java.util.zip.ZipFile.getInputStream(java.util.zip.ZipEntry)" is null
java.lang.NullPointerException: Cannot invoke "java.io.InputStream.readAllBytes()" because the return value of "java.util.zip.ZipFile.getInputStream(java.util.zip.ZipEntry)" is null
        at com.google.wear.watchface.dfx.memory.AndroidResourceLoader.lambda$streamFromApkFile$6(AndroidResourceLoader.java:223)
        at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
        at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:179)
        at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:179)
        at java.base/java.util.TreeMap$ValueSpliterator.forEachRemaining(TreeMap.java:3215)
        at java.base/java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:762)
        at java.base/java.util.stream.ReferencePipeline$7$1.accept(ReferencePipeline.java:276)
        at java.base/java.util.AbstractList$RandomAccessSpliterator.forEachRemaining(AbstractList.java:720)
        at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
        at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
        at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
        at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
        at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
        at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:596)
        at com.google.wear.watchface.dfx.memory.WatchFaceData.fromResourcesStream(WatchFaceData.java:91)
        at com.google.wear.watchface.dfx.memory.ResourceMemoryEvaluator.evaluateMemoryFootprint(ResourceMemoryEvaluator.java:116)
        at com.google.wear.watchface.dfx.memory.ResourceMemoryEvaluator.evaluateInHumanReadableMode(ResourceMemoryEvaluator.java:78)
        at com.google.wear.watchface.dfx.memory.ResourceMemoryEvaluator.main(ResourceMemoryEvaluator.java:50)

I cannot figure out what's wrong, I'd appreciate any help.

amoledwatchfaces commented 2 months ago

Try release.aab and then use a memory-footprint for it. I'm not sure if memory-footprint is intended to work with .apk files.

Chippi commented 2 months ago

Try release.aab and then use a memory-footprint for it. I'm not sure if memory-footprint is intended to work with .apk files.

Thanks for your suggestion @amoledwatchfaces.

For me, it didn't work with .aab bundle either.

java -jar ./memory-footprint.jar --watch-face app-release.aab --schema-version 2 --ambient-limit-mb 10 --active-limit-mb 100 --apply-v1-offload-limitations --estimate-optimization

Starting memory footprint test with app-release.aab
Test report:
[MEMORY_FOOTPRINT]: �??FAIL�?? Asset @drawable/minute_hand was not found in the watch face package �??
amoledwatchfaces commented 2 months ago

@Chippi This output is correct. Now you need to resolve issue within your watch face package.

  1. how are you referencing minute_hand in your watchface.xml?
  2. is the minute_hand drawable.xml or png?
  3. is minute_hand resource really in the package?
Chippi commented 2 months ago

@amoledwatchfaces

1.

            <MinuteHand
                height="150"
                pivotX="0.5"
                pivotY="1"
                resource="@drawable/minute_hand"
                width="10"
                x="220"
                y="75" />
  1. It's a png, minute_hand.png placed in the drawable folder

  2. Here's a snapshot of my release aab bundle. image

garanj commented 2 months ago

Is it possible to share the watch face? If you'd prefer not to post it could you share it with me directly? (garan@google.com)

amoledwatchfaces commented 2 months ago

@Chippi

@amoledwatchfaces

1.

            <MinuteHand
                height="150"
                pivotX="0.5"
                pivotY="1"
                resource="@drawable/minute_hand"
                width="10"
                x="220"
                y="75" />

Here, change it to resource="minute_hand" (do not use @drawable) What do you think @garanj ?

garanj commented 2 months ago

Here, change it to resource="minute_hand" (do not use @drawable) What do you think @garanj ?

Yes, good spot @amoledwatchfaces !

Chippi commented 2 months ago

2 days of struggle and you solved it, now it works. Thank you so much! @amoledwatchfaces

I got it from this example. Never realised it was wrong since it works fine on the wear os android emulator. https://github.com/android/wear-os-samples/blob/81c6e335718119f0c762b4c5d42f3d39af461d74/WatchFaceFormat/SimpleAnalog/watchface/src/main/res/raw/watchface.xml

amoledwatchfaces commented 2 months ago

I got it from this example. Never realised it was wrong since it works fine on the wear os android emulator. https://github.com/android/wear-os-samples/blob/81c6e335718119f0c762b4c5d42f3d39af461d74/WatchFaceFormat/SimpleAnalog/watchface/src/main/res/raw/watchface.xml

Perfect!

@garanj maybe I can create PR to remove those @drawable references in the sample?

garanj commented 2 months ago

I got it from this example. Never realised it was wrong since it works fine on the wear os android emulator. https://github.com/android/wear-os-samples/blob/81c6e335718119f0c762b4c5d42f3d39af461d74/WatchFaceFormat/SimpleAnalog/watchface/src/main/res/raw/watchface.xml

Perfect!

@garanj maybe I can create PR to remove those @drawable references in the sample?

Ouch! yes please!

gondwanasoft commented 2 months ago

The tool is documented here to work on .apk but indeed seems to work only on .aab. Could I suggest that the documentation be updated?