How to resolve Xamarin Android linking problem - xamarin.forms

My Xamarin Forms Android app works fine in Debug. But in Release, when deployed to either the emulator or to a device, the app is "stopped" after showing the splash screen. The debug log shows these errors, indicating that it can't find class FitWindowsLinearLayout...
10-23 22:24:59.270 14008 14008 E AndroidRuntime: Caused by:
android.view.InflateException: Binary XML file line #14: Binary XML
file line #14: Error inflating class
android.support.v7.widget.FitWindowsLinearLayout
10-23 22:24:59.270 14008 14008 E AndroidRuntime: Caused by:
android.view.InflateException: Binary XML file line #14: Error
inflating class android.support.v7.widget.FitWindowsLinearLayout
10-23 22:24:59.270 14008 14008 E AndroidRuntime: Caused by:
java.lang.ClassNotFoundException: Didn't find class
"android.support.v7.widget.FitWindowsLinearLayout" on path:
DexPathList[[zip file
"/data/app/zeemerix.NflCalcXF-1/base.apk"],nativeLibraryDirectories=[/data/app/zeemerix.NflCalcXF-1/lib/arm,
/data/app/zeemerix.NflCalcXF-1/base.apk!/lib/armeabi-v7a, /system/lib,
/vendor/lib]]
Changing Linking to "None" resolves the problem, but then the APK is very large.
Should I use "Skip Linking Assemblies"? If so, what to enter?
I tried using a Proguard profile, but when I do, then the MainPage appears as a blank screen, and the debug log says it can't find Help_ObClick(), which is an event handler in the MainPage code behind. The profile I used is this...
-dontobfuscate
-keep class android.support.v7.widget.** { *; }
-dontwarn android.support.v7.widget.**
-keep class android.support.v4.widget.Space { *; }
-dontwarn android.support.v4.widget.Space
My Android Options:
Off: Use shared runtime
On: Enable Proguard
On: Enable developer instrumentation
Linking: Sdk and User Assemblies [Setting it to None resolves problem]
Compile using Android version: 8.1
Min Android version: 7.0
Target Android version: 8.1
My setup:
VS Community 2017, Version 15.7.3
Xamarin 4.10.10.1
Xamarin Android SDK 8.3.3.2
Xamarin Forms 3.3.0.912540
Xamarin support libraries v27.0.2.1

As you know linking 'None' works, try then linking 'Sdk Assemblies Only'
If that doesn't work, then you can go into your build folder, copy all the names of all the assemblies minus extension and add them to the "Skip linking assemblies" field
Then set linking to 'Sdk and User Assemblies' and try again.
It will take forever but then remove each of these files from the list until you find the one(s) that cause the problem.
For me it was much easier as Link 'Sdk Assemblies Only' worked so i could eliminate all the Sdk assemblies found here:
https://learn.microsoft.com/en-us/xamarin/cross-platform/internals/available-assemblies
The user list was much smaller and thus process of elimination much quicker...
Fwiw, libraries that use reflection are often a problem as they cant be easily identified as used before compile and get marked for delete.
In my case it was Json.Net, RestSharp and the like....
My published app size is only a third what it would have been otherwise...

if you want to link SDK and User Assemblies you have to skip linking your .net standard and any projects you use, like customControls in my project.
There are many other ways to do this but this is easier.

Related

How can i fix Bad JNI version returned from JNI_OnLoad error on flutter

When I extract the app as apk and test it on a real Android device, it crashes, but when I run it as debug it works fine. The cause of the error is pub.dev --> video_editor library. I got this error output from Firebase:
Caused by java.lang.UnsatisfiedLinkError:
Bad JNI version returned from JNI_OnLoad in "/data/app/com.projectName--b7nYjATxtDAUxnuC_rpnQ==/base.apk!/lib/armeabi-v7a/libmobileffmpeg.so": 0
java.lang.Runtime.loadLibrary0 (Runtime.java:1016)
java.lang.System.loadLibrary (System.java:1657)
com.arthenica.mobileffmpeg.Config.<clinit> (Config.java:146)
com.arthenica.mobileffmpeg.Config.nativeFFprobeExecute (Config.java)
com.arthenica.mobileffmpeg.FFprobe.execute (FFprobe.java)
com.arthenica.mobileffmpeg.FFprobe.getMediaInformationFromCommandArguments (FFprobe.java)
com.arthenica.mobileffmpeg.FFprobe.getMediaInformation (FFprobe.java:48)
com.arthenica.flutter.ffmpeg.FlutterFFmpegGetMediaInformationAsyncTask.doInBackground (FlutterFFmpegGetMediaInformationAsyncTask.java:21)
com.arthenica.flutter.ffmpeg.FlutterFFmpegGetMediaInformationAsyncTask.doInBackground (FlutterFFmpegGetMediaInformationAsyncTask.java:2)
android.os.AsyncTask$2.call (AsyncTask.java:333)
java.util.concurrent.FutureTask.run (FutureTask.java:266)
java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1162)
java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:636)
java.lang.Thread.run (Thread.java:764)
Enabling ProGuard on releases older than v0.2.4 causes linking errors. Please add the following rule inside your proguard-rules.pro file to preserve necessary method names and prevent linking errors.
-keep class com.arthenica.mobileffmpeg.Config {
native <methods>;
void log(int, byte[]);
void statistics(int, float, float, long , int, double, double);
}
and also make sure that mavenCentral() is defined as a repository in your build.gradle and it is listed before jcenter().
Refer from flutter ffmpeg documentation https://pub.dev/packages/flutter_ffmpeg

Xamarin.Forms problems with Embedded Resources and Proguard

I have two different applications, both using files that I've included in my Xamarin.Forms project's root. The files are set as Embedded Resources under "Build Action" and then fetched using the code below.
var assembly = Assembly.GetExecutingAssembly();
Stream stream = assembly.GetManifestResourceStream("test.text.json");
This approach works just fine with all compilation options such as AoT and LLVM, except for when Proguard is involved. If the application is compiled using Proguard it will just instantly force close without being able to read the files.
So far I've tried making exceptions for the classes in the project using a custom proguard.cfg-file that is set as my "ProguardConfiguration" in VS 2017.
-dontobfuscate
-keep class com.companyname.test** { *; }
-keeppackagenames com.companyname.test**
This has not yielded any results. The application still crashes instantly. Every other application using Proguard is working just fine as long as it's not loading any files locally. Should I use a different way of loading files or can I exclude anything else in my Proguard configuration to make this work?
EDIT: Just updating this post to draw attention to the solution. It turns out I have solved this problem before but for some reason it seems to be back. Here is the log output:
android.view.InflateException: Binary XML file line #20: Binary XML file
line #20: Error inflating class android.support.v7.widget.FitWindowsFrameLayout
Which is something that I have already added to my general Proguard rules without me having to add a special Proguard configuration to my project. As a solution this time I simply added these two lines to my proguard.cfg file:
-keep public class android.support.v7.widget.** { *; }
-dontwarn android.support.**
Thanks Alen.Toma for pointing me in the right direction.

AspectRatioFrameLayout duplicate entry in google-vr sdk, when project already uses EXO player library

My application already uses ExoPlayer from google.
I want to add google-vr sdk to it.
But I have got error:
Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/android/exoplayer/AspectRatioFrameLayout.class
Problem is that google-vr sdk alredy contains ExoPlayer inside, and I can not modify google-vr sdk as it is distributed as aar android library.
Here is part of my dependencies:
dependencies {
// exo player
compile 'com.google.android.exoplayer:exoplayer:r1.5.0'
// Google VR SDK
compile project(':gvr-common')
compile project(':gvr-commonwidget')
compile project(':gvr-videowidget')
}
Would be very happy for any suggestions.
Use this:
compile 'com.google.android.exoplayer:exoplayer:r2.4.0'
compile 'com.google.android.exoplayer:exoplayer-core:r2.4.0'
compile 'com.google.android.exoplayer:exoplayer-dash:r2.4.0'
compile 'com.google.android.exoplayer:exoplayer-hls:r2.4.0'
compile 'com.google.android.exoplayer:exoplayer-smoothstreaming:r2.4.0'
And keep the minimum sdk version to 21 and remove the Google VR SDK

Configuration files are ignored after migrating to Servicemix 5

We use a .cfg file in ./etc directory to configure our bundle in ServiceMix. Everything worked fine in SMX 4.5.3, but when migrating to the 5th version the file is not picked up. When the bundle encounters a property the following exception is thrown:
java.lang.IllegalArgumentException: Property with key [xslt.dir] not found in properties from text: {{xslt.dir}}, StackTrace: org.apache.camel.RuntimeCamelException: java.lang.IllegalArgumentException: Property with key [xslt.dir] not found in properties from text: {{xslt.dir}}
However, if I put the properties in default-properties section in my blueprint configuration, it works.
Also, the console command config:list actually shows the properties for the bundle in spite of the exception:
Pid: misrouter
BundleLocation: mvn:ru.mig/mis-router/1.0-SNAPSHOT
Properties:
service.pid = misrouter
felix.fileinstall.filename = file:/home/petr/programs/5.0.0-apache-servicemix/etc/misrouter.cfg
xslt.dir = /home/petr/programs/5.0.0-apache-servicemix/xslt
So was something changed in SMX 5 configuration mechanism or is there a bug in it?
What version of the JDK/JRE are you using? When I was trying this out a few minutes ago to answer your question, I also had some problems using the 1.7.0_15 version I had installed and upgrading to the latest 1.7.0_51 fixed those for me.
Actually it's related to Camel vm component, a bug was created for SMX

Automation_agent and qtp_air resource bundles not found when adding automation libs to AIR project

I'm trying to add the automation libraries to my project in Flash Builder so we can automate our testing.
I've added this to the additional compiler settings:
-include-libraries+="${flexlib}/libs/automation/automation.swc","${flexlib}/libs/automation/automation_agent.swc","${flexlib}/libs/automatio n/automation_dmv.swc","${flexlib}/libs/automation/automation_spark.swc ","${flexlib}/libs/automation/automation_air.swc","${flexlib}/libs/aut omation/automation_airspark.swc","${flexlib}/libs/automation/qtp_air.swc"
and -locale nl_BE fr_BE
After compiling this I get 2 errors:
Unable to resolve resource bundle "automation_agent"
Unable to resolve resource bundle "qtp_air"
However, in my nl_BE and fr_BE folders under flex_sdk\frameworks\locale\ the automation_agent_rb.swc and qtp_air_rb.swc are present.
If I switch to en_US, it works fine.
Can somebody explain to me why Flash Builder can't find these resource bundles?
Try explicitly adding automation_agent_rb.swc and qtp_air_rb.swc to your library-path as well.

Resources