Bug 47607 - Not able to run the app on x86_64 Android devices after adding a package dependency with x86_64 library
Summary: Not able to run the app on x86_64 Android devices after adding a package depe...
Status: NEEDINFO
Alias: None
Product: Android
Classification: Xamarin
Component: Linker ()
Version: 7.0 (C8)
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Radek Doulik
URL:
Depends on:
Blocks:
 
Reported: 2016-11-21 23:05 UTC by Evgeny
Modified: 2017-10-17 02:19 UTC (History)
10 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report for Bug 47607 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
NEEDINFO

Description Evgeny 2016-11-21 23:05:37 UTC
Steps to reproduce:
1) Create an Android project that does not have x86_64 in the list of enabled architectures.
2) Link project to a package that has an Android library with an x86_64 build. SQLitePCLRaw is one example.
3) Build the app and try to run it on a x86_64 device or simulator.

Result:
App crashes on startup with the following output
java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/<package>-1/base.apk"],nativeLibraryDirectories=[/data/app/<package>-1/lib/x86_64, /data/app/<package>-1/base.apk!/lib/x86_64, /vendor/lib64, /system/lib64]]] couldn't find "libmonodroid.so"
	at java.lang.Runtime.loadLibrary(Runtime.java:367)
	at java.lang.System.loadLibrary(System.java:1076)
	at mono.MonoPackageManager.LoadApplication(MonoPackageManager.java:34)
	at mono.MonoRuntimeProvider.attachInfo(MonoRuntimeProvider.java:22)
	at android.app.ActivityThread.installProvider(ActivityThread.java:5341)
	at android.app.ActivityThread.installContentProviders(ActivityThread.java:4936)
	at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4876)
	at android.app.ActivityThread.access$1700(ActivityThread.java:156)
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1471)
	at android.os.Handler.dispatchMessage(Handler.java:102)
	at android.os.Looper.loop(Looper.java:148)
	at android.app.ActivityThread.main(ActivityThread.java:5608)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:746)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)

It looks like the app is built incorrectly in this case. I can see that the APK file has libs/x86_64 folder with a single file libe_sqlite3.so in it. This probably makes package manager believe that app has x86_64 build even though x86_64 architecture is un-checked in the project settings.

Expected result:
The APK file should not contain libs/x86_64 folder unless it is enabled in the project settings.

Workaround:
Enable x86_64 architecture in the project settings. This increases the APK size but fixes the problem.
Comment 1 Evgeny 2016-11-21 23:11:46 UTC
Strangely, this is limited to x86_64 architecture, but not arm64-v8a
Comment 2 Jahmai 2017-03-20 07:33:33 UTC
I have this problem with Xamarin.Android 7.1, did you ever resolve it? We need to manually pack the APK in order to fix it.
Comment 3 Chris Riesgo 2017-05-04 12:59:26 UTC
I'm seeing this issue too, but in the 15.2 Beta Preview 2. Please help. Because of another open issue, the workaround listed above (Enabling x86_64 architecture) cannot work. 

Here's a link to the other issue that compounds my problem with this one:

https://bugzilla.xamarin.com/show_bug.cgi?id=55087
Comment 4 Christophe Oosterlynck 2017-07-03 12:30:56 UTC
We are having the same issue. Is there a fix planned for this?
Comment 5 John Miller [MSFT] 2017-07-05 17:25:25 UTC
Thank you for taking the time to submit the bug. We are unable to reproduce this issue. Please attach a reproduction to the bug by starting with a clean Xamarin.Android project and adding just the code necessary to demonstrate the issue.

Please also attach your version information to confirm which version of Xamarin.Android is being used. Thanks!
Comment 6 Christophe Oosterlynck 2017-07-07 11:21:42 UTC
Xamarin.Android version 7.1.0.43

I haven't had time yet to setup a demo project or test it on a more recent version of Xamarin.Android but I think I did find the source of the problem: 

https://github.com/xamarin/xamarin-android/blob/a35e52abed7468e359918f913270fafc8f5a1cfc/src/Xamarin.Android.Build.Tasks/Tasks/BuildApk.cs#L532

"x86/library.so" and "x86_64/library.so" both contain the string "x86". So when compiling for x86 but not for x86_64, still both libraries are being put in the apk

Resulting lib folder in the APK:

lib/x86/library.so
lib/x86/libmonodroid.so
lib/x86/libmonosgen-2.0.so
lib/x86_64/library.so
Comment 7 Jahmai 2017-07-19 00:31:18 UTC
Can someone change the status of this bug? It looks like the problem has been identified and just needs a fix.

This issue is bloating our app due to needing to include x86_64 unnecessarily to work around it, otherwise the app crashes on x86_64 devices.
Comment 8 Jahmai 2017-08-11 01:55:37 UTC
Anyone?... Please update the status of this issue from NEEDINFO to something else.
Comment 9 Nathan Westfall 2017-08-30 17:43:15 UTC
Please see this follow pull request.  It contains a fix and test project.  I was testing using a x86_64 device.
Comment 10 Nathan Westfall 2017-08-30 17:43:24 UTC
Sorry, forgot the link. https://github.com/xamarin/xamarin-android/pull/796
Comment 11 Nathan Westfall 2017-09-01 19:30:20 UTC
Pull request was merged into master and confirmed using nightly build that this fixes the problem.
Comment 12 tomas_nemec 2017-10-15 08:10:09 UTC
I am having the same issue with VS for Mac 7.2 and Xamarin Android 8.0.33 when trying to build my MonoGame application.

When I select armeabi v7 + x86 as my release architectures (leaving x86_64 unselected) and then generate the APK the resulting file contains wrong dlls:

lib/armeabi-v7a/libmonodroid.so
lib/armeabi-v7a/libmonosgen-2.0.so
lib/armeabi-v7a/libopenal32.so
lib/x86/libmonodroid.so
lib/x86/libmonosgen-2.0.so
lib/x86/libopenal32.so
lib/x86_64/libopenal32.so

Has the fix in develop not got into 8.0.0.33 or is there another place where the bug needs to be fixed?
Comment 13 Nathan Westfall 2017-10-17 02:19:08 UTC
I can confirm this went out in the Visual Studio 2017 15.5 Preview 1.  I actually just did a build today with this change using it.

You must be using Xamarin Android 8.1

If you don't want VS Preview, just pull Xamarin Android 8.1 from here

https://jenkins.mono-project.com/view/Xamarin.Android/job/xamarin-android-builds-d15-5/