49

I'm testing Android 6.0 on a Nexus 5 and i'm using Metaio (I know that the service is going to end on the 15th of december but for that date we'll move to another AR platform). The problem is that when I start the ARActivity I get the following error:

    09-02 08:45:11.138: E/AndroidRuntime(6141):     java.lang.UnsatisfiedLinkError: dlopen failed: /data/app/com.myapp.myapp/lib/arm/libavcodec.so: has text relocations
    09-02 08:45:11.138: E/AndroidRuntime(6141):     at java.lang.Runtime.loadLibrary(Runtime.java:372)
    09-02 08:45:11.138: E/AndroidRuntime(6141):     at java.lang.System.loadLibrary(System.java:1076)
    09-02 08:45:11.138: E/AndroidRuntime(6141):     at com.metaio.sdk.jni.IMetaioSDKAndroid.loadNativeLibs(IMetaioSDKAndroid.java:54)
    09-02 08:45:11.138: E/AndroidRuntime(6141):     at metaioCloudPlugin.SplashActivity.loadNativeLibs(SplashActivity.java:37)
    09-02 08:45:11.138: E/AndroidRuntime(6141):     at metaioCloudPlugin.SplashActivity.onCreate(SplashActivity.java:68)
    09-02 08:45:11.138: E/AndroidRuntime(6141):     at android.app.Activity.performCreate(Activity.java:6237)
    09-02 08:45:11.138: E/AndroidRuntime(6141):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
    09-02 08:45:11.138: E/AndroidRuntime(6141):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
    09-02 08:45:11.138: E/AndroidRuntime(6141):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
    09-02 08:45:11.138: E/AndroidRuntime(6141):     at android.app.ActivityThread.-wrap11(ActivityThread.java)
    09-02 08:45:11.138: E/AndroidRuntime(6141):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
    09-02 08:45:11.138: E/AndroidRuntime(6141):     at android.os.Handler.dispatchMessage(Handler.java:102)
    09-02 08:45:11.138: E/AndroidRuntime(6141):     at android.os.Looper.loop(Looper.java:148)
    09-02 08:45:11.138: E/AndroidRuntime(6141):     at android.app.ActivityThread.main(ActivityThread.java:5417)
    09-02 08:45:11.138: E/AndroidRuntime(6141):     at java.lang.reflect.Method.invoke(Native Method)
    09-02 08:45:11.138: E/AndroidRuntime(6141):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
    09-02 08:45:11.138: E/AndroidRuntime(6141):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

Does anyone know a possible solution for this or at least a workaround? I'm struggling to find a solution but I can't understand what the problem could be.

LS_
  • 6,763
  • 9
  • 52
  • 88
  • 3
    I met the equal problem with NDK ver r8B. Generated .so file contained TEXTREL section. But with NDK r8D I got .so lib without TEXTREL. You can check your library with command: `android-ndk-r8d\toolchains\arm-linux-androideabi-4.7\prebuilt\windows\bin\arm-linux-androideabi-readelf.exe -a libhcsample.so | grep TEXTREL` – liquid_code Dec 17 '15 at 10:43

6 Answers6

48

Today, I got the same error messages when testing my app with Android 6.0 on a Nexus 6 (Motorola). I solved my issue by checking the targetSDKVersion in the manifest file. Using "22" and not "23" as targetSDKVersion solved it. (See below)

<uses-sdk
        android:minSdkVersion="15"
        android:targetSdkVersion="22" />

I also checked the build.gradle files for compile version and targetSDKversion:

compileSdkVersion 22
    buildToolsVersion '22.0.1'

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 22
    }

Hope this will help you. However, this is just a short term workaround for now, I hope that we will get some feedback from metaio though.

Regards, christin

christin
  • 594
  • 5
  • 9
  • Yeah this is also what I did! I contacted Metaio and I hope on their answer about the problem if they have the possibility to find an easy fix for this but I pretty worried about it.. – LS_ Sep 03 '15 at 07:17
  • Fine that is working for you too! I have not yet got feedback from metaio. If you get some news from them, please keep me updated with a comment or message. As far as I understand, it seems to be a Google/Android related problem (not a metaioSDK related one) as the native library libavcodec cannot be loaded upon app start. An exception is thrown which we then see in the logcat. – christin Sep 03 '15 at 12:52
  • of course I'll keep you updated! Yeah and I don't know what we can do about that.. May I ask you, did you had the chance to use the Metaio SDK on IOS9? Because I haven't tried yet and I'm scared It will have problems too – LS_ Sep 03 '15 at 14:43
  • 1
    Yes, I tried iOS 9 on an iPad mini 1. My AREL apps work as expected. I also tried some of my junaio channels. No problems so far. I tested tracking like Glue, LB/ GPS, GPS/ Orientation Tracking, Instant Tracking, Extended Image Tracking, Dummy Tracking. Methods like setTexture(); startAnimation() + other animation handling methods, shareScreenshot(), startMovieTexture() are working. Starting full screen movies too. Reflection maps are also rendered. Setting 3D models to COS = 0 with screen anchor is working too. Hope it will be the same with your projects. – christin Sep 03 '15 at 20:10
  • Thanks a lot for your help, this is a very good news! Wish I could upvote more than once :D Thanks again for your time and if Metaio decides to answer me i'll let you know! – LS_ Sep 04 '15 at 06:56
  • AReallyGoodName has found a solution, check the answer below! – LS_ Oct 16 '15 at 08:17
  • The textures in 3D models are not displayed. Does anyone have a solution? – user949884 Nov 06 '15 at 23:52
  • 1
    @user949884 Check the px size (should be a power of 2 size like 512x512 px), try a square PNG or a NON-progressive JPG. Otherwise, there is still the metaio helpdesk, until 15 dec 2015. You could search and look for answers, there had been plenty of similar problems. – christin Nov 09 '15 at 17:27
  • 1
    @user949884 Or check the mesh of your model for backface culling. If the normals do not point outwardly, the models' texture will appear transparent as they are applied inside and the rear side is transparent. – christin Nov 09 '15 at 17:30
  • 1
    ok, downgrading the targetSdkVersion really works for this problem. But if I do this, google will not let me republish/update my app. What will be the solution then? – Tushar Monirul May 09 '16 at 17:40
  • @christin What if i want to run my app with targetSDKVersion 23? – Hiren Dabhi Jun 30 '16 at 08:52
  • 3
    @Hiren Dabhi : I think you would have to compile the libraries (FFMPEG …) on your own to a shared object (-.so) and exchange the problematic -.so library with your updated -.so. As for myself, I have not done this, I do not work with the metaioSDK anymore. As far as I know, it is still possible to publish apps at GooglePlay with targetSDKversion = 22 (Unity apps do so too) . But, it is not possible to use targetSDKversion 22, if the app had already published with version 23. – christin Jun 30 '16 at 22:13
  • ok, downgrading the targetSdkVersion really works for this problem. – Lokesh Jun 22 '17 at 19:48
  • @christin what if i want to run my app with target SDK version 24?? – Arslan Maqbool Aug 03 '17 at 12:47
15

You can check if your shared lbirary has text relocations by doing this:

readelf -a path/to/yourlib.so | grep TEXTREL

If it has text relocations, it will show you something like this:

0x00000016 (TEXTREL)                    0x0

If this is the case, you may recompile your shared library with the latest NDK version available:

ndk-build -B -j 8

And if you check it again, the grep command will return nothing.

thiagolr
  • 6,909
  • 6
  • 44
  • 64
  • 1
    How i can achieve this by using a tool or command prompt ? help me – Arslan Maqbool Aug 03 '17 at 12:46
  • Hi, i am having the same issue, I am able to see that TEXTREL message once i used that command. But not able run that ndk command i am getting this issue while running that ndk command: ndk-build: command not found – Black4Guy Sep 03 '20 at 10:42
12

Previous versions of Android would warn if asked to load a shared library with text relocations:

"libfoo.so has text relocations. This is wasting memory and prevents security hardening. Please fix.".

Despite this, the OS will load the library anyway. Marshmallow rejects library if your app's target SDK version is >= 23. System no longer logs this because it assumes that your app will log the dlopen(3) failure itself, and include the text from dlerror(3) which does explain the problem. Unfortunately, lots of apps seem to catch and hide the UnsatisfiedLinkError throw by System.loadLibrary in this case, often leaving no clue that the library failed to load until you try to invoke one of your native methods and the VM complains that it's not present.

You can use the command-line scanelf tool to check for text relocations. You can find advice on the subject on the internet; for example https://wiki.gentoo.org/wiki/Hardened/Textrels_Guide is a useful guide.

Anirudh
  • 2,524
  • 1
  • 14
  • 14
12

OK I've got this working here even with targetSDK 23 set.

For me and my branch the five files that required patching were

libavcodec\arm\fft_fixed_neon.S  
libavcodec\arm\fft_neon.S  
libavcodec\arm\fft_vfp.S   
libavcodec\arm\mlpdsp_armv5te.S  
libutil\arm\asm.S  

I took the latest from https://github.com/FFmpeg/FFmpeg

You will also need HAVE_SECTION_DATA_REL_RO declared somewhere in your build for the macro in asm.S to use the dynamic relocations option.

AReallyGoodName
  • 351
  • 3
  • 7
  • thanks a lot!! I'm gonna test it as soon as I can and let you know! – LS_ Oct 16 '15 at 06:39
  • 3
    For those on a completely different branch here's a link to the exact patches that ffmpeg had that fixes this issue, [link1](https://github.com/FFmpeg/FFmpeg/commit/f963f80399deb1a2b44c1bac3af7123e8a0c9e46) and [link2](https://github.com/FFmpeg/FFmpeg/commit/cb416a7d795414aaa534c27943bda0d3aef3b5a1) – AReallyGoodName Oct 16 '15 at 07:06
  • 1
    Did this actually solve your issue? I applied these patches but still got the failure on M after recompiling my library. – William Seemann Oct 19 '15 at 01:53
  • 1
    Hi, Would you be able to share the lib files (.so) when you do the build ? I'm unable to get it to build at my end – Champika Samarasinghe Oct 26 '15 at 20:09
  • @AReallyGoodName Could you please share the .so files. It would help us a lot. – Rahul Sainani Nov 02 '15 at 15:32
  • Hey @Signo Could you please tell us how you compiled the .so files for android. I'm following [this guide to build ffmpeg using ndk](http://www.roman10.net/how-to-build-ffmpeg-with-ndk-r9/) but I'm unable to do so, stuck on it for days. I'm using ndkr10e. This generates .a files in android/arm/lib folder instead of .so files. Could you please point me in the right direction. Cheers! – Rahul Sainani Nov 04 '15 at 15:15
  • @droidster i'm sorry but I still haven't tested this solution, I'm still using the targetSDKVersion = 22, you should ask aReallyGoodName how he did that – LS_ Nov 05 '15 at 08:12
  • @Signo Thanks for replying. No problem. – Rahul Sainani Nov 05 '15 at 11:39
  • 2
    @AReallyGoodName I've got the .so files but they have version numbers in the file names and they are referenced using those names from inside other .so files so they can't just be renamed. Can you please tell us how you compiled .so files without versioning. Sorry about all the comments. :) – Rahul Sainani Nov 05 '15 at 11:41
  • @AReallyGoodName I have built newest ffmpeg libraries and now I have new UnsatisfiedLinkError: "cannot locate symbol 'avcodec_register_all' " referenced by libmetaiosdk.so . Does it mean there is still relocations from metaio's so library? Have you succsessfully tried it? And where HAVE_SECTION_DATA_REL_RO should be declared and with what value? – kolodi Jun 28 '16 at 10:42
  • @AReallyGoodName can you tell me how to use this? already my app is live with `compileSdkVersion 25`. I have add ffmpeg library. now i have change targetSdk to `23` . but this not compress video in marshmellow and nougat . My ffmpeg command is as follows . ` {"ffmpeg","-y","-i","/storage/emulated/0/Download/Nature_Beautiful_short_video_720p_HD.mp4","-strict","-2","-vcodec","libx264","-preset","ultrafast","-acodec","aac","-ar","44100","-ac","1","-b:a","72k","-s","480x480","-aspect","1:1","-r","24","/storage/emulated/0/KhetiVadi/videoCompress/d272264d84d2c06f2bcd9f0c8471075a.mp4"}` – Dharmishtha Aug 10 '17 at 07:47
6

After a long time struggling and trying to compile FFmpeg in different ways, I found the solution. Make sure to compile FFmpeg with the --disable-asm flag. This will make sure that FFmpeg wouldn't have text relocations and won't crash when compiling against Android M (SDK 23)

To make sure it worked, you can use readelf as mentioned above.

Cheers

Ozzz
  • 342
  • 5
  • 12
  • Hi i am using windows machine, can you let us know how to recompile the source, if it could be done in Linux/Ubuntu only kindly let me know a valid latest steps for the building. Right now i am using prebuilt .so libraries provided with ffmpeg4android_demo, I am stuck at same position that you were, I tried compiling the source but it was a fail. If you have your own fork kindly guide. – Arun May 18 '16 at 16:41
  • You have to compile ffmpeg alone and don't use pre-built .so because they will still have the text relocations problem. – Ozzz Jun 03 '16 at 14:20
  • Thanks for your input. – Arun Jun 05 '16 at 15:24
  • No problem, let me know if it helped – Ozzz Jun 08 '16 at 07:53
  • 1
    A note to anyone who sees this in the future - using -disable-asm with FFmpeg results in a performance hit. See this discussion thread on the FFmpeg issue tracker: https://trac.ffmpeg.org/ticket/4928 – Francesca Nannizzi Oct 10 '16 at 19:56
  • @Ozzz I am using Videokit library. Can you please let me know how can I compile FFMpeg with the --disable-asm flag on? – Subash May 16 '17 at 17:10
  • I have never used this lib but it looks like that the Videokit library is already taking care of that because their sample code has a compileSdkVersion 25. – Ozzz May 17 '17 at 21:48
  • how to compile the .so file to remove the text relocation error?@Ozzz – Arslan Maqbool Aug 03 '17 at 12:44
  • Make sure to compile FFmpeg with the --disable-asm flag. – Ozzz Aug 04 '17 at 09:56
  • @Arun please tell the way how to implement this in android project . – Dharmishtha Aug 10 '17 at 09:32
  • @Dharmishtha, quite delayed to reply you, Please use prebuilt library rather than trying to compile on your own. please let me know your issue in detail if still any. – Arun Aug 23 '17 at 21:23
2

I received feedback from metaio's SDK team. They say that this issue cannot be easily solved by metaio, as it is related to the FFMpeg library. We would have to hope that an update of FFMpeg would fix the issue. I assume that we have to wait for such an update and to exchange the library files in the app.

I have not yet looked for a FFMpeg developer contact forum to make enquiries or to notify a bug. Do you know one by accident?

Best regrads, christin

christin
  • 594
  • 5
  • 9
  • 1
    Thanks again for your time! Excuse me if I didn't gave you news but I still haven't received any answer from the Metaio team. Unfortunately I don't know any FFMpeg forum so I can't help you.. I hope we'll get an update but i'm pretty skeptical about it.. If I have any news i'll answer you here! Thanks again!! – LS_ Sep 16 '15 at 15:07
  • I have tryed new updated FFMpeg libraries. Now it gives another error: java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "avcodec_register_all" referenced by "/data/app/it.productlab.card-1/lib/arm/libmetaiosdk.so"... Looks like there are references from within libmetaiosd.so file, meaning that all so libraries was compiled in tandem with metaio library, and it can not be solved without metaio now.... – kolodi Jun 27 '16 at 11:28
  • Maybe it's the FFMpeg version. – user949884 Oct 13 '16 at 07:06