Reputation: 8931
My app can be started in two ways:
The first method works just fine. The main activity opens up, and the user can use the app. The second method however produces the following error/crash:
Unable to instantiate activity ComponentInfo{de.mystuff.myapp/de.mystuff.myapp.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "de.mystuff.myapp.MainActivity" on path: DexPathList[[zip file "/data/app/de.mystuff.myapp-1/base.apk"],nativeLibraryDirectories=[/data/app/de.mystuff.myapp-1/lib/arm, /data/app/de.mystuff.myapp-1/base.apk!/lib/armeabi-v7a, /vendor/lib, /system/lib]]
In my manifest I have declared the main activity as follows:
<activity android:name=".MainActivity" android:theme="@style/AppTheme">
<intent-filter>
<action android:name="android.intent.action.CALL" />
<category android:name="android.intent.category.DEFAULT" />
<action android:name="android.intent.action.CALL_PRIVILEGED" />
<data android:scheme="tel" />
</intent-filter>
</activity>
And my activity's code looks like this:
[Activity (Label = "MyApp", MainLauncher = true, Icon = "@mipmap/ic_launcher")]
public class MainActivity : Activity, SwipeRefreshLayout.IOnRefreshListener
{
AppSettings mAppSettings;
ContactListViewAdapter mListViewAdapter;
SwipeRefreshLayout mSwiper;
protected override void OnCreate (Bundle savedInstanceState)
{
base.OnCreate (savedInstanceState);
SetContentView (Resource.Layout.Main);
// Do some other init stuff
}
}
Upvotes: 0
Views: 1839
Reputation: 4547
For Xamarin.Android, I was able to solve this problem by removing activity declaration and setting my package as ProjectNamespace.ProjectNamespace
in the AndroidManifest.xml.
I don't know why it worked but it did.
Here is how my Manifest
file looks:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="CSharpApp.CSharpApp" android:installLocation="auto">
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:theme="@style/AppTheme.NoActionBar" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true">
<meta-data android:name="com.google.android.geo.API_KEY" android:value="@string/maps_api_key" />
</application>
<uses-sdk android:minSdkVersion="15" android:targetSdkVersion="25" />
</manifest>
Upvotes: 0
Reputation: 14750
You should avoid to mix up declarative style and manually writing the AndroidManifest.xml
.
[Activity (Label = "MyApp", MainLauncher = true, Icon = "@mipmap/ic_launcher")]
is generating a piece of code in the actual used (generated) AndroidManifest.xml
that looks like:
<activity android:icon="@drawable/icon" android:label="AndroidApp1" android:name="md5c178831cd46fc53bebc42cf953f78ced.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
and your code will be somewhere else. You can find the generated AndroidManifest.xml
in the output folder .\obj\Debug\android
.
Solution:
You can add your stuff via attributes like:
[Activity (Label = "MyApp", MainLauncher = true, Icon = "@mipmap/ic_launcher")]
[IntentFilter(
new [] { Intent.ActionCall, "android.intent.action.CALL_PRIVILEGED" },
Categories = new [] {Intent.CategoryDefault},
DataScheme = "tel")]
public class MainActivity : Activity, SwipeRefreshLayout.IOnRefreshListener
{
// ...
}
And remove the manual edits from your manifest file. The output will look like:
<activity android:icon="@drawable/icon" android:label="AndroidApp1" android:name="md5c178831cd46fc53bebc42cf953f78ced.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.CALL" />
<action android:name="android.intent.action.CALL_PRIVILEGED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="tel" />
</intent-filter>
</activity>
Upvotes: 4