I'm trying to use libtensorflow.so in my c++ project so I can use it in my android wrapper. My project is a c++ project at it's core but uses different UI binders mainly android NDK. I've checked the official build docs and ran this command: bazel build --config=elinux_aarch64 -c opt //tensorflow/lite/c:libtensorflowlite_c.so which built with no proplems. Then I got the necessary include directories mainly tensorflow and flatbuffers from the tensorflow source directory I got from github (Where I ran bazel).
Then I've added it to my android cmake like so:
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../third-party/include/tflite)
add_library(libtensorflowlite
SHARED
IMPORTED)
set_target_properties(
libtensorflowlite
PROPERTIES
IMPORTED_LOCATION
${CMAKE_CURRENT_SOURCE_DIR}/../../third-party/libs/tflite/arm64-v8a/libtensorflowlite.so
)
...
target_link_libraries(
...
#tflite
libtensorflowlite
...
)
When I run my project I get this output on logcat:
2023-02-13 11:37:01.222 3987-3987 ample.nerveblo com.example.my_proj W Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (unsupported, reflection, allowed)
2023-02-13 11:37:01.223 3987-3987 ample.nerveblo com.example.my_proj W Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (unsupported, reflection, allowed)
2023-02-13 11:37:01.229 3987-3987 AndroidRuntime com.example.my_proj D Shutting down VM
2023-02-13 11:37:01.231 3987-3987 AndroidRuntime com.example.my_proj E FATAL EXCEPTION: main
Process: com.example.my_proj, PID: 3987
java.lang.UnsatisfiedLinkError: dlopen failed: library "libm.so.6" not found: needed by /data/app/~~0XEVJKwYyglTdlVABYHPjw==/com.example.my_proj-8OVBEONU7K3bv0RuyroYKA==/base.apk!/lib/arm64-v8a/libtensorflowlite.so in namespace classloader-namespace
at java.lang.Runtime.loadLibrary0(Runtime.java:1077)
at java.lang.Runtime.loadLibrary0(Runtime.java:998)
at java.lang.System.loadLibrary(System.java:1656)
at com.example.my_proj.My_proj.<clinit>(My_proj.java:40)
at com.example.my_proj.MainActivity.onCreate(MainActivity.java:76)
at android.app.Activity.performCreate(Activity.java:8326)
at android.app.Activity.performCreate(Activity.java:8306)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1347)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4212)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4403)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:104)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2498)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:313)
at android.app.ActivityThread.main(ActivityThread.java:8855)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
2023-02-13 11:37:01.246 3987-3987 Process com.example.My_proj I Sending signal. PID: 3987 SIG: 9
---------------------------- PROCESS ENDED (3987) for package com.example.my_proj ----------------------------
2023-02-13 11:37:01.268 1161-2253 WindowManager system_server E win=Window{a2940e9 u0 Splash Screen com.example.my_proj EXITING} destroySurfaces: appStopped=false win.mWindowRemovalAllowed=true win.mRemoveOnExit=true win.mViewVisibility=0 caller=com.android.server.wm.ActivityRecord.destroySurfaces:6283 com.android.server.wm.ActivityRecord.destroySurfaces:6264 com.android.server.wm.WindowState.onExitAnimationDone:6089 com.android.server.wm.ActivityRecord$$ExternalSyntheticLambda14.accept:2 java.util.ArrayList.forEach:1262 com.android.server.wm.ActivityRecord.onAnimationFinished:8340 com.android.server.wm.ActivityRecord.postApplyAnimation:6016
The reason was I ran with the --config=elinux_aarch64 flag not --config=android_arm64. Using the android version of the command caused a bunch of more problems but I think it's the right way to go. The new problems are mainly caused by me trying to cross-compile an aarch64 code on a linux amd machine and it is not fully supported by tensorflow yet as far as I'm concerned. Although I'm not quite sure how someone can compile on an aarch64 machine...
If someone has a pre-compiled aarch64 c++ tensorflow lite library links I would appreciate it.
Related
I want to import below libraries in my Android Studio Project these are placed in /system/lib64/ folder.
I am getting below error
2020-01-06 13:23:31.358 5171-5171/org.strongswan.android E/AndroidRuntime: FATAL EXCEPTION: main
Process: org.strongswan.android, PID: 5171
java.lang.UnsatisfiedLinkError: dlopen failed: library "/system/lib64/libstrongswan.so" needed or dlopened by "/system/lib64/libnativeloader.so" is not accessible for the namespace "classloader-namespace"
at java.lang.Runtime.loadLibrary0(Runtime.java:1016)
at java.lang.System.loadLibrary(System.java:1669)
at org.strongswan.android.logic.CharonVpnService.<init>(CharonVpnService.java:730)
at java.lang.Class.newInstance(Native Method)
at android.app.AppComponentFactory.instantiateService(AppComponentFactory.java:103)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:3740)
at android.app.ActivityThread.access$1400(ActivityThread.java:238)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1803)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7073)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964)
on the line System.loadLibrary("strongswan")
System.loadLibrary("strongswan");
if (MainActivity.USE_BYOD)
{
System.loadLibrary("tncif");
System.loadLibrary("tnccs");
System.loadLibrary("imcv");
}
System.loadLibrary("hydra");
System.loadLibrary("charon");
System.loadLibrary("ipsec");
System.loadLibrary("androidbridge");
}
From Nougat onwards, Android prevents the runtime linkage of private symbols from system libraries (see this blogpost in Android Developers).
You have two options:
Include those libraries in your APK so that you don't need to look for them in /system/lib/; or
Modify your Android ROM so that those libraries are considered public. This can be done by adding those libraries to /system/etc/public.libraries.txt.
I also meet this error.The situation I tested is like this.
I put the so file in the [libs/yourCpuModel(armeabi-v7a)/] directory will be this error.
I put the so file in the [src/jniLibs/youtCpuModel(armeabi-v7a)/] directory will be this error.
But I put the so file in the [src/main/jniLibs/yourCpuModel(armeabi-v7a)/] directory will not.
I don't know why.Maybe you can try it.
I'm trying to port LG system launcher but I can't get it to work due to a certain missing class called "LGSharedPreferences" or something like that. Here is the logcat obtained:
FATAL EXCEPTION: main
Process: com.lge.launcher3, PID: 9174
java.lang.NoClassDefFoundError: Failed resolution of: Landroid/app/LGSharedPreferences;
at com.lge.launcher3.util.LGHomeFeature.getPermanentPreferences(LGHomeFeature.java:416)
at com.lge.launcher3.util.LGHomeFeature.getSwivelHomeStateFromPreferences(LGHomeFeature.java:369)
at com.lge.launcher3.util.LGHomeFeature.<init>(LGHomeFeature.java:278)
at com.lge.launcher3.util.LGHomeFeature.init(LGHomeFeature.java:294)
at com.lge.launcher3.allapps.SwivelAllAppsDBProvider.onCreate(SwivelAllAppsDBProvider.java:28)
at android.content.ContentProvider.attachInfo(ContentProvider.java:2388)
at android.content.ContentProvider.attachInfo(ContentProvider.java:2358)
at android.app.ActivityThread.installProvider(ActivityThread.java:7248)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:6789)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6706)
at android.app.ActivityThread.access$1300(ActivityThread.java:238)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1914)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7666)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Caused by: java.lang.ClassNotFoundException: android.app.LGSharedPreferences
... 18 more
If it helps I tried both installing it as a user app and making a magisk module to install it as a system app (also I bundled with it some libraries I found in the app manifest such as "com.lge.sui" and "com.lge.lgdynamicactionbar" but no luck) and I always get the same error, some help will be highly appreciated 👍
By the way, sorry for my bad English, I'm still learning :)
The error message means that android.app.LGSharedPreferences was available at compile time, but is missing at runtime. Given the package name of the class, my guess would be that the class is supposed to be loaded from the OS on LG phones, and you are running the app on a phone that doesn't have that available.
If you have the source code for the app and the library that contains android.app.LGSharedPreferences, you should make sure the library containing LGSharedPreferences is statically compiled in (probably also change the package name to avoid conflicts on LG phones).
I've moved from Mac to a linux machine (ubuntu) and and can't get the previous project running. The project has about 10 modules, and it still works fine on my macbook, but when building on ubuntu (tried clean install on 17.10 2 times, and 16.04 2 times as well) will crash the app on start with the following error:
E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to instantiate application com.xxx.xxx.Application: java.lang.ClassNotFoundException: Didn't find class "com.xxx.xxx.Application" on path: DexPathList[[zip file "/data/app/com.xxx.xxx.debug-1/base.apk"],nativeLibraryDirectories=[/data/app/com.xxx.xxx.debug-1/lib/arm, /data/app/com.xxx.xxx.debug-1/base.apk!/lib/armeabi-v7a, /system/lib, /vendor/lib]]
at android.app.LoadedApk.makeApplication(LoadedApk.java:802)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5418)
at android.app.ActivityThread.-wrap2(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1558)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6165)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:778)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.xxx.xxx.Application" on path: DexPathList[[zip file "/data/app/com.xxx.xxx.debug-1/base.apk"],nativeLibraryDirectories=[/data/app/com.xxx.xxx.debug-1/lib/arm, /data/app/com.xxx.xxx.debug-1/base.apk!/lib/armeabi-v7a, /system/lib, /vendor/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.app.Instrumentation.newApplication(Instrumentation.java:1014)
at android.app.LoadedApk.makeApplication(LoadedApk.java:796)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5418)
at android.app.ActivityThread.-wrap2(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1558)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6165)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:888)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:778)
I've tried cleaning, rebuilding, invalidating and restarting, 3 different android studio versions (the stable one, 2.3, and latest canary build) on both operating systems (17.10 and 16.04) and I still get exactly same error. Also, I've installed the libraries for 64 bit system. Also, I've tried with oracle java as well.
Does anyone have any clue why a project gets this error on linux but not on mac?
Update
So I found out that Ubuntu does not see the application class. It has a red label and is not recognized from the manifest file. This is the application class from app package and I can only see it if I switch to project view. I'm currently investigating why it doesn't see it.
So the problem was that Ubuntu would not see the Application class, and thus did not consider it on build, as a result it wasn't included in dex files. The thing is that the application class is inside app -> src -> main -> Java -> packagename -> Application.class , and Ubuntu did not recognize Java as a valid directory. It recognizes it only if it is java. So renaming the folder Java to java has fixed the problem and the application class is now visible.
Morale 1: Always triple check all ridiculous use cases and pay attention to details.
Morale 2: Ubuntu handles folders in a different manner than Mac because Mac couldn't care less if that's capital J or lowercase j.
Do one thing disable Instant Run feature.
you can do it by
File->Settings->Build,Execution,Deployment->Instant run
Click on instant run and then disable the checkbox for Instant Run.
A runtime exception is happening after executing the command
buck install --run demo_app_android following this tutorial and this sample demo
Then, the following is shown in console
Installing apk on emulator-5554 (null).
[-] PROCESSING BUCK FILES...FINISHED 0.0s [100%] 🐌 File removed
[-] DOWNLOADING... (0.00 B/S AVG, TOTAL: 0.00 B, 0 Artifacts)
[-] BUILDING...FINISHED 0.8s [100%] (1/1 JOBS, 1 UPDATED, 0 [0.0%] CACHE MISS)
[+] INSTALLING...2.1s
Successfully ran install apk //android:demo-app on 1 device(s)
Starting activity com.facebook.buck.demo/.App...
Successfully ran start activity on 1 device(s)
Finally, the device shows a message saying Buck Demo App has stopped
The app was successfully installed as I can see it on the apps list but it's not working
Stacktrace:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.facebook.buck.demo, PID: 7265
java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.facebook.buck.demo-1/base.apk"],nativeLibraryDirectories=[/data/app/com.facebook.buck.demo-1/lib/x86, /system/lib, /vendor/lib]]] couldn't find "libjni.so"
at java.lang.Runtime.loadLibrary0(Runtime.java:972)
at java.lang.System.loadLibrary(System.java:1530)
at com.facebook.buck.demo.Hello.<init>(Hello.java:13)
at com.facebook.buck.demo.App.onCreate(App.java:24)
at android.app.Activity.performCreate(Activity.java:6662)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
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:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
Device specs:
Native Android Emulator (also, ran it into a real device with same result)
Nexus 5 API 24
My computer:
MacBook pro mid 2012
Note: Also, this issue was reported directly to the buck repository but no solution was given yet
Any idea about how to solve it?
Repeating the answer from github:
You need to install Android NDK from here (version 10e) and set ANDROID_NDK_REPOSITORY to the location of the unpacked NDK (see buckconfig section for more info).
For example, if you unpack NDK to ~/tmp/ndk (so that there is a directory ~/tmp/ndk/android-ndk-r10e), you need to set ANDROID_NDK_REPOSITORY to ~/tmp/ndk.
After that delete old cache and rebuild the app:
$ buck kill && rm -rf buck-out
$ buck build demo_app_android
I'm trying to use an app in Eclipse (v3.8), but it don't work.
The API is 19, and the app is Serial_Port_1.1.apk
My method: (I'm new with eclipse)
Extract the apk with apktool
Import the folder with Eclipse
Run as: Android application
I got theses errors:
threadid=1: thread exiting with uncaught exception (group=0xb3ac2ba8)
FATAL EXCEPTION: main
Process: android_serialport_api.sample, PID: 1508
java.lang.RuntimeException: Unable to instantiate application android_serialport_api.sample.Application: java.lang.ClassNotFoundException: Didn't find class "android_serialport_api.sample.Application" on path: DexPathList[[zip file "/data/app/android_serialport_api.sample-1.apk"],nativeLibraryDirectories=[/data/app-lib/android_serialport_api.sample-1, /vendor/lib, /system/lib]]
at android.app.LoadedApk.makeApplication(LoadedApk.java:516)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4317)
I'm trying to connect an Arduino to Eclipse, and the app works fine on a real system (ARM Orange Pi)
As it says in the LogCat, there is a ClassNotFoundException when you try to run it after decompile. As I understood, the original app works but after decompile + recompile it won't work again, throwing a CNF. This means that your decompile process didn't work properly. I suggest you trying the Android APK Decompiler, which is a free online tool.
Note: I haven't tested it yet, but it should work.