Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ionic 3 manifest error after upgrade to target-sdk 31 #807

Open
orelbutbul opened this issue Aug 15, 2022 · 40 comments
Open

Ionic 3 manifest error after upgrade to target-sdk 31 #807

orelbutbul opened this issue Aug 15, 2022 · 40 comments

Comments

@orelbutbul
Copy link

After upgrade target-sdk to 31 I get an error that comes from AndroidManifest.xml file

> Task :app:processDebugMainManifest FAILED
....\platforms\android\app\src\main\AndroidManifest.xml 
Error:
Apps targeting Android 12 and higher are required to specify an explicit value for `android:exported` when the corresponding component has an intent filter defined. See https://developer.android.com/guide/topics/manifest/activity-element#exported for details.

The only thing that doesn't contain the tag android:exported on AndroidManifest.xml file is

<receiver android:name="com.onesignal.ADMMessageHandler$Receiver" android:permission="com.amazon.device.messaging.permission.SEND">
     <intent-filter>
         <action android:name="com.amazon.device.messaging.intent.REGISTRATION" />
         <action android:name="com.amazon.device.messaging.intent.RECEIVE" />
         <category android:name="com.app.testapp" />
     </intent-filter>
 </receiver>

But after I try to add the tag to the receiver and build again It replicates the receiver without the tag,
i using
"onesignal-cordova-plugin": "^2.11.2",
"ionic-native/onesignal": "^4.18.0",

@nan-li
Copy link
Contributor

nan-li commented Aug 15, 2022

Thank you for reporting @orelbutbul,

We will update our Amazon SDK Setup documentation under Step 2.3 with android:exported="true". I will close this issue when it goes live.

@orelbutbul
Copy link
Author

@nan-li Maybe you didn't understand me, but I have an error, it doesn't let me add android:exported="true" to the reciver ,
when I try to add, it duplicates the receiver code over again without the android:exported="true",

Does anyone know how to solve the problem?

@nan-li
Copy link
Contributor

nan-li commented Aug 15, 2022

Ahh I see, sorry I did misunderstand.

You are on the previous major version 2.x.x of onesignal-cordova-plugin. This <receiver> is coming directly from our SDK here but is no longer included in the current major versions 3.x.x.

Are you able to upgrade to 3.x.x?

@orelbutbul
Copy link
Author

orelbutbul commented Aug 15, 2022

No I have no option, It's ionic 3, and because this is coming directly from your SDK I cannot edit the AndroidManifest.xml file manually, Is there any way I can fix this error?

@nan-li
Copy link
Contributor

nan-li commented Aug 16, 2022

We would have to make a release here on version 2.x.x. We would also have to release an older version of OneSignal-Android-SDK as well and check all of its dependencies. This is because our Cordova plugin relies on our Android native SDK.

There may be a workaround for now where you can overwrite entries for library Manifests. I am able to reproduce your issue and will investigate a solution.

@lincond
Copy link

lincond commented Aug 16, 2022

I'm having the same issue. Any expectations to release a version with the fix for 2.x.x? I tried to modify the plugin.xml to see if I could do some workaround but I'm still getting an error because there is more declarations with intent-filter without the android:exported on the merged-manifest.

Thank you!

@danialvesb
Copy link

i'm having the same problem, we can't update onesignal at the moment to the latest version. To fix it I would need to insert android:exported in the plugin and in the android SDK.

@heliocesar01
Copy link

I have the same problem, I use cordova to compile the apps, I've tried all the steps mentioned and it doesn't work. @orelbutbul do you know if there is a fix for this problem?

@orelbutbul
Copy link
Author

orelbutbul commented Aug 17, 2022

In my case with Ionic 3 I installed the version

"onesignal-cordova-plugin": "^3.1.0",
"@ionic-native/onesignal": "^5.36.0",

in app.module.ts i change to
import { OneSignal } from '@ionic-native/onesignal/ngx';

And instead of using this code to get details

this.oneSignal.startInit(oneSignalAppId, sender_id);
this.oneSignal.inFocusDisplaying(this.oneSignal.OSInFocusDisplayOption.Notification);
this.oneSignal.handleNotificationReceived().subscribe(data => this.onPushReceived(data.payload));
this.oneSignal.handleNotificationOpened().subscribe(data => this.onPushOpened(data.notification.payload));
this.oneSignal.enableSound(false);
this.oneSignal.endInit();
this.oneSignal.getIds().then((id) => {
      // use the details
}

I use this code

window['plugins']['OneSignal'].setAppId(app.oneSignalAppId)
     
window['plugins']['OneSignal'].addSubscriptionObserver(async (event) => {
      if (event.to.isSubscribed) {
          window['plugins']['OneSignal'].getDeviceState((state) => {
              if(state) {
                       // use the details
              }
          })
      }
});
window['plugins']['OneSignal'].setNotificationOpenedHandler((jsonData: any) => {
    this.onPushOpened(jsonData.notification)
});

And it works for me :) I hope I helped some of you, it's just important to note that I'm doing a build from Android Studio

@marcioramosilva1
Copy link

i'm having the same problem, we can't update onesignal at the moment to the latest version. To fix it I would need to insert android:exported in the plugin and in the android SDK. My app only register at Onesignal with 2.11.4 version.

The Play Store is mandatory Android vresion 31.

Help me Please.

@danialvesb
Copy link

danialvesb commented Aug 18, 2022

In more detail, the problem is quite simple. But I can't insert android:exported in OneSignalAndroidSDK. Only in plugin.xml as shown in the image.
image

In OneSignalAndroidSDK comes with manifest without android:exported.
image

Unfortunately, we are currently unable to update OneSignal to version >3.X.X, due to compatibility issues with AndroidX.
:(

@marcioramosilva1
Copy link

In more detail, the problem is quite simple. But I can't insert android:exported in OneSignalAndroidSDK. Only in plugin.xml as shown in the image. image

In OneSignalAndroidSDK comes with manifest without android:exported. image

Unfortunately, we are currently unable to update OneSignal to version >3.X.X, due to compatibility issues with AndroidX. :(

Do you know why all 3.x.x don't run?

@danialvesb
Copy link

danialvesb commented Aug 18, 2022

@marcioramosilva1
Version 3.X.X is only compatible with projects with androidx enabled.
We haven't migrated our app to androidx yet, so OneSignal 3.X.X is not supported. The reason not to migrate yet is because many plugins we use don't support androidx.
We tried to use cordova-plugin-androidx-adapter plugin, but onesignal in version 3.X.X causes a runtime error causing the app to not open on Android 12 OS.

@marcioramosilva1
Copy link

I use ionic, but i created a new app empty, and add just onesignal plugin. The app don't register at onesignal.

@lincond
Copy link

lincond commented Aug 18, 2022

In more detail, the problem is quite simple. But I can't insert android:exported in OneSignalAndroidSDK. Only in plugin.xml as shown in the image. image

In OneSignalAndroidSDK comes with manifest without android:exported. image

Unfortunately, we are currently unable to update OneSignal to version >3.X.X, due to compatibility issues with AndroidX. :(

I tried the same workaround, but it fails because the merged-manifest doesn't have all the android:exported needed. @nan-li Any chance to add the missing android:exported on plugin.xml and on the OneSignalAndroidSDK?

@nan-li
Copy link
Contributor

nan-li commented Aug 25, 2022

Hi all, we are investigating the complexity of updating the previous major version to support targeting Android 31.

Updating our own android:exported property is simple. However, we have to update the OneSignal Android SDK's own dependencies as well and this may pose some challenges. We will follow up on this.

@jsBiztech
Copy link

Is there any workaround available till then, It's been a while.

@satianoCantana
Copy link

I am in the same situation, I tried the solution proposed by @orelbutbul but with no success, is there any thing else to try ?

@webxvivek
Copy link

Hi,

Did any one have got any work around??

Guys, ANDROID 31 target has mostly broken all cordova projects.

Thanks

@danialvesb
Copy link

danialvesb commented Sep 22, 2022

I found an alternative.
In order not to migrate to androidx, we use the cordova-plugin-androidx-adapter plugin.
the latest version of onesignal normally. That way it works.

Add this to config.xml:
<preference name="AndroidXEnabled" value="true" /> <edit-config file="app/src/main/AndroidManifest.xml" target="/manifest/application/activity" mode="merge"> <activity android:exported="true" /> </edit-config>

This should work, but there is an error on android 12 that the app closes. To solve it, I forked the one-signal plugin and made a change in the plugin.xml of the onesignal plugin adding this:
<framework src="androidx.work:work-runtime-ktx:2.7.0" />

The fork was added like this in the config.xml:
<plugin name="onesignal-cordova-pluginfix" spec="git+https://github.com/danialvesb/onesignal-cordova-pluginfix.git" />

This is just a stopgap measure, while the issue is not resolved in version 2.X.X, the issue still persists.

@timonjagi
Copy link

Any update on this issue? @nan-li

@nan-li
Copy link
Contributor

nan-li commented Oct 13, 2022

Hi everyone, I am very sorry for the delayed response.

After investigating full support of Android 31 on the previous release, we will not be making updates to OneSignal-Cordova-SDK 2.x.x to support this.

Instead, we will aim to help apps upgrade to OneSignal-Cordova-SDK 3.x.x, starting with looking at the compatibility issue with cordova-plugin-androidx-adapter.

Please post any issues you run into upgrading to version 3.x.x and we will try to help you resolve them.

@timonjagi
Copy link

I'm on Ionic 6 and I'm still getting the same error even after updating my android target and compile SDK to version 33 as per the OneSignal documentation on upgrading from 2.X.X to 3.X.X

Apps targeting Android 12 and higher are required to specify an explicit value for android:exported when the corresponding component has an intent filter defined.

@nan-li
Copy link
Contributor

nan-li commented Oct 25, 2022

Hi @timonjagi,

To confirm, you are using OneSignal-Cordova-SDK version 3.x.x and you are still getting "Apps targeting Android 12 and higher are required to specify an explicit value for android:exported when the corresponding component has an intent filter defined"? Is that error gone if you remove OneSignal?

@timonjagi
Copy link

timonjagi commented Oct 26, 2022

@nan-li My bad. I can confirm the error still persists even after removing OneSignal. It must be another other plugin causing the error.

[EDIT] Found the source of the error. It was being caused by social-sharing plugin, not OneSignal. The fix is here

@sonicwong
Copy link

sonicwong commented Nov 18, 2022

I found that widget.name in config include any non english letter will cause build error.
I change the app name to pure english without space, use plugin cordova-plugin-app-name to rename app name.
Everything got well when using ionic 3 with onesignal v3.2.0

For iOS, need OneSignal.promptForPushNotificationsWithUserResponse(); after OneSignal.setAppId();

@adeel399
Copy link

hy i am facing issue if i use onesignal latest version 3.x.x then that targetsdk 31 issue resolve and i am able to build but onesignal gives "plugin not installed error on inspect" but if i use 2.x.x version of onesignal then on targetsdk 31 i face that merge manifest issue i also try adding export true in plugin.xml file of version 2.x.x

plz help me any workaround

@sonicwong
Copy link

@adeel399 Please remove "@ionic-native/onesignal@4" if exist.
Onesignal v3.2.0 can import directly by: import OneSignal from 'onesignal-cordova-plugin';
OneSignal.setAppId("YOUR_ONESIGNAL_APP_ID");

@adeel399
Copy link

You mean i update onesignal to latest version and add these line directly to app.component file and then i will not get plugin not installed error??

@sonicwong
Copy link

@adeel399 you got error when install plugin or when build apk? copy whole error message and post here.

@adeel399
Copy link

No i receive error after build no plugin installed

@sonicwong
Copy link

@adeel399 try remove cordova-android and reinstall.
Make sure project is selected to use JDK v11+ in Android Studio

@jsBiztech
Copy link

Hello @adeel399 , @sonicwong , @nan-li
I am using Ionic 6.0 with current version of
onesignal-cordova-plugin as 2.11.4
@ionic-native/onesignal": "^5.30.0
@ionic/angular": "^6.1.0

Currently I have code regarding to import { OneSignal } from '@ionic-native/onesignal/ngx';
this particular line.
and code is

if (!this.appPlatform.is('desktop') && !this.appPlatform.is('mobileweb') && (((await Network.getStatus()).connectionType !== 'none') || (await Network.getStatus()).connected)) {
        if (this.appPlatform.is("ios")) {
          this.oneSignal.startInit((this.commonService.serverName == "live" || this.commonService.serverName == "train") ? 'key' : "key");
        } else {
          this.oneSignal.startInit((this.commonService.serverName == "live" || this.commonService.serverName == "train") ? 'key' : "key", (this.commonService.serverName == "live" || this.commonService.serverName == "train") ? 'googleprojectnumber' : 'googleprojectnumber');
        }

        this.oneSignal.inFocusDisplaying(this.oneSignal.OSInFocusDisplayOption.None);
        this.oneSignal.handleNotificationOpened().subscribe((data) => {
          if (data && data.notification && data.notification.payload && data.notification.payload.additionalData)
            this.getNotificationRun(data.notification.payload.additionalData)
        });
        this.oneSignal.endInit();

        this.commonService.isOffline.subscribe(response => {
          this.checkPendingLogoutRequest()
        })
        this.localStorageService.getStoragedata("appConfigData").then((appconfigResult: any) => {
          this.checkPendingLogoutRequest()
          this.oneSignal.getIds().then((data) => {
            this.commonService.oneSignalToken = data.userId;
            if (appconfigResult && appconfigResult.isLoggedIn) {
              this.commonService.registerOneSignalDevice()
            }
          })
          this.oneSignal.addSubscriptionObserver().subscribe((state) => {
            if (!state.from.subscribed && state.to.subscribed) {
              this.commonService.oneSignalToken = state.to.userId;
              if (appconfigResult && appconfigResult.isLoggedIn) {
                this.commonService.registerOneSignalDevice()
              }
            }
          })

With this I got error of mainfest merger when build android from android studio.

Is there any Solution to keep version as same , and I fork plugin and make some adjustments with 2.11.4 version?

if not how can I convert my existing above code to migrate from onesignal-cordova-plugin as 2.11.4 to latest version?

@nan-li
Copy link
Contributor

nan-li commented Dec 5, 2022

Hi @jsBiztech,

This is the Cordova migration guide from 2.x.x to 3.x.x.

Here is the regular Ionic setup guide.

Also, you should import via import OneSignal from 'onesignal-cordova-plugin' and not from import { OneSignal } from '@ionic-native/onesignal/ngx'.

@mkwitko
Copy link

mkwitko commented Dec 6, 2022

Guys, i don't know if this is still a valid question but in order to make it work you have to edit the plugins.xml in onesignal folder plugins/onesignal-cordova-plugin/plugins.xml and edit the android:exported there; then exclude platforms/android and generate it again. The duplicate problem is because the plugins.xml is editing the androidmanifest, so if you change the value in androidmanifest directly the plugins.xml will generate the code again, giving the duplicate error

@diegok350
Copy link

Hello everyone, I have the same problem, if I use the onesignal version:
onesignal-cordova-plugin as 2.11.4

In AndroidManafest.xml gives a duplicate error

if i update the version to: onesignal-cordova-plugin as 3.x.x

It does not work or register devices on the onesignal platform, any solution?
This is my info:

Ionic:

Ionic CLI : 6.20.3 (C:\Users\diego\AppData\Roaming\npm\node_modules@ionic\cli)
Ionic Framework : @ionic/angular 6.0.1
@angular-devkit/build-angular : 13.0.4
@angular-devkit/schematics : 13.0.4
@angular/cli : 13.0.4
@ionic/angular-toolkit : 5.0.3

Cordova:

Cordova CLI : 11.1.0
Cordova Platforms : android 11.0.0
Cordova Plugins : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 4.2.1, (and 21 other plugins)

@Elierak26
Copy link

Hi,

@diegok350 The problem is that onesignal-cordova-plugin v3 cannot work with @ionic-native/onesignal@5.36.0 because it has not been maintained for 2 years.

So, If you want to use onesignal-cordova-plugin v3, you need to follow this step link:

  1. Import onesignal-cordova-plugin in src/app/app.module.ts like this :

import { OneSignalPlugin } from 'onesignal-cordova-plugin';

providers: [
    StatusBar,
    SplashScreen,
    HttpClientModule,
    { provide: RouteReuseStrategy, useClass: IonicRouteStrategy },
    OneSignalPlugin
  ],

  1. Create Initialisation function for Onesignal your page. Ex : home.page.ts

import { OneSignalPlugin } from 'onesignal-cordova-plugin';

export class HomePage implements OnInit {
  
  constructor(
    private platform: Platform,
    private splashScreen: SplashScreen,
    private statusBar: StatusBar,
    public oneSignal: OneSignalPlugin
  }{
    
  }

  ngOnInit(){
    this.platform.ready().then(() => {
      console.log(this.oneSignal);
      this.oneSignalInit();
    })
  }


  oneSignalInit(){
    this.oneSignal.setAppId(this.ONESIGNAL_APP_ID);

    this.oneSignal.setExternalUserId(this.user.id)

    this.oneSignal.setNotificationWillShowInForegroundHandler(event => {
      console.log('setNotificationWillShowInForegroundHandler', JSON.stringify(event));
    });

    this.oneSignal.setNotificationOpenedHandler(event => {
      console.log('setNotificationOpenedHandler', JSON.stringify(event));
    })

  } 
} 

That's work for me. Just append your fonction to the notification event handler link

My config :


Ionic:

   Ionic CLI                     : 6.20.9 (/usr/local/lib/node_modules/@ionic/cli)
   Ionic Framework               : @ionic/angular 4.11.13
   @angular-devkit/build-angular : 0.803.29
   @angular-devkit/schematics    : 8.1.3
   @angular/cli                  : 8.1.3
   @ionic/angular-toolkit        : 2.0.0

Cordova:

   Cordova CLI       : 11.1.0
   Cordova Platforms : android 11.0.0, ios 6.2.0
   Cordova Plugins   : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 5.0.0, (and 17 other plugins)


@Shadowstep33
Copy link

Just putting this here in case someone more industrious can implement: i also hit a different manifest merger issue wherein the value I set in Android/app/build.gradle for manifestPlaceholders appears to get overwritten. Further googling shows this might be because of mainfestPlaceholders = vs manifestPlaceholders +=. I tested this theory by setting the value I need in this package's build-extras-onesignal.gradle and the error went away. This is the error I was receiving:

Attribute data@scheme at AndroidManifest.xml requires a placeholder substitution but no value for <AUTH_URL_SCHEME> is provided

And thusly this causes issues with @ionic-enterprise/auth@4

@mhunesi
Copy link

mhunesi commented May 12, 2023

Hello everyone! It works for me.

SDK 31 Android 12 Ionic 3. OneSignal version 3.0.1 fully supports Android 12.

  1. Android X enabled.
ionic cordova plugin add cordova-plugin-androidx
ionic cordova plugin add cordova-plugin-androidx-adapter
  1. Add config.xml
<preference name="AndroidXEnabled" value="true" />
  1. Add config.xml platform android.
<edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application/activity" xmlns:android="http://schemas.android.com/apk/res/android">
     <activity android:exported="true" />
</edit-config>
  1. Remove and re-add OneSignal
cordova plugin rm onesignal-cordova-plugin
cordova plugin add onesignal-cordova-plugin
  1. Remove the Android platform and re-add it
cordova platform rm android
cordova platform add android

@dtarnawsky
Copy link

Hey @Shadowstep33, I've added your issue here: #928 . You may want to subscribe to that issue or add a "me too".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests