kylecorry31/ML4K-AI-Extension

Requires Android Oreo or later

dalelane opened this issue · 10 comments

Tried running something on a second-hand Android device I was able to get hold of, and it crashed with:

12-09 17:03:16.756 11271 11443 E AndroidRuntime: FATAL EXCEPTION: Thread-8
12-09 17:03:16.756 11271 11443 E AndroidRuntime: Process: edu.mit.appinventor.aicompanion3, PID: 11271
12-09 17:03:16.756 11271 11443 E AndroidRuntime: java.lang.NoSuchMethodError: No virtual method toPath()Ljava/nio/file/Path; in class Ljava/io/File; or its super classes (declaration of 'java.io.File' appears in /system/framework/core-oj.jar)
12-09 17:03:16.756 11271 11443 E AndroidRuntime: 	at com.kylecorry.ml4k.ML4K.getImageData(ML4K.java:310)
12-09 17:03:16.756 11271 11443 E AndroidRuntime: 	at com.kylecorry.ml4k.ML4K.access$100(ML4K.java:39)
12-09 17:03:16.756 11271 11443 E AndroidRuntime: 	at com.kylecorry.ml4k.ML4K$1.run(ML4K.java:86)
12-09 17:03:16.756 11271 11443 E AndroidRuntime: 	at java.lang.Thread.run(Thread.java:761)
12-09 17:03:16.766   548  1332 W ActivityManager:   Force finishing activity edu.mit.appinventor.aicompanion3/.Screen1

According to threads like osiegmar/FastCSV#16 and https://bitbucket.org/ijabz/jaudiotagger/issues/113/cannot-run-under-android-could-not-find it's because that method isn't available on the version of Android that I have (Android 7.1).

I don't know if there is a way to code around this. If not, it might be worth a warning somewhere to say that the image block needs Android 8 or later.

I think I might be able to get around this.

So I did some research into this, and I can get by the toPath() issue, but I need the Base64 encoder for images, which was added in Android 8 as well (https://developer.android.com/reference/java/util/Base64). I could write my own base64 encoder in the future (I've written one before and it was slow - don't think I have the code for it anymore).

I am on break from college in a week, so I will add a workaround then. (Android allows you to check the API version and I can run the efficient code on new devices and the custom code on old devices)

@kylecorry31 That's awesome news, thanks!

@dalelane This issue should now be resolved with the latest release (and the master branch's release/ folder has been updated)

Could you test the latest version on the Android 7.1 device for me? I am going to mark this issue as closed for now, as it appears all of the offending code has backfills now.

@kylecorry31 Thanks for doing this! (I've not had a chance to test it yet, but will let you know when I do)

@kylecorry31 Sorry for taking so long to get to this - Christmas got in the way :-)

I'm still not having much luck. I was trying to use an image classifier.

If I use the Camera, then the data seems to be missing from the classification request. (I just got a HTTP 400 Missing data error response)

If I use the Image Picker, I get a crash

AndroidRuntime: FATAL EXCEPTION: Thread-9
AndroidRuntime: Process: edu.mit.appinventor.aicompanion3, PID: 4426
AndroidRuntime: java.lang.NoSuchMethodError: No static method toUnsignedInt(B)I in class Ljava/lang/Byte; or its super classes (declaration of 'java.lang.Byte' appears in /system/framework/core-oj.jar)
AndroidRuntime: 	at com.kylecorry.ml4k.ML4K$Base64Encoder.encode(ML4K.java:452)
AndroidRuntime: 	at com.kylecorry.ml4k.ML4K.getImageData(ML4K.java:320)
AndroidRuntime: 	at com.kylecorry.ml4k.ML4K.access$100(ML4K.java:40)
AndroidRuntime: 	at com.kylecorry.ml4k.ML4K$1.run(ML4K.java:91)
AndroidRuntime: 	at java.lang.Thread.run(Thread.java:761)

Have you tried doing a project using the Camera, without needing to take a picture and then go via the Image Picker?

That's a sort of side issue I guess though, as it looks like the Base64-encoding would be a problem either way.

Hello, thanks for the update. I have attached an extension file which should fix that "no static method" issue - please let me know if that fixes the issue.
ML4K.zip

I will look into the camera issue, thanks

@kylecorry31 That did the trick with the Image Picker - thanks!

Awesome, thanks!