Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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')
}
like image 319
Sina Avatar asked Nov 26 '15 06:11

Sina


3 Answers

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

like image 132
jkasten Avatar answered Oct 17 '22 11:10

jkasten


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.

like image 43
jakeatwork Avatar answered Oct 17 '22 10:10

jakeatwork


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 "
like image 35
Nikhil Avatar answered Oct 17 '22 10:10

Nikhil