简体   繁体   中英

Exception when starting android xamarin forms app

I got the following exception within Xamarin in VS 2017 when I change the build configuration from Debug to Release :

07-07 14:34:49.820 D/AccessibilityManager(10619): setStateLocked: wasEnabled = false, mIsEnabled = false, wasTouchExplorationEnabled = false, mIsTouchExplorationEnabled = false, wasHighTextContrastEnabled = false, mIsHighTextContrastEnabled = false
07-07 14:34:49.820 D/AccessibilityManager(10619): java.lang.Throwable: setStateLocked
07-07 14:34:49.820 D/AccessibilityManager(10619):   at android.view.accessibility.AccessibilityManager.setStateLocked(AccessibilityManager.java:553)
07-07 14:34:49.820 D/AccessibilityManager(10619):   at android.view.accessibility.AccessibilityManager.tryConnectToServiceLocked(AccessibilityManager.java:636)
07-07 14:34:49.820 D/AccessibilityManager(10619):   at android.view.accessibility.AccessibilityManager.<init>(AccessibilityManager.java:226)
07-07 14:34:49.820 D/AccessibilityManager(10619):   at android.view.accessibility.AccessibilityManager.getInstance(AccessibilityManager.java:206)
07-07 14:34:49.820 D/AccessibilityManager(10619):   at android.view.View.setFlags(View.java:9843)
07-07 14:34:49.820 D/AccessibilityManager(10619):   at android.view.ViewGroup.initViewGroup(ViewGroup.java:536)
07-07 14:34:49.820 D/AccessibilityManager(10619):   at android.view.ViewGroup.<init>(ViewGroup.java:525)
07-07 14:34:49.820 D/AccessibilityManager(10619):   at android.view.ViewGroup.<init>(ViewGroup.java:520)
07-07 14:34:49.820 D/AccessibilityManager(10619):   at android.support.v7.widget.Toolbar.<init>(Toolbar.java:200)
07-07 14:34:49.820 D/AccessibilityManager(10619):   at android.support.v7.widget.Toolbar.<init>(Toolbar.java:196)
07-07 14:34:49.820 D/AccessibilityManager(10619):   at java.lang.reflect.Constructor.newInstance(Native Method)
07-07 14:34:49.820 D/AccessibilityManager(10619):   at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
07-07 14:34:49.820 D/AccessibilityManager(10619):   at android.view.LayoutInflater.createView(LayoutInflater.java:607)
07-07 14:34:49.820 D/AccessibilityManager(10619):   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
07-07 14:34:49.820 D/AccessibilityManager(10619):   at android.view.LayoutInflater.inflate(LayoutInflater.java:482)
07-07 14:34:49.820 D/AccessibilityManager(10619):   at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
07-07 14:34:49.820 D/AccessibilityManager(10619):   at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
07-07 14:34:49.820 D/AccessibilityManager(10619):   at md5fcb90111a512f6bdf8650a2bd92e7238.MainActivity.n_onCreate(Native Method)
07-07 14:34:49.820 D/AccessibilityManager(10619):   at md5fcb90111a512f6bdf8650a2bd92e7238.MainActivity.onCreate(MainActivity.java:31)
07-07 14:34:49.820 D/AccessibilityManager(10619):   at android.app.Activity.performCreate(Activity.java:6092)
07-07 14:34:49.820 D/AccessibilityManager(10619):   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1112)
07-07 14:34:49.820 D/AccessibilityManager(10619):   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2468)
07-07 14:34:49.820 D/AccessibilityManager(10619):   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2595)
07-07 14:34:49.820 D/AccessibilityManager(10619):   at android.app.ActivityThread.access$800(ActivityThread.java:178)
07-07 14:34:49.820 D/AccessibilityManager(10619):   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1470)
07-07 14:34:49.820 D/AccessibilityManager(10619):   at android.os.Handler.dispatchMessage(Handler.java:111)
07-07 14:34:49.820 D/AccessibilityManager(10619):   at android.os.Looper.loop(Looper.java:194)
07-07 14:34:49.820 D/AccessibilityManager(10619):   at android.app.ActivityThread.main(ActivityThread.java:5631)
07-07 14:34:49.820 D/AccessibilityManager(10619):   at java.lang.reflect.Method.invoke(Native Method)
07-07 14:34:49.820 D/AccessibilityManager(10619):   at java.lang.reflect.Method.invoke(Method.java:372)
07-07 14:34:49.820 D/AccessibilityManager(10619):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959)
07-07 14:34:49.820 D/AccessibilityManager(10619):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)
07-07 14:34:49.831 W/art     (10619): Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable

All I see from my app is a white screen. And as soon as I change the configuration back to Debug everything is working fine.

Some days ago before I have changed quite a lot on the GUI, everything was working fine. The problem is that I have no idea what the exception message is meaning. What is StateLocked?

As proposed from a comment I add below some more parts of my code:

MainActivity.cs:

[Activity(Label = "enio.TrackR", Icon = "@drawable/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
    protected override void OnCreate(Bundle bundle)
    {
        TabLayoutResource = Resource.Layout.Tabbar;
        ToolbarResource = Resource.Layout.Toolbar;

        base.OnCreate(bundle);

        global::Xamarin.Forms.Forms.Init(this, bundle);
        LoadApplication(new App());
    }
    protected override void OnStart()
    {
        base.OnStart();
        StartService(new Intent(this, typeof(LocationService)));

    }
}

I believe you need to change

StartService(new Intent(this, typeof(LocationService)));

To

Intent serviceIntent = new Intent(this, typeof(LocationActivity));
context.StartActivity(serviceIntent);

Someone gave me the advice to change the linking option in the Android project properties from "Sdk and User Assemblies" to "Sdk Assemblies Only". This solved the issue and I could start and deploy the app to the playstore.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM