Share via

Xamarin android app not deploying.

Isaac Rosenfeld 1 Reputation point
2022-04-25T18:21:53.203+00:00

App2I am unable to deploy or to archive it. But I'm not receiving any errors.
But when I removed the broadcast receiver (Receiver1.cs) it worked.
The code is located at:
Thank You

Developer technologies | .NET | Xamarin
Developer technologies | C#
Developer technologies | C#

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.

0 comments No comments

1 answer

Sort by: Most helpful
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 50,166 Reputation points Microsoft External Staff
    2022-04-26T02:49:04.79+00:00

    Hello,

    In my testing, After I removed the following code from AndroidManifest.xml:

       <receiver android:name=".BootReceiver" android:enabled="true" android:permission="android.permission.RECEIVE_BOOT_COMPLETED">  
       	<intent-filter>  
       		<action android:name="android.intent.action.BOOT_COMPLETED" />  
       		<category android:name="android.intent.category.DEFAULT" />  
       	</intent-filter>  
       </receiver>  
    

    and added the following code in Receiver1.cs, the application could successfully deploy to my Android Emulator.

       [BroadcastReceiver(Name = "com.my_app.app.BootBroadcast", Enabled = true, Exported = false)]  
       [IntentFilter(new[] { Intent.ActionBootCompleted })]  
       public class BootReceiver : BroadcastReceiver  
    

    The reason is that you need to set a value to the property export in using API 31 or above. and you can refer to this documentation Working with the Android Manifest to find this:

    Xamarin.Android helps to minimize this difficulty by allowing you to add custom attributes to your classes, which will then be used to automatically generate the manifest for you. Our goal is that 99% of our users should never need to manually modify AndroidManifest.xml.

    For this reason, we should try not to modify AndroidManifest.xml if we can.

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.