I tried several methods to deploy the tflite model on android, flutter, kotlin, etc, but andriod app keeps crashing when I want to make predictions. This was an error I got trying out the object detection codelab:
2022-01-01 15:52:55.965 2971-3034/org.tensorflow.codelabs.objectdetection E/AndroidRuntime: FATAL EXCEPTION: DefaultDispatcher-worker-1
Process: org.tensorflow.codelabs.objectdetection, PID: 2971
java.io.FileNotFoundException: This file can not be opened as a file descriptor; it is probably compressed
at android.content.res.AssetManager.nativeOpenAssetFd(Native Method)
at android.content.res.AssetManager.openFd(AssetManager.java:938)
at org.tensorflow.lite.task.core.TaskJniUtils.createHandleFromFdAndOptions(TaskJniUtils.java:65)
at org.tensorflow.lite.task.vision.detector.ObjectDetector.createFromFileAndOptions(ObjectDetector.java:147)
at org.tensorflow.codelabs.objectdetection.MainActivity.runObjectDetection(MainActivity.kt:127)
at org.tensorflow.codelabs.objectdetection.MainActivity.access$runObjectDetection(MainActivity.kt:48)
at org.tensorflow.codelabs.objectdetection.MainActivity$setViewAndDetect$1.invokeSuspend(MainActivity.kt:150)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)
2022-01-01 15:52:56.014 2971-3034/org.tensorflow.codelabs.objectdetection I/Process: Sending signal. PID: 2971 SIG: 9
This issue was caused by android compressing the tflite model during the build. To solve this issue i had to instruct aapt not to compress the file.
go to build.gradle, at the app level, inside the andriod{} block, add
aaptOptions {
noCompress "model.tflite"
}
please rename model.tflite to your custom name if your tflite model is not named "model.tflite"
Related
I've tried to make a POST request using ION as showcased here but I'm getting the following errors.
2020-11-30 14:08:37.353 8610-8651/com.example.test_app E/AndroidRuntime: FATAL EXCEPTION: ion-ion
Process: com.example.test_app, PID: 8610
java.lang.AssertionError
at com.koushikdutta.async.AsyncSSLSocketWrapper.write(AsyncSSLSocketWrapper.java:492)
at com.koushikdutta.async.AsyncSSLSocketWrapper.handleHandshakeStatus(AsyncSSLSocketWrapper.java:378)
at com.koushikdutta.async.AsyncSSLSocketWrapper.handshake(AsyncSSLSocketWrapper.java:182)
at com.koushikdutta.async.http.AsyncSSLSocketMiddleware.tryHandshake(AsyncSSLSocketMiddleware.java:89)
at com.koushikdutta.async.http.AsyncSSLSocketMiddleware$2.onConnectCompleted(AsyncSSLSocketMiddleware.java:106)
at com.koushikdutta.async.http.AsyncSocketMiddleware.lambda$getSocket$3$AsyncSocketMiddleware(AsyncSocketMiddleware.java:217)
at com.koushikdutta.async.http.-$$Lambda$AsyncSocketMiddleware$glazjOxu-iNIRY4N890Wl1ngyGo.onCompleted(Unknown Source:12)
at com.koushikdutta.async.future.SimpleFuture.lambda$setCallback$0(SimpleFuture.java:212)
at com.koushikdutta.async.future.-$$Lambda$SimpleFuture$h_gK5Y1XHZI1H8JTE2xOg4dXbp8.onCompleted(Unknown Source:2)
at com.koushikdutta.async.future.SimpleFuture$FutureCallsite.loop(SimpleFuture.java:130)
at com.koushikdutta.async.future.SimpleFuture.handleCallbackUnlocked(SimpleFuture.java:153)
at com.koushikdutta.async.future.SimpleFuture.setComplete(SimpleFuture.java:191)
at com.koushikdutta.async.future.SimpleFuture.setComplete(SimpleFuture.java:174)
at com.koushikdutta.async.future.-$$Lambda$VNAuWcttAhMr3VsWCERbmWE6yR0.success(Unknown Source:2)
at com.koushikdutta.async.future.SimpleFuture.lambda$success$4(SimpleFuture.java:279)
at com.koushikdutta.async.future.-$$Lambda$SimpleFuture$DxIsaj7NQi76eWgOKS4iviWPLV0.onCompleted(Unknown Source:4)
at com.koushikdutta.async.future.SimpleFuture$FutureCallsite.loop(SimpleFuture.java:130)
at com.koushikdutta.async.future.SimpleFuture.handleCallbackUnlocked(SimpleFuture.java:153)
at com.koushikdutta.async.future.SimpleFuture.setComplete(SimpleFuture.java:191)
at com.koushikdutta.async.future.SimpleFuture.setComplete(SimpleFuture.java:178)
at com.koushikdutta.async.http.-$$Lambda$cBC5du-82c5EcL72rP5wNK7Y2Y4.onConnectCompleted(Unknown Source:2)
at com.koushikdutta.async.AsyncServer.runLoop(AsyncServer.java:896)
at com.koushikdutta.async.AsyncServer.run(AsyncServer.java:717)
at com.koushikdutta.async.AsyncServer.access$800(AsyncServer.java:46)
at com.koushikdutta.async.AsyncServer$11.run(AsyncServer.java:671)
Any idea? Thanks.
I found the solution, the problem was that this library doesn't seem to work with Gradle versions newer than 4.0.1.
My Project structure:
1- Kotlin app lib.
2-Java app calling methods from Kotlin lib.
From Java app I'm calling some methods from Kotlin lib. in development all works good and methods called successfully. after generating apk app starts with splash screen then crashes after getting location,
specifically when calling methods from Kotlin lib.
I think I missed something when generating apk with App and lib.
I tried this example and another about proguardFiles but no new result:
https://www.petrikainulainen.net/programming/gradle/getting-started-with-gradle-creating-a-multi-project-build/
the error:
2020-05-28 13:22:29.970 339-339/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.app.app, PID: 339
java.lang.NoSuchMethodError: No static method asAttributeSet(Lh/a/a/a;)Landroid/util/AttributeSet; in class Landroid/util/Xml; or its super classes (declaration of 'android.util.Xml' appears in /system/framework/framework.jar:classes2.dex)
at c.a.n.g.inflate()
at ui.activity.MainActivity.onCreateOptionsMenu()
at android.app.Activity.onCreatePanelMenu(Activity.java:3183)
at androidx.fragment.app.d.onCreatePanelMenu()
at c.a.n.i.onCreatePanelMenu()
at androidx.appcompat.app.f$j.onCreatePanelMenu()
at c.a.n.i.onCreatePanelMenu()
at androidx.appcompat.app.i.o()
at androidx.appcompat.app.i$a.run()
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
I want to build android apk in my libGdx project but I got this error shows up
My other projects with libgdx and scala works well.
I have it on this part of the code:
tempArray = stage.getActors.items.array.filter(_ != null).filter(_.getName == "ball1")
W/com.scala.gdx: Accessing hidden method Ljava/lang/invoke/VarHandle;->releaseFence()V (blacklist, reflection, denied)
E/AndroidRuntime: FATAL EXCEPTION: GLThread 456
Process: com.scala.gdx, PID: 8618
java.lang.ExceptionInInitializerError
...
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1557)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1272)
Caused by: java.lang.NoSuchMethodException: java.lang.invoke.VarHandle.releaseFence []
at java.lang.Class.getMethod(Class.java:2072)
at java.lang.Class.getDeclaredMethod(Class.java:2050)
at java.lang.invoke.MethodHandles$Lookup.findStatic(MethodHandles.java:782)
...
at a.a.a.p.a.l.onSurfaceChanged(:310)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1557)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1272)
I have downloaded SDK for Android from
https://developers.chirp.io/downloads
After that I added *.aar library as was explain here:
https://developer.android.com/studio/projects/android-library.html#AddDependency
Hurrah. I can build the project.
Now I want to install the test App on the phone. But the application crashes like this:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: io.chirp.sdkdemoapp, PID: 12979
java.lang.NoClassDefFoundError: Failed resolution of: Lkotlin/jvm/internal/Intrinsics;
at io.chirp.chirpsdk.ChirpSDK.<init>(Unknown Source:2)
at io.chirp.chirpsdk.ChirpSDK.<init>(Unknown Source:5)
at io.chirp.chirpsdk.ChirpSDK.<init>(Unknown Source:8)
at io.chirp.sdkdemoapp.MainActivity.onCreate(MainActivity.java:77)
As I understand it, a problem arose with dependencies when packaging * aar
So I added in build.gradle (marked as Module) dependency for kotlin like:
implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.2.61'
After that my ERROR has changed.
E/AndroidRuntime: FATAL EXCEPTION: main
Process: io.chirp.sdkdemoapp, PID: 13395
java.lang.NoClassDefFoundError: Failed resolution of: Lokhttp3/MediaType;
at io.chirp.b.a.<init>(Unknown Source:24)
at io.chirp.chirpsdk.a.<init>(Unknown Source:36)
at io.chirp.chirpsdk.ChirpSDK.<init>(Unknown Source:20)
at io.chirp.chirpsdk.ChirpSDK.<init>(Unknown Source:5)
at io.chirp.chirpsdk.ChirpSDK.<init>(Unknown Source:8)
at io.chirp.sdkdemoapp.MainActivity.onCreate(MainActivity.java:77)
I have wrong paths to io.chirp internal libraries.
What should I do to resolve dependency related errors?
You have to import the okhttp 3.12.x dependency required by the ChirpSDK.
However, you don't need to explicitly import the dependency if you are using the SDK from the maven repository as this will be already included:
implementation 'io.chirp:chirpsdk:3.10.0'
and add the repository in your parent maven file:
repositories {
maven {
url "https://maven.chirp.io/release"
}
}
Thanks Dinu for your answer!
Maven repository doesn't work in my case (proxy issues or something else but this is the topic of another discussion).
The problem with using offline ChirpSDK was solved by adding two dependencies:
implementation 'com.squareup.okhttp3:okhttp:3.12.6'
implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.3.50'
I'm try to run python code in my android app using Chaquopy, I'm also using the moviepy library (I'm converting a mp4 file to a gif file). When I try to do the conversion I get the following error message:
2019-02-06 15:46:47.586 3924-3924/com.udacity.gradle.builditbigger E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.udacity.gradle.builditbigger, PID: 3924
com.chaquo.python.PyException: AttributeError: module 'moviepy.audio.fx.all' has no attribute 'audio_fadein'
at <python>.moviepy.editor.<module>(<string>:1)
at <python>.moviepy.editor.<module>(editor.py:80)
at <python>.java.android.importer.load_module_impl(importer.py:435)
at <python>.java.android.importer.load_module(importer.py:353)
at <python>.importlib._bootstrap._load_backward_compatible(<frozen importlib._bootstrap>:626)
at <python>.importlib._bootstrap._load_unlocked(<frozen importlib._bootstrap>:656)
at <python>.importlib._bootstrap._find_and_load_unlocked(<frozen importlib._bootstrap>:955)
at <python>.importlib._bootstrap._find_and_load(<frozen importlib._bootstrap>:971)
at <python>.java.chaquopy.import_override(import.pxi:18)
at <python>.gif_convert.<module>(gif_convert.py:1)
at <python>.java.android.importer.load_module_impl(importer.py:435)
at <python>.java.android.importer.load_module(importer.py:353)
at <python>.importlib._bootstrap._load_backward_compatible(<frozen importlib._bootstrap>:626)
at <python>.importlib._bootstrap._load_unlocked(<frozen importlib._bootstrap>:656)
at <python>.importlib._bootstrap._find_and_load_unlocked(<frozen importlib._bootstrap>:955)
at <python>.importlib._bootstrap._find_and_load(<frozen importlib._bootstrap>:971)
at <python>.importlib._bootstrap._gcd_import(<frozen importlib._bootstrap>:994)
at <python>.importlib.import_module(__init__.py:126)
at <python>.chaquopy_java.Java_com_chaquo_python_Python_getModule(chaquopy_java.pyx:154)
at com.chaquo.python.Python.getModule(Native Method)
at com.udacity.gradle.builditbigger.newPost.visualMediaPost.VisualMediaPostFragment.moveFile(VisualMediaPostFragment.java:247)
at com.udacity.gradle.builditbigger.camera.LifeCycleCamera.getFilePath(LifeCycleCamera.java:1161)
at com.udacity.gradle.builditbigger.camera.LifeCycleCamera.stopRecordingVideo(LifeCycleCamera.java:1078)
at com.udacity.gradle.builditbigger.newPost.visualMediaPost.VisualMediaPostFragment.lambda$onCreateView$5(VisualMediaPostFragment.java:162)
at com.udacity.gradle.builditbigger.newPost.visualMediaPost.-$$Lambda$VisualMediaPostFragment$WS1G2y9p8sE-re_eOWFa7Rr0OCU.onClick(Unknown Source:4)
at android.view.View.performClick(View.java:6897)
at android.view.View$PerformClick.run(View.java:26089)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6940)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
I've found a fix for this problem (it involves changing the python code that would normally be generated by android studio, so any changes made to the python files will be overwritten during build time.
The python code is shown below
from moviepy.editor import VideoFileClip
def convert(path):
clip = VideoFileClip(path)
return clip.write_gif("output.gif", fps=24)
The java code used to start the pyhton code:
Python.start(new AndroidPlatform(getActivity()));
Python py = Python.getInstance();
PyObject gifConvert = py.getModule("gif_convert");
PyObject gif = gifConvert.callAttr("convert", file.getAbsolutePath());
Log.i("gif type", gif.toString());
Any help would be greatly appreciated.
Older versions of Chaquopy had a problem with pkgutil.iter_modules. This has been fixed in Chaquopy 6.2.1.