Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin linking SDK and UserAssemblies: Error inflating class android.support.v7.widget.FitWindowsFrameLayout

My app is working without linking. It works fine also when I choose Sdk Assemblies only. It works fine in debug mode as well but it start failing if I choose linking SDk and UserAssemblies. I checked the logs and i find only what is below. I google all around for android, xamarin.android erros and people are talking about using Frames. I dont use any android native code. there is no frame defined in my android project. i am not sure if that is xamarin.forms producing but Can you please help me how to solve this problem?

there are similar questions like below. I already went through them no answer looks like related to my one. Even when I google "android.support.v7.widget.FitWindowsFrameLayout", I dont find any error about it. what is this class for? I am not referring to it all. Error indicates me about line number 23 and I check the 23 in my manifest, there I have the line <receiver android:name="com.onesignal.NotificationOpenedReceiver" />. I excluded it and tried, error didnt change. Please lead me where should I look, if you need more information, I am going to update this question.

Error inflating class android.support.v7.widget.Toolbar?

01-24 18:54:47.344: E/AndroidRuntime(30427): java.lang.RuntimeException: Unable to start activity ComponentInfo{myapp.myapp/md5874faab2802fcbafca06095cc637d65d.MainActivity}: android.view.InflateException: Binary XML file line #23: Binary XML file line #23: Error inflating class android.support.v7.widget.FitWindowsFrameLayout
    01-24 18:54:47.344: E/AndroidRuntime(30427):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2464)
    01-24 18:54:47.344: E/AndroidRuntime(30427):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2524)
    01-24 18:54:47.344: E/AndroidRuntime(30427):    at android.app.ActivityThread.access$900(ActivityThread.java:154)
    01-24 18:54:47.344: E/AndroidRuntime(30427):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1391)
    01-24 18:54:47.344: E/AndroidRuntime(30427):    at android.os.Handler.dispatchMessage(Handler.java:102)
    01-24 18:54:47.344: E/AndroidRuntime(30427):    at android.os.Looper.loop(Looper.java:234)
    01-24 18:54:47.344: E/AndroidRuntime(30427):    at android.app.ActivityThread.main(ActivityThread.java:5526)
    01-24 18:54:47.344: E/AndroidRuntime(30427):    at java.lang.reflect.Method.invoke(Native Method)
    01-24 18:54:47.344: E/AndroidRuntime(30427):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
    01-24 18:54:47.344: E/AndroidRuntime(30427):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
    01-24 18:54:47.344: E/AndroidRuntime(30427): Caused by: android.view.InflateException: Binary XML file line #23: Binary XML file line #23: Error inflating class android.support.v7.widget.FitWindowsFrameLayout
    01-24 18:54:47.344: E/AndroidRuntime(30427):    at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
    01-24 18:54:47.344: E/AndroidRuntime(30427):    at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
    01-24 18:54:47.344: E/AndroidRuntime(30427):    at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
    01-24 18:54:47.344: E/AndroidRuntime(30427):    at android.support.v7.app.AppCompatDelegateImplV7.createSubDecor(AppCompatDelegateImplV7.java:410)
    01-24 18:54:47.344: E/AndroidRuntime(30427):    at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:309)
    01-24 18:54:47.344: E/AndroidRuntime(30427):    at android.support.v7.app.AppCompatDelegateImplV7.initWindowDecorActionBar(AppCompatDelegateImplV7.java:171)
    01-24 18:54:47.344: E/AndroidRuntime(30427):    at android.support.v7.app.AppCompatDelegateImplBase.getSupportActionBar(AppCompatDelegateImplBase.java:88)
    01-24 18:54:47.344: E/AndroidRuntime(30427):    at android.support.v7.app.AppCompatDelegateImplV7.setSupportActionBar(AppCompatDelegateImplV7.java:195)
    01-24 18:54:47.344: E/AndroidRuntime(30427):    at android.support.v7.app.AppCompatActivity.setSupportActionBar(AppCompatActivity.java:126)
    01-24 18:54:47.344: E/AndroidRuntime(30427):    at md5874faab2802fcbafca06095cc637d65d.MainActivity.n_onCreate(Native Method)
    01-24 18:54:47.344: E/AndroidRuntime(30427):    at md5874faab2802fcbafca06095cc637d65d.MainActivity.onCreate(MainActivity.java:32)
    01-24 18:54:47.344: E/AndroidRuntime(30427):    at android.app.Activity.performCreate(Activity.java:6285)
    01-24 18:54:47.344: E/AndroidRuntime(30427):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108)
    01-24 18:54:47.344: E/AndroidRuntime(30427):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2417)
    01-24 18:54:47.344: E/AndroidRuntime(30427):    ... 9 more
    01-24 18:54:47.344: E/AndroidRuntime(30427): Caused by: android.view.InflateException: Binary XML file line #23: Error inflating class android.support.v7.widget.FitWindowsFrameLayout
    01-24 18:54:47.344: E/AndroidRuntime(30427):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:776)
    01-24 18:54:47.344: E/AndroidRuntime(30427):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
    01-24 18:54:47.344: E/AndroidRuntime(30427):    at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
    01-24 18:54:47.344: E/AndroidRuntime(30427):    ... 22 more
    01-24 18:54:47.344: E/AndroidRuntime(30427): Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.widget.FitWindowsFrameLayout" on path: DexPathList[[zip file "/data/app/myapp.myapp-1/base.apk"],nativeLibraryDirectories=[/data/app/myapp.myapp-1/lib/arm, /data/app/myapp.myapp-1/base.apk!/lib/armeabi-v7a, /vendor/lib, /system/lib]]
    01-24 18:54:47.344: E/AndroidRuntime(30427):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
    01-24 18:54:47.344: E/AndroidRuntime(30427):    at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
    01-24 18:54:47.344: E/AndroidRuntime(30427):    at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
    01-24 18:54:47.344: E/AndroidRuntime(30427):    at android.view.LayoutInflater.createView(LayoutInflater.java:583)
    01-24 18:54:47.344: E/AndroidRuntime(30427):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764)
    01-24 18:54:47.344: E/AndroidRuntime(30427):    ... 24 more
    01-24 18:54:47.344: E/AndroidRuntime(30427):    Suppressed: java.lang.ClassNotFoundException: android.support.v7.widget.FitWindowsFrameLayout
    01-24 18:54:47.344: E/AndroidRuntime(30427):        at java.lang.Class.classForName(Native Method)
    01-24 18:54:47.344: E/AndroidRuntime(30427):        at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
    01-24 18:54:47.344: E/AndroidRuntime(30427):        at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
    01-24 18:54:47.344: E/AndroidRuntime(30427):        at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
    01-24 18:54:47.344: E/AndroidRuntime(30427):        ... 27 more
    01-24 18:54:47.344: E/AndroidRuntime(30427):    Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available

MANIFEST:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="myapp.myapp" android:versionCode="1"
 android:versionName="1.0" android:installLocation="preferExternal">
    <uses-sdk android:minSdkVersion="15" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.ACCESS_NOTIFICATION_POLICY" />
    <uses-feature android:name="android.hardware.sensor.accelerometer" android:required="true" />
    <application android:label="myApp" android:icon="@drawable/icon">
        <meta-data android:name="onesignal_app_id" android:value="346457689798" />
        <meta-data android:name="onesignal_google_project_number" android:value="134654677" />
        <receiver android:name="com.onesignal.GcmBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND">
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <category android:name="com.companyname.example.shared.application.droid" />
            </intent-filter>
        </receiver>
        <receiver android:name="com.onesignal.NotificationOpenedReceiver" />
        <service android:name="com.onesignal.GcmIntentService" />
        <service android:name="com.onesignal.SyncService" android:stopWithTask="false" />
        <activity android:name="com.onesignal.PermissionsActivity" android:theme="@android:style/Theme.Translucent.NoTitleBar" />
        <activity android:name="com.google.android.gms.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
        android:theme="@android:style/Theme.Translucent" />
    </application>
</manifest>

STYLE.XML

<?xml version="1.0" encoding="utf-8" ?>
<resources> 
  <style name="MyTheme" parent="MyTheme.Base">
    <item name="android:windowBackground">@drawable/launch_logo</item>
  </style> 
  <style name="MyTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">   
    <item name="windowNoTitle">true</item>    
    <item name="windowActionBar">false</item>   
    <item name="colorPrimary">#00FFFF</item>   
    <item name="colorPrimaryDark">#1976D2</item>    
    <item name="colorAccent">#FF4081</item>    
    <item name="windowActionModeOverlay">true</item>
    <item name="android:datePickerDialogTheme">@style/AppCompatDialogStyle</item>    
  </style>  
  <style name="AppCompatDialogStyle" parent="Theme.AppCompat.Light.Dialog">
    <item name="colorAccent">#FF4081</item>
    <item name="windowNoTitle">true</item>
  </style>
</resources>

TOOLBAR.AXML

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?attr/colorPrimary"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    android:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

TABBAR.AXML

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.TabLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/sliding_tabs"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?attr/colorPrimary"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    app:tabIndicatorColor="@android:color/white"
    app:tabGravity="fill"
    app:tabMode="fixed" />

LAUNCH_LOGO.xml

<?xml version="1.0" encoding="utf-8" ?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" android:opacity="opaque">
  <item>
    <color android:color="@color/background_material_light"/>
  </item>
  <item>
    <bitmap
        android:src="@drawable/ic_splash"
        android:tileMode="disabled"
        android:gravity="center"/>
  </item>
  <item>
    <bitmap
        android:src="@drawable/splash_text"
        android:tileMode="disabled" 
        android:gravity="bottom" 
        />
  </item>  
</layer-list>

MAINACTIVITY

 [Activity(Label = "myApp",
        Icon = "@drawable/icon",
        Theme = "@style/MyTheme",
         MainLauncher = true,
        ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
    public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
    {
        public static Android.App.Activity current;

        protected override void OnCreate(Bundle bundle)
        {

            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource = Resource.Layout.Toolbar;

            base.OnCreate(bundle);   
like image 336
Emil Avatar asked Jan 24 '17 21:01

Emil


3 Answers

Try change ProGuard configuration.

I found great article with ProGuard configuration which fixes the missing "android.support.v7.widget.FitWindowsFrameLayout" problem ("Solution 2: ProGuard" in the article):

http://shaneneuville.com/firebase/proguard/2017/06/17/firebase-proguard-fun.html

ProGuard configuration from article:

-keep class com.google.android.gms.** { *; }
-dontwarn com.google.android.gms.**
-keep class com.microsoft.windowsazure.messaging.** { *; }
-dontwarn com.microsoft.windowsazure.messaging.**
-keep class com.google.firebase.** { *; }
-dontwarn com.google.firebase.**
-keep class android.support.v7.widget.** { *; }
-dontwarn android.support.v7.widget.**
-keep class android.support.v4.widget.Space { *; }
-dontwarn android.support.v4.widget.Space

You should clean solution after any ProGuard configuration changes.

like image 80
Jiří Kuba Avatar answered Nov 10 '22 01:11

Jiří Kuba


Try to exclude Android.Support v7 and v4 from the linker.

In XamarinStudio: Project Options -> Android Build -> Linker -> Ignore assemblies

add Xamarin.Android.Support.v7.AppCompat;Xamarin.Android.Support.v4

Linker settings for android support libraries in Xamarin

like image 40
MariusK Avatar answered Nov 09 '22 23:11

MariusK


It's stripped by the linker so you can "trick it " and simulate a false usage like this :

static bool falseflag = false;
static LinkerPleaseInclude()
{
    if (falseflag)
    {
        var ignore = new FitWindowsFrameLayout(Application.Context);
    }
}

This is available in the Xamarin documentation too : https://developer.xamarin.com/guides/android/advanced_topics/linking/

like image 9
Jonathan ANTOINE Avatar answered Nov 10 '22 01:11

Jonathan ANTOINE