2

I have this app and I want to send push notifications from my admin panel. I think I did everything OK, but OneSignal detects my app installed only when I install it in my emulator, but when I install the apk on my phone, it doesn't detect that. I have an android 10 phone. Here are my files:

build.cradle (app):

buildscript {
    repositories {
        maven { url 'https://plugins.gradle.org/m2/'}
    }
    dependencies {
        classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:[0.12.8, 0.99.99]'
    }
}
apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'

repositories {
    maven { url 'https://maven.google.com' }
}

apply plugin: 'com.android.application'

android {
    compileSdkVersion 29
    defaultConfig {
        applicationId 'ga.nabukoapps.materialwallpaper'

        manifestPlaceholders = [onesignal_app_id: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
                                // Project number pulled from dashboard, local value is ignored.
                                onesignal_google_project_number: "REMOTE"]

        minSdkVersion 16
        targetSdkVersion 29
        versionCode 1
        versionName '1.0'
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    productFlavors {
    }
    useLibrary 'org.apache.http.legacy'
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'com.google.android.material:material:1.2.0'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.recyclerview:recyclerview:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.0'
    implementation 'com.google.android.gms:play-services-ads:19.3.0'
    implementation 'com.google.android.ads.consent:consent-library:1.0.8'
    implementation 'com.balysv:material-ripple:1.0.2'
    //noinspection GradleDependency
    implementation 'com.onesignal:OneSignal:[3.15.0, 3.99.99]'
    //implementation 'com.onesignal:OneSignal:3.11.2'
    implementation 'com.theartofdev.edmodo:android-image-cropper:2.7.0'
    implementation 'com.bogdwellers:pinchtozoom:0.1'
    implementation 'com.github.clans:fab:1.6.4'
    implementation 'com.karumi:dexter:4.2.0'
    implementation 'com.github.chrisbanes:PhotoView:2.1.4'
    implementation 'com.beloo.widget:ChipsLayoutManager:0.3.7@aar'
    implementation 'com.android.volley:volley:1.1.1'
    implementation 'com.google.code.gson:gson:2.8.5'
    implementation 'com.squareup.okhttp3:okhttp:3.11.0'
    implementation 'commons-io:commons-io:2.4'
    implementation 'com.android.support:multidex:1.0.3'
    implementation 'com.google.firebase:firebase-analytics:17.5.0'

}

apply plugin: 'com.google.gms.google-services'

build.cradle (project):

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.0.1'
        classpath 'com.google.gms:google-services:4.3.3'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven { url "https://jitpack.io" }
    }
}
Nabukodonosor
  • 699
  • 1
  • 8
  • 20
  • I assume that you have followed instructions from : https://documentation.onesignal.com/docs/android-sdk-setup Have you tried installing the app on a few different real devices? Maybe your device has some issues with Google Play Services? – Mohru Sep 02 '20 at 19:04
  • You may also try to include in your project a google-services.json for the Firebase APi key you use with OneSignal. One more thing, I'm not sure that you need `apply plugin: 'com.google.gms.google-services'` - maybe it breaks something. – Mohru Sep 02 '20 at 19:10
  • I have included it in my project. – Nabukodonosor Sep 03 '20 at 15:19

3 Answers3

2

https://stackoverflow.com/a/39283454/8393749

I've never worked with OneSignal, but one of the reasons this problem occurs is that the app package name the push is looking for is different. Maybe you can focus on that.

In the link above, there is a part of a build.gradle (app level) file you can take as a reference. It mentions adding manifestApplicationId key and your app package name as a value in the manifestPlaceholders area like this:

release {
      defaultConfig {
         manifestPlaceholders = [manifestApplicationId          : "${applicationId}",
                                 onesignal_app_id               : "22222222-2222-2222-2222-222222222222",
                                 onesignal_google_project_number: "222222222"]
      }
   }

p.s. If you are not using any flavors, maybe you should remove this part from your code:

productFlavors {
}
Dharman
  • 30,962
  • 25
  • 85
  • 135
Şevval
  • 86
  • 1
  • 7
  • This didn't help. I think the problem is with google play services. I get this error in the OneSignal dash: "Outdated Google Play Services App". And I only see it when I install the app in the emulator. When I install the app via .apk I don't get anything at all. – Nabukodonosor Sep 01 '20 at 21:08
1

I know it won't help you using OneSignal , but the best approach to work with notification in android is using Firebase Cloud Messaging , its well documented with a higher google-services compatibility since it belongs to Google .

Setting up Firebase Cloud Messaging will take you a couple of hours.

ismail alaoui
  • 5,748
  • 2
  • 21
  • 38
1

To answer myself. Everything was done good on my side, but the problem is I guess in my phone. I've read somewhere that it will not be a problem when I install the app from the Play Store. Also, my emulator image was not good. I've installed a new one, Pixel 3a I think, and it works fine in it. Thanks everyone who tried to help.

Nabukodonosor
  • 699
  • 1
  • 8
  • 20