dotnet / android

.NET for Android provides open-source bindings of the Android SDK for use with .NET managed languages such as C#
MIT License
1.92k stars 525 forks source link

Xamarin Android 8.3 ignores android:extractNativeLibs in AndroidManifest.xml #1819

Closed BeanStalka closed 2 years ago

BeanStalka commented 6 years ago

Steps to Reproduce

  1. Create a Hello world Xamarin android app.

  2. Reference Mono

  3. inherit from the Application class OR manually edit the AndroidManifest.xml to include extractNativeLibs<application android:label="@string/app_name" android:extractNativeLibs="false"></application>

  4. Flip to Release config and build

  5. go to archive manager and distribute via ad-hoc

  6. find the APK in the signed folder

  7. Use (7.zip) "7z.exe - l" (thats a lowercase L) and list contents of the apk

  8. Note that the 'Compressed' column for the mono .so files is NOT the same as the 'Size' column.

Expected Behavior

The .so files listed via "7z.exe l" would have a 'Size' that matches the 'Compressed' IOW, NOT compressed. This would indicate that the "android:extractNativeLibs="false" flag in the manifest was being respected.

Actual Behavior

The .so files listed via "7z.exe l" command have a 'Compressed' column about half of the 'Size' column. IOW, compressed. This indicates that the "android:extractNativeLibs="false" flag in the manifest is being ignored.
IOW, the .so files remain compressed.

Version Information

Microsoft Visual Studio Community 2017 Version 15.7.1 VisualStudio.15.Release/15.7.1+27703.2000 Microsoft .NET Framework Version 4.7.03056

Installed Version: Community

Microsoft Visual Studio Tools for Applications 2017 00369-60000-00001-AA218 Microsoft Visual Studio Tools for Applications 2017

Visual C++ 2017 00369-60000-00001-AA218 Microsoft Visual C++ 2017

Application Insights Tools for Visual Studio Package 8.12.10405.1 Application Insights Tools for Visual Studio

ASP.NET and Web Tools 2017 15.0.40501.0 ASP.NET and Web Tools 2017

ASP.NET Core Razor Language Services 15.7.31476 Provides languages services for ASP.NET Core Razor.

ASP.NET Web Frameworks and Tools 2017 5.2.60419.0 For additional information, visit https://www.asp.net/

Azure App Service Tools v3.0.0 15.0.40424.0 Azure App Service Tools v3.0.0

Azure Data Lake Node 1.0 This package contains the Data Lake integration nodes for Server Explorer.

Azure Data Lake Tools for Visual Studio 2.3.3000.2 Microsoft Azure Data Lake Tools for Visual Studio

Azure Functions and Web Jobs Tools 15.0.40424.0 Azure Functions and Web Jobs Tools

Azure Stream Analytics Tools for Visual Studio 2.3.3000.2 Microsoft Azure Stream Analytics Tools for Visual Studio

C# Tools 2.8.0-beta6-62830-08. Commit Hash: e595ee276d14e14bfb3eb323fb57f2aa668bddea C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools 1.10 Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Fabric.DiagnosticEvents 1.0 Fabric Diagnostic Events

JavaScript Language Service 2.0 JavaScript Language Service

JavaScript Project System 2.0 JavaScript Project System

Merq 1.1.17-rc (cba4571) Command Bus, Event Stream and Async Manager for Visual Studio extensions.

Microsoft Azure HDInsight Azure Node 2.3.3000.2 HDInsight Node under Azure Node

Microsoft Azure Hive Query Language Service 2.3.3000.2 Language service for Hive query

Microsoft Azure Service Fabric Tools for Visual Studio 2.1 Microsoft Azure Service Fabric Tools for Visual Studio

Microsoft Azure Stream Analytics Language Service 2.3.3000.2 Language service for Azure Stream Analytics

Microsoft Azure Stream Analytics Node 1.0 Azure Stream Analytics Node under Azure Node

Microsoft Azure Tools 2.9 Microsoft Azure Tools for Microsoft Visual Studio 2017 - v2.9.10420.2

Microsoft Continuous Delivery Tools for Visual Studio 0.3 Simplifying the configuration of continuous build integration and continuous build delivery from within the Visual Studio IDE.

Microsoft JVM Debugger 1.0 Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Microsoft MI-Based Debugger 1.0 Provides support for connecting Visual Studio to MI compatible debuggers

Microsoft Visual C++ Wizards 1.0 Microsoft Visual C++ Wizards

Microsoft Visual Studio Tools for Containers 1.1 Develop, run, validate your ASP.NET Core applications in the target environment. F5 your application directly into a container with debugging, or CTRL + F5 to edit & refresh your app without having to rebuild the container.

Microsoft Visual Studio VC Package 1.0 Microsoft Visual Studio VC Package

Mono Debugging for Visual Studio 4.10.5-pre (ab58725) Support for debugging Mono processes with Visual Studio.

Node.js Tools 1.4.11027.3 Adds support for developing and debugging Node.js apps in Visual Studio

NuGet Package Manager 4.6.0 NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

ProjectServicesPackage Extension 1.0 ProjectServicesPackage Visual Studio Extension Detailed Info

ResourcePackage Extension 1.0 ResourcePackage Visual Studio Extension Detailed Info

SQL Server Data Tools 15.1.61804.210 Microsoft SQL Server Data Tools

SQL Server Integration Services
Microsoft SQL Server Integration Services Designer Version 14.0.800.98

ToolWindowHostedEditor 1.0 Hosting json editor into a tool window

TypeScript Tools 15.7.20419.2003 TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools 2.8.0-beta6-62830-08. Commit Hash: e595ee276d14e14bfb3eb323fb57f2aa668bddea Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual C++ for Cross Platform Mobile Development (Android) 15.0.27625.00 Visual C++ for Cross Platform Mobile Development (Android)

Visual F# Tools 10.1 for F# 4.1 15.7.0.0. Commit Hash: 16ecf5a30ad868d183c58e4a71a71c23d4ed3ba9. Microsoft Visual F# Tools 10.1 for F# 4.1

Visual Studio Code Debug Adapter Host Package 1.0 Interop layer for hosting Visual Studio Code debug adapters in Visual Studio

Visual Studio Tools for Apache Cordova 15.123.7408.1 Visual Studio Tools for Apache Cordova

Visual Studio Tools for CMake 1.0 Visual Studio Tools for CMake

VisualStudio.Mac 1.0 Mac Extension for Visual Studio

Windows Machine Learning Generator Extension 1.0 Windows Machine Learning Visual Studio Extension Detailed Info

Xamarin 4.10.0.442 (396b18cef) Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Designer 4.12.264 (fc37cd02e) Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin.Android SDK 8.3.0.19 (HEAD/342b2ce96) Xamarin.Android Reference Assemblies and MSBuild support.

Xamarin.iOS and Xamarin.Mac SDK 11.10.1.177 (7e782c1) Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.

Log File

jonathanpeppers commented 6 years ago

Yeah, I don't think Xamarin.Android supports this feature yet. But it's been around since Android 6.0?

Here is a good post from StackOverflow going over what android:extractNativeLibs is. Since we are manually packing the APK, we have to do something here to implement this.

BeanStalka commented 6 years ago

Jonathan

I know Android Studio respects the flag. Maybe you could draw inspiration from there.

I am looking for a work around while the Xamarin team implements a permanent fix.

Any workaround you think of please feel free to share it here and I will give it a go.

Thanks,

Bean

jonathanpeppers commented 6 years ago

Sorry... I think the only workaround is going to be to manually re-pack and re-sign the APK so that native libraries are uncompressed.

We also are shipping this feature in the next release: https://github.com/xamarin/xamarin-android/pull/1827

Perhaps you can then make this work by setting *.so files to be uncompressed?

BeanStalka commented 6 years ago

Jonathan, can you explain this?

Perhaps you can then make this work by setting .so files to be uncompressed? where would I set this ".so" value?

I looked at the link attached, but I do not know what piece of code you are commenting on

NaderMichael commented 6 years ago

Any updates?

JonDouglas commented 6 years ago

@BeanStalka I believe Jonathan was referring to using:

<AndroidStoreUncompressedFileExtensions>.so</AndroidStoreUncompressedFileExtensions>

Inside your project to workaround https://github.com/xamarin/xamarin-android/issues/1822

This is available in Xamarin.Android 9.0 and above.

NaderMichael commented 6 years ago

Is this workaround applicable to Xamarin.Forms v.3.1?

As I am using:

.so;.dll

But still see the compressed .so files within the generated APK, where the .dlls were uncompressed!!!

Any idea?

JonDouglas commented 6 years ago

@NaderMichael This workaround would be specifically for native libraries.

One example is the Android Things guideline:

https://developer.android.com/things/sdk/apis/native#packaging-native-code

extractNativeLibs requires the following to be true:

  1. The .so files inside the APK cannot be compressed - they must be stored.
  2. The .so files must be paged aligned using zipalign

The following is being tracked to more formally support this attribute:

https://github.com/xamarin/xamarin-android/issues/1906#issuecomment-401942316

jpobst commented 2 years ago

It looks like this has been fixed: https://github.com/xamarin/xamarin-android/pull/2579

ghost commented 2 years ago

We suspect this issue is stale and no longer relevant. It will be closed if no further activity occurs within 14 more days. Any new comment (by anyone, not necessarily the author) will undo this process.

ghost commented 2 years ago

This issue will now be closed since it had been marked possibly-stale but received no further activity in the past 14 days. It is still possible to reopen or comment on the issue, but please note that the issue will be locked if it remains inactive for another 30 days.