OneSignal / OneSignal-Xamarin-SDK

OneSignal is a free push notification service for mobile apps. This plugin makes it easy to integrate your Xamarin app with OneSignal. https://onesignal.com
Other
105 stars 50 forks source link

Enabling aapt2 cause "unexpected element <receiver>" build errors #146

Closed Logan2014 closed 5 years ago

Logan2014 commented 5 years ago

Description:

I receive two build errors when enable "Use incremental Android packaging system (aapt2)" build option: "unexpected element <receiver> found in <manifest>".

Environment

Xamarin.Android SDK 9.3.0.22 NuGet Package Manager 5.1.0 Com.OneSignal NuGet package 3.3.0

Steps to Reproduce Issue:

Enable "Use incremental Android packaging system (aapt2)" Android build option.

Self investigation: OneSignal SDK adds receiver tags to AndroidManifest.xml at build stage:

<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.market_universal.ds" />
    </intent-filter>
</receiver>

Aapt2 enables more strict checks for AndroidManifest.xml: receiver should be inside application tag.

rgomezp commented 5 years ago

Hello, What is the exact build error you are seeing? Thanks

ndastur commented 5 years ago

@rgomezp I think @Logan2014 described the problem well in the bug report. I.e. the receiver attribute should be enclosed in the application tag of the AndroidManifest not outside it. https://developer.android.com/guide/topics/manifest/receiver-element

The build error is aapt finding an "unexpected element". Also have the same issue

rgomezp commented 5 years ago

I see. Will have to investigate deeper. Thanks for your patience

rgomezp commented 5 years ago

Howdy, What Gradle version are you using? Also, if you don't use aapt do you still see the issue?

ndastur commented 5 years ago

@rgomep it's Xamarin. So no gradle. I have to say the fix appears quite simple. Put the attribute where it's supposed to be ?? As described in the android documents.

rgomezp commented 5 years ago

Take a look at this thread. It's Cordova but they were also running into issues with aapt. Maybe you can learn something from their response

rgomezp commented 5 years ago

Closing due to no response

ndastur commented 5 years ago

@rgomezp not sure why you have closed this. It's still a bug regardless of whether it occurs on Cordova as well.

rgomezp commented 5 years ago

Howdy @ndastur , Could you please try the suggestion from the Edit: Cordova thread? Thanks

ndastur commented 5 years ago

@rgomezp can you please confirm which thread you are talking about? Just in case, if you mean the suggestion to turn linking off, that's not a solution. All that does is stop the appt2 tool from running and results in a massive unlinked app

rgomezp commented 5 years ago

Howdy endastur, First, the receiver isn't required for the SDK to work. Second, if you want to use it, it has to go inside an application tag in your manifest. In other words, this has nothing to do with our SDK since the receiver isn't even required. Hopefully, you can glean something from the Cordova thread, which the other gentleman was able to successfully resolve. I recommend taking another look at his reply. Cheers

ndastur commented 5 years ago

Thanks @rgomezp would you mind getting the OneSignal Xamarin SDK documentation updated to reflect that. See your page https://documentation.onesignal.com/docs/xamarin-sdk-setup Section 3.2 could be removed by what you say?

rgomezp commented 5 years ago

Howdy endastur, We can't remove that as it is our receiver, which of course is needed. The receiver I referenced in the above comment is the Firebase receiver.

Logan2014 commented 5 years ago

Thanks @ndastur for moral support. As I can see this issue was resolved 5 days ago at 3.4.0 release: https://github.com/OneSignal/OneSignal-Xamarin-SDK/releases/tag/3.4.0 (Replaced GCM dependency with Firebase Messaging dependency)