Sina
Sina

Reputation: 269

android OneSignal import Error

hi i'm trying to use OneSignal in android and i'm following this tutorial to install the SDK in Android Studio. here

i was able to compile the dependencies and sync the gradle file. but when i want to import com.onesignal.OneSignal; it says: Cannot resolve symbol!

here is my dependencies in app.gradle file

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.0.1'
    compile 'com.android.support:design:23.0.1'
    compile 'com.onesignal:OneSignal:1.10.+@aar'
    compile 'com.google.android.gms:play-services-gcm:+'
    compile 'com.google.android.gms:play-services-analytics:+'
    compile project(':gson-2.2.2')
    compile project(':java_websocket')
    compile project(':signalr-client-sdk')
    compile project(':signalr-client-sdk-android')
}

thing i done:

1. File > Synchronize
2. File > Invalidate Cashes and Restart

UPDATE:

i did the steps in a new project and that was ok! why i can't do it in this specific project?

EDIT:

whole build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    useLibrary 'org.apache.http.legacy'

    defaultConfig {
        applicationId "ir.irsapardaz.sina.gamev01"
        manifestPlaceholders = [manifestApplicationId:"${applicationId}"]
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'),    'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.0.1'
    compile 'com.android.support:design:23.0.1'
    compile 'com.onesignal:OneSignal:1.10.+@aar'
    compile 'com.google.android.gms:play-services-gcm:+'
    compile 'com.google.android.gms:play-services-analytics:+'
    compile project(':gson-2.2.2')
    compile project(':java_websocket')
    compile project(':signalr-client-sdk')
    compile project(':signalr-client-sdk-android')
}

Upvotes: 8

Views: 10014

Answers (5)

Dnyaneshwar Panchal
Dnyaneshwar Panchal

Reputation: 444

In your build.gradle add this dependencies and sync gradle file I hope it will works.

 compile 'com.onesignal:OneSignal:3.+@aar'
 compile 'com.google.android.gms:play-services-gcm:10.2.1'
 compile 'com.firebase:firebase-client-android:2.5.2+'

You can also see the proper OneSignal's documentation if that doesn't work. https://documentation.onesignal.com/docs/android-sdk-setup

Upvotes: 0

jkasten
jkasten

Reputation: 3948

Use the following in your gradle file to get the latest OneSignal SDK 3.X version.

compile 'com.onesignal:OneSignal:[3.8.3, 3.99.99]'

The error you're are seeing is normally due to Android Studio either not pulling in the SDK from Maven Central or you haven't synced your .gradle since you added OneSignal to it.

In your case going to Tool > Android > Sync Project should fix the following error

com.onesignal.OneSignal; Cannot resolve symbol!

See OneSignal's documentation for a few more things to try if that doesn't work. https://documentation.onesignal.com/docs/troubleshooting-android

Upvotes: 10

Nikhil
Nikhil

Reputation: 41

Click here for image reference

Click here for image reference

In your Build gradel file

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    useLibrary 'org.apache.http.legacy'

    defaultConfig {

        applicationId "ir.irsapardaz.sina.gamev01"
        manifestPlaceholders = [manifestApplicationId:"${applicationId}"]
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'),    'proguard-rules.pro'
        }
    }

Under

default Config{

}

add this :

manifestPlaceholders = [onesignal_app_id: " Your app ID as provided by OneSignal ",

onesignal_google_project_number: " Your Sender Id as provided by Google firebase "

Upvotes: 1

jakeatwork
jakeatwork

Reputation: 497

if anyone comes across this for ReactNative v0.37, i had a similar issue, but my code was newer in general. the following solved it:

for android be sure to use:

import com.geektime.reactnativeonesignal.ReactNativeOneSignalPackage; and NOT import com.geektime.rnonesignal.ReactNativeOneSignalPackage;

some old documentation had the rnonesignal and that's since been updated.

YMMV if you are using something lower than v0.37 of RN. good luck.

Upvotes: 1

Ramesh sambu
Ramesh sambu

Reputation: 3539

compile 'com.onesignal:OneSignal:2.3.0' Try this in gradle file.Version will be updated.

Upvotes: 0

Related Questions