android: Automatic main dex list is not supported when compiling for Android O and later (--min-api 26)

Hi,

I have added:

<AndroidDexTool>d8</AndroidDexTool> to my project file PropertyGroup and now I am getting this error:

Automatic main dex list is not supported when compiling for Android O and later (–min-api 26)

but my Minimum Version is 8.1 (API 27)

my Target Version is 9.0 (API 28)

and this is my AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="100" android:versionName="1.0" package="com.jafaria.app" android:installLocation="auto">
	<uses-sdk android:minSdkVersion="27" android:targetSdkVersion="28" />
	<application android:label="الأوقاف الجعفرية" android:icon="@drawable/icon" android:supportsRtl="true" android:largeHeap="true">
		<meta-data android:name="com.google.firebase.messaging.default_notification_icon" android:resource="@drawable/ic_notification" />
    <meta-data android:name="com.google.firebase.messaging.default_notification_channel_id" android:value="@string/default_notification_channel_id" />
    <receiver android:name="com.google.firebase.iid.FirebaseInstanceIdInternalReceiver" android:exported="false" />
    <receiver android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver" android:exported="true" android:permission="com.google.android.c2dm.permission.SEND">
			<intent-filter>
				<action android:name="com.google.android.c2dm.intent.RECEIVE" />
				<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
				<category android:name="com.jafaria.app" />
			</intent-filter>
		</receiver>
	</application>
	<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
	<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_LOCATION_EXTRA_COMMANDS" />
	<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
	<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
	<uses-permission android:name="android.permission.INTERNET" />
	<uses-permission android:name="android.permission.MEDIA_CONTENT_CONTROL" />
	<uses-permission android:name="android.permission.WAKE_LOCK" />
	<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
	<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
</manifest>

Kindly help…

Thanks, Jassim

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 21 (9 by maintainers)

Most upvoted comments

My problem is solved now. I just deleted all unnecessary spaces in the csproj file and deleted bin and ob then restarted Visual Studio and it’s now fine for both d8 and r8

Thank you so much @jonathanpeppers

So the error you are getting with r8:

error : java/lang/Object;I)V: defining a default interface method requires --min-sdk-version >= 24 (currently 13) for interface methods: com.google.android.exoplayer2.Player$EventListener.onTimelineChanged : (Lcom/google/android/exoplayer2/Timeline;Ljava/lang/Object;I)V

This means you cannot use ExoPlayer unless your minSdkVersion is 24 or greater.

@jrahma some other advice here:

  • If you are using a Code Shrinker, either ProGuard or r8, then don’t use multi-dex.
  • Code Shrinker is for Release builds only – they slow down your build, but produce a smaller APK.
  • You may need to add some ProGuard rules yourself to use ProGuard or r8, I don’t see any in this build log yet? Jon Douglas has a good post explaining ProGuard rules here (it was written before we had r8 support, but still valid): https://www.jon-douglas.com/2016/11/22/xamarin-android-proguard/
  • Debug builds should use multi-dex if your app doesn’t build without it. You would get an error that says “java exited with code N”, the build log will say “too many fields” or “too many methods”.

I am going to write a blog post on this subject, but my talk at Xamarin Dev Summit might also be helpful: https://youtu.be/YJ8TiRCsLl4?t=5939