Failed to load .so in android studio - android

I wanted to load a .so file: System.loadLibrary("example");
but i faced with this error!!
this is the error:
FATAL EXCEPTION: main
Process: com.name.ex, PID: 30737
java.lang.UnsatisfiedLinkError: dlopen failed: file offset for the library "/data/app/com.name.ex-1/lib/arm/example.so" >= file size: 0 >= 0
at java.lang.Runtime.loadLibrary(Runtime.java:372)
at java.lang.System.loadLibrary(System.java:1076)
at com.name.ex.example<clinit>(example.java:582)
at java.lang.Class.newInstance(Native Method)
at android.app.Instrumentation.newApplication(Instrumentation.java:1020)
at android.app.Instrumentation.newApplication(Instrumentation.java:1005)
at android.app.LoadedApk.makeApplication(LoadedApk.java:670)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6395)
at android.app.ActivityThread.access$1800(ActivityThread.java:229)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1887)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:7325)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

you might have placed the native assembly for ARM into the wrong directory ...or the file-size is indeed 0. it's ordinary called armeabi-v7a instead of arm, for example (the jniLibs path might need to be adjusted, depending how your project looks alike):
app/src/main/jniLibs/armeabi-v7a
in the module-level build.gradle one can define the location:
android {
...
sourceSets {
main {
jniLibs.srcDir "src/main/jniLibs"
}
}
}

Related

RuntimeException: Unable to instantiate application com.company.app.Application: ClassNotFoundException

I've read a few answers on this site with the same or similar error messages, and I've tried all the solutions already. Sadly, none of them have worked so far.
My gradle files all look like they're properly set up for Multidex, the Application class extends MultiDexApplication and is referenced correctly in the manifest, I've cleaned all caches and restarted the IDE, deleting builds from the project and the device and re-building/re-installing, etc. etc.
Inspecting the APK, I found the Application in classes2.dex, correctly referencing .super Landroidx/multidex/MultiDexApplication;
The stack I'm getting is like this:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.<REDACTED>, PID: 25475
java.lang.RuntimeException: Unable to instantiate application com.<REDACTED>.Application: java.lang.ClassNotFoundException: Didn't find class "com.<REDACTED>.Application" on path: DexPathList[[zip file "/data/app/~~b-NK-x066lFdY_bh0tm6ew==/com.<REDACTED>-V2WCXZvYqUZRGKbFMfmgFg==/base.apk"],nativeLibraryDirectories=[/data/app/~~b-NK-x066lFdY_bh0tm6ew==/com.<REDACTED>-V2WCXZvYqUZRGKbFMfmgFg==/lib/arm64, /system/lib64, /system/system_ext/lib64]]
at android.app.LoadedApk.makeApplication(LoadedApk.java:1306)
at android.app.ActivityThread.handleMakeApplication(ActivityThread.java:7401)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7374)
at android.app.ActivityThread.access$1500(ActivityThread.java:301)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2118)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:246)
at android.app.ActivityThread.main(ActivityThread.java:8425)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:596)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.<REDACTED>.Application" on path: DexPathList[[zip file "/data/app/~~b-NK-x066lFdY_bh0tm6ew==/com.<REDACTED>-V2WCXZvYqUZRGKbFMfmgFg==/base.apk"],nativeLibraryDirectories=[/data/app/~~b-NK-x066lFdY_bh0tm6ew==/com.<REDACTED>-V2WCXZvYqUZRGKbFMfmgFg==/lib/arm64, /system/lib64, /system/system_ext/lib64]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:207)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at android.app.AppComponentFactory.instantiateApplication(AppComponentFactory.java:76)
at android.app.Instrumentation.newApplication(Instrumentation.java:1158)
at android.app.LoadedApk.makeApplication(LoadedApk.java:1298)
at android.app.ActivityThread.handleMakeApplication(ActivityThread.java:7401) 
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7374) 
at android.app.ActivityThread.access$1500(ActivityThread.java:301) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2118) 
at android.os.Handler.dispatchMessage(Handler.java:106) 
at android.os.Looper.loop(Looper.java:246) 
at android.app.ActivityThread.main(ActivityThread.java:8425) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:596) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130) 
Suppressed: java.io.IOException: Failed to open dex files from /data/app/~~b-NK-x066lFdY_bh0tm6ew==/com.<REDACTED>-V2WCXZvYqUZRGKbFMfmgFg==/base.apk because: Failure to verify dex file '/data/app/~~b-NK-x066lFdY_bh0tm6ew==/com.<REDACTED>-V2WCXZvYqUZRGKbFMfmgFg==/base.apk': Bad index for method_handle_item method_idx: ffff >= de57
at dalvik.system.DexFile.openDexFileNative(Native Method)
at dalvik.system.DexFile.openDexFile(DexFile.java:367)
at dalvik.system.DexFile.<init>(DexFile.java:109)
at dalvik.system.DexFile.<init>(DexFile.java:82)
at dalvik.system.DexPathList.loadDexFile(DexPathList.java:439)
at dalvik.system.DexPathList.makeDexElements(DexPathList.java:398)
at dalvik.system.DexPathList.<init>(DexPathList.java:166)
at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:129)
at dalvik.system.BaseDexClassLoader.<init>(BaseDexClassLoader.java:104)
at dalvik.system.PathClassLoader.<init>(PathClassLoader.java:74)
at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:87)
at com.android.internal.os.ClassLoaderFactory.createClassLoader(ClassLoaderFactory.java:116)
at android.app.ApplicationLoaders.getClassLoader(ApplicationLoaders.java:114)
at android.app.ApplicationLoaders.getClassLoaderWithSharedLibraries(ApplicationLoaders.java:60)
at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:933)
at android.app.LoadedApk.getClassLoader(LoadedApk.java:990)
at android.app.LoadedApk.getResources(LoadedApk.java:1234)
at android.app.ContextImpl.createAppContext(ContextImpl.java:2788)
at android.app.ContextImpl.createAppContext(ContextImpl.java:2780)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7263)
... 8 more
Can anyone figure out what this is all about?
In the module level build.gradle, we added these lines:
// Near the top
apply plugin: 'com.google.firebase.crashlytics'
// ...
android {
// ...
compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
// ...
}
// ...
I have no idea how this fixed this crash, but I suppose that's what I get for using "It just works" libraries.

How to build and use PJSIP for different architectures than armeabi?

I succesfully compiled PJSIP library for Android. Sample project works without any problems when I build for default architecture armeabi. Now I tried to compile library for arch such as armeabi-v7a and arm64-v8a. Unfortunately when I add libraries to project in appropriate folders (jnLibs/armeabi-v7a and jniLibs/arm64-v8a) application is not starting...
To setup build for different archs I use this command:
NDK_TOOLCHAIN_VERSION=4.9 TARGET_ABI=armeabi-v7a ./configure-android --use-ndk-cflags
I have this error on app launch:
07-04 12:28:46.079 15317-15317/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.futuremind.omili, PID: 15317
java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "getifaddrs" referenced by "/data/app/com.futuremind.omili-1/lib/arm/libpjsua2.so"...
at java.lang.Runtime.loadLibrary(Runtime.java:372)
at java.lang.System.loadLibrary(System.java:1076)
at com.futuremind.omili.MyApp.<clinit>(MyApp.java:293)
at com.futuremind.omili.MainActivity.onCreate(MainActivity.java:87)
at android.app.Activity.performCreate(Activity.java:6289)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2405)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2535)
at android.app.ActivityThread.access$900(ActivityThread.java:155)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1380)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:152)
at android.app.ActivityThread.main(ActivityThread.java:5497)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Thanks for any help! :)
I was able to fix this error by updating the AndroidManifest.xml in "pjsip-apps/src/swig/java/android/app/src/main" to match my android target -- in my case to "23". Then "make clean" and another "make" in "pjsip-apps/src/swig", and rebuilding my app.

UnsatisfiedLinkError - com.datumdroid.android.ocr.simple couldn't find "libjpgt.so"

I'm new to Android Studios and I am doing this OCR http://swlock.blogspot.com/2016/07/ocr-tesseract-2.html where the image convert to text but everytime I take an image app the will close and got this error. Anyone can guide me to fix this error? Thanks
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.datumdroid.android.ocr.simple, PID: 2425
java.lang.UnsatisfiedLinkError: com.android.tools.fd.runtime.IncrementalClassLoader$DelegateClassLoader[DexPathList[[dex file "/data/data/com.datumdroid.android.ocr.simple/files/instant-run/dex/slice-slice_9-classes.dex", dex file "/data/data/com.datumdroid.android.ocr.simple/files/instant-run/dex/slice-slice_8-classes.dex", dex file "/data/data/com.datumdroid.android.ocr.simple/files/instant-run/dex/slice-slice_7-classes.dex", dex file "/data/data/com.datumdroid.android.ocr.simple/files/instant-run/dex/slice-slice_6-classes.dex", dex file "/data/data/com.datumdroid.android.ocr.simple/files/instant-run/dex/slice-slice_5-classes.dex", dex file "/data/data/com.datumdroid.android.ocr.simple/files/instant-run/dex/slice-slice_4-classes.dex", dex file "/data/data/com.datumdroid.android.ocr.simple/files/instant-run/dex/slice-slice_3-classes.dex", dex file "/data/data/com.datumdroid.android.ocr.simple/files/instant-run/dex/slice-slice_2-classes.dex", dex file "/data/data/com.datumdroid.android.ocr.simple/files/instant-run/dex/slice-slice_1-classes.dex", dex file "/data/data/com.datumdroid.android.ocr.simple/files/instant-run/dex/slice-slice_0-classes.dex"],nativeLibraryDirectories=[/data/app/com.datumdroid.android.ocr.simple-2/lib/x86, /system/lib, /vendor/lib]]] couldn't find "libjpgt.so"
at java.lang.Runtime.loadLibrary0(Runtime.java:972)
at java.lang.System.loadLibrary(System.java:1530)
at com.googlecode.tesseract.android.TessBaseAPI.<clinit>(TessBaseAPI.java:44)
at com.datumdroid.android.ocr.simple.SimpleAndroidOCRActivity.onPhotoTaken(SimpleAndroidOCRActivity.java:214)
at com.datumdroid.android.ocr.simple.SimpleAndroidOCRActivity.onActivityResult(SimpleAndroidOCRActivity.java:138)
at android.app.Activity.dispatchActivityResult(Activity.java:6915)
at android.app.ActivityThread.deliverResults(ActivityThread.java:4049)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4096)
at android.app.ActivityThread.-wrap20(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1516)
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:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Application terminated.
That means that the *.so files are not in your *.apk file. Follow the steps in this stackoverflow question/answer.
You can always go to Build > Analyze APK... to see if the *.so files are getting added. Obviously, if they are not in the APK, then there is no reason to attempt to run the app that needs the *.so files.

Realm causes my app to crash when trying to build a RealmConfiguration

I'm trying to use Realm as a database for high scores in my app. However, when this line of code is called:
realmConfig = new RealmConfiguration.Builder(getActivity().getApplicationContext()).build();
in the Fragment where I'm trying to save the user's score, I get this:
FATAL EXCEPTION: main
Process: com.tommy.mastersproject, PID: 21387
Theme: themes:{com.android.settings=overlay:com.cyngn.hexo, default=overlay:system, iconPack:system, fontPkg:system, com.android.systemui=overlay:system, com.android.systemui.navbar=overlay:system}
java.lang.NoClassDefFoundError: Failed resolution of: Lio/realm/RealmConfiguration$Builder;
at com.tommy.mastersproject.fragments.MemoryRecallFragment.onCreate(MemoryRecallFragment.java:144)
at android.support.v4.app.Fragment.performCreate(Fragment.java:1951)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1029)
at android.support.v4.app.BackStackRecord.setLastIn(BackStackRecord.java:779)
at android.support.v4.app.BackStackRecord.calculateFragments(BackStackRecord.java:802)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:660)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617)
at android.support.v4.app.FragmentController.execPendingActions(FragmentController.java:339)
at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:601)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1238)
at android.app.Activity.performStart(Activity.java:6268)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2413)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2510)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1363)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5461)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.ClassNotFoundException: Didn't find class "io.realm.RealmConfiguration$Builder" on path: DexPathList[[dex file "/data/data/com.tommy.mastersproject/files/instant-run/dex/slice-support-annotations-23.4.0_d80f4a0fc2ae8e1f7cf76e4c536a48795da28487-classes.dex", dex file "/data/data/com.tommy.mastersproject/files/instant-run/dex/slice-slice_9-classes.dex", dex file "/data/data/com.tommy.mastersproject/files/instant-run/dex/slice-slice_8-classes.dex", dex file "/data/data/com.tommy.mastersproject/files/instant-run/dex/slice-slice_7-classes.dex", dex file "/data/data/com.tommy.mastersproject/files/instant-run/dex/slice-slice_6-classes.dex", dex file "/data/data/com.tommy.mastersproject/files/instant-run/dex/slice-slice_5-classes.dex", dex file "/data/data/com.tommy.mastersproject/files/instant-run/dex/slice-slice_4-classes.dex", dex file "/data/data/com.tommy.mastersproject/files/instant-run/dex/slice-slice_3-classes.dex", dex file "/data/data/com.tommy.mastersproject/files/instant-run/dex/slice-slice_2-classes.dex", dex file "/data/data/com.tommy.mastersproject/files/instant-run/dex/slice-slice_1-classes.dex", dex file "/data/data/com.tommy.mastersproject/files/instant-run/dex/slice-slice_0-classes.dex", dex file "/data/data/com.tommy.mastersproject/files/instant-run/dex/slice-library-2.4.0_e0d22a6e7ea9a4d2326a0c8c16bbc09d4d04442c-classes.dex", dex file "/data/data/com.tommy.mastersproject/files/instant-run/dex/slice-internal_impl-23.4.0_bd67bdb6ef0c094e8f4157e2567e8b30b9d0dd7f-classes.dex", dex file "/data/data/com.tommy.mastersproject/files/instant-run/dex/slice-com.jakewharton-butterknife-8.0.1_9246a0d023a2de89ba20a84f0fb1ecc6b733b004-classes.dex", dex file "/data/data/com.tommy.mastersproject/files/instant-run/dex/slice-com.code-troopers.betterpickers-library-3.0.0_f98f8b23c6650d93d8479a647f8f2162db8834e8-classes.dex", dex file "/data/data/com.tommy.mastersproject/files/instant-run/dex/slice-com.astuetz-pagerslidingtabstrip-1.0.1_474986b4f5d06e547dc72e3bf0988a95fa9d3973-classes.dex", dex file "/data/data/com.tommy.mastersproject/files/instant-run/dex/slice-com.android.support-support-vector-dr
I've also tried using
realm = Realm.getDefaultInstance();
but without any luck.
From a quick Google search, there have been similar complaints which were due to Realm's poor compatibility with the Android multidex and for not being up-to-date with Gradle, but I'm currently running Gradle 2.1.2.
I am also using Gradle 2.1.2 and Realm is working perfectly fine, problem could be with Instant Run, Did you try loading the project without Instant Run? If not disable it(In Android studio -> Preferences -> Build, Execution, Deployment -> Instant Run), clean the project and run it again.
If it does not work, share the actual code where you are creating RealmConfiguration and using Realm.

Fields from imported android library not generated in R file

I need to integrate a certain SDK with my app, I added the .aar file in my gradle dependencies and I added the code they provided me.
The gradle build went with no special problems, but when I tried to start the SDK's activity the app crashed with the following exception:
12-07 16:28:09.991 16236-16236/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.positiveapps.clickins, PID: 16236
java.lang.NoSuchFieldError: No static field action_show_neura of type I in class Lcom/neura/standalonesdk/R$id; or its superclasses (declaration of 'com.neura.standalonesdk.R$id' appears in /data/app/com.positiveapps.clickins-1/base.apk:classes2.dex)
at com.neura.dashboard.R$id.<clinit>(R.java:995)
at com.neura.dashboard.activity.LoginActivity.onCreate(LoginActivity.java:59)
at com.neura.dashboard.activity.AppAuthenticationActivity.onCreate(AppAuthenticationActivity.java:26)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
After I went through the R files that are generated in my application I found out a significant amount of fields that exist in R.txt file in the aar are missing from the generated R.
I've tried building with and without proguard, updating gradle version, I cleaning and rebuilding the project, removing "build" directory manually, adding the aar as a module.
None of these seem to be the problem, the R file is still missing fields.
Thanks for any help, Ilia.
Keep aar file in libs folder. ( as libname.aar )
then in app build.gradle specify following.
repositories {
flatDir {
dirs 'libs'
}
}
dependencies {
compile(name:'libname', ext:'aar')
}
and click sync project with gradle files.
Then clean build the project.

Categories

Resources