Xamarin Android java.lang.ClassNotFoundException only on Android 4.3 (api 17)

BrunoRoldoBrunoRoldo USMember ✭✭

I have a project that works fine on Android 5.0 or above.

But i tried to run it on Android 4.3, and it crashes before starting the first activity.

Full error:

05-18 23:44:57.309 E/AndroidRuntime(27114): Caused by: java.lang.ClassNotFoundException: Didn't find class "mapsproject.ApplicationStartup" on path: /data/app/MapsProject.MapsProject-1.apk

The class that he didn't find is an Application. I use Android Support Library on my project, there's an SupportApplication or anything like this?

Below is my Manifest:

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="MapsProject.MapsProject" android:versionCode="2" android:versionName="1.0.1" android:installLocation="auto">
  <uses-sdk android:minSdkVersion="17" />
  <uses-feature android:glEsVersion="0x00020000" android:required="true" />
  <uses-permission android:name="android.permission.INTERNET" />
  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
  <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
  <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
  <uses-permission android:name="com.xamarin.docs.android.mapsproject.permission.MAPS_RECEIVE" />
  <permission android:name="com.xamarin.docs.android.mapsproject.permission.MAPS_RECEIVE" android:protectionLevel="signature" />
  <!--Location permissions-->
  <uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
  <!--Location permissions end-->
  <application android:label="MobileMapsProject" android:name="mapsproject.ApplicationStartup" android:allowBackup="true" android:debuggable="true">
    <meta-data android:name="com.google.android.geo.API_KEY" android:value="AIzaSyATpV7pH8ti6rJrnN01H4dbVeaMX2vJdvE" />
    <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
    <!--Facebook SDK-->
    <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"></meta-data>
    <activity android:name="com.facebook.FacebookActivity" android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation" android:theme="@android:style/Theme.Translucent.NoTitleBar" android:label="@string/ApplicationName" android:screenOrientation="portrait" />
    <activity android:icon="@drawable/icon" android:label="MapsProject" android:theme="@style/MobileMapsTheme" android:name="md53f4bea8a426a59bffa9695091cc3f865.MainActivity">
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
    </activity>
    <activity android:theme="@style/MobileMapsTheme" android:name="md53f4bea8a426a59bffa9695091cc3f865.MainMapActivity" />
    <activity android:configChanges="keyboardHidden|orientation|screenSize" android:name="com.facebook.ads.InterstitialAdActivity" />
    <service android:name="md59f70a99687498e7ba187118950981d26.KeepAliveService" />
    <provider android:name="mono.MonoRuntimeProvider" android:exported="false" android:initOrder="2147483647" android:authorities="MapsProject.MapsProject.mono.MonoRuntimeProvider.__mono_init__" />
    <receiver android:name="mono.android.Seppuku">
      <intent-filter>
        <action android:name="mono.android.intent.action.SEPPUKU" />
        <category android:name="mono.android.intent.category.SEPPUKU.MapsProject.MapsProject" />
      </intent-filter>
    </receiver>
    <activity android:name="com.facebook.FacebookActivity" android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation" android:theme="@style/com_facebook_activity_theme" />
    <activity android:name="com.facebook.CustomTabActivity" android:exported="true"></activity>
    <activity android:name="com.facebook.CustomTabMainActivity" />
    <activity android:name="com.facebook.FacebookActivity" android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation" android:theme="@style/com_facebook_activity_theme" />
    <activity android:name="com.facebook.CustomTabActivity" android:exported="true"></activity>
    <activity android:name="com.facebook.CustomTabMainActivity" />
    <!--Include the AdActivity and InAppPurchaseActivity configChanges and themes. -->
    <activity android:name="com.google.android.gms.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" android:theme="@android:style/Theme.Translucent" />
    <activity android:name="com.google.android.gms.ads.purchase.InAppPurchaseActivity" android:theme="@style/Theme.IAPTheme" />
    <activity android:name="com.google.android.gms.common.api.GoogleApiActivity" android:theme="@android:style/Theme.Translucent.NoTitleBar" android:exported="false" />
    <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
  </application>
</manifest>

And below is my class that is throwing the exception:

[Application(Name ="mapsproject.ApplicationStartup")]
    public class ApplicationStartup : Application
    {
        public static ApplicationStartup Current { get; private set; }
        public SqliteManager Manager { get; set; }
        SQLiteConnection conn;
        public ApplicationStartup(IntPtr handle, global::Android.Runtime.JniHandleOwnership transfer)
            : base(handle, transfer) {
            Current = this;
        }
        public override void OnCreate()
        {
            base.OnCreate();

            var sqliteFilename = "MapsDB.db3";
            string libraryPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            var path = Path.Combine(libraryPath, sqliteFilename);
            conn = new SQLiteConnection(path);

            Manager = new SqliteManager(conn);
        }
    }

I've tried some tips on another threads, but it didn't solve the problem.

Thanks in advance!

Posts

  • JonDouglasJonDouglas USXamarin Team, University, Developer Group Leader Xamurai

    You are most likely running into a limitation of the main Application class not making the main dex list. I talk about this on my blog here: http://www.jon-douglas.com/2016/09/23/xamarin-android-multidex-keep/

    I believe there's a couple of bugs such as https://bugzilla.xamarin.com/show_bug.cgi?id=55268 and https://bugzilla.xamarin.com/show_bug.cgi?id=55050 which may help ensure it is ALWAYS included on the main dex list.

  • BrunoRoldoBrunoRoldo USMember ✭✭
    edited May 2017

    Thank you!
    Probably the problem is related to this.
    But, i have builded my project many times, and the multidex.keep file on obj/Debug is always blank, i was looking forward it to use as example.
    I've created my multidex.keep file on project, but what am i supposed to write in it? All the project classes, including outside packages?

  • JonDouglasJonDouglas USXamarin Team, University, Developer Group Leader Xamurai

    Perhaps you're running into an issue described in my first blog:

    http://www.jon-douglas.com/2016/09/05/xamarin-android-multidex/

    Please ensure your tooling is up to date and ensure the multidex.keep is being generated correctly.

  • BrunoRoldoBrunoRoldo USMember ✭✭

    JonDouglas, thank you very much for the help.

    Now my multidex.keep is generating correctly, but i still don't get it; what i have to do to my Application class to be generated on classes.dex, instead of classes2.dex?

    This class is on the multidex.keep, but it stills gets generated on classes2.dex.

  • BrunoRoldoBrunoRoldo USMember ✭✭
    edited May 2017

    I created my own multidex.keep on the solution, and it solved the problem, i didn't know why, but it generated the Application on the classes.dex

    Thank you very much! I'll be checking your blog from now on ;)

  • Having the same problem, how did you resolve?
    What did you put in the multidex.keep

Sign In or Register to comment.