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

[Bug]: Unsolved Reference #2164

Closed
1 task done
fcidev opened this issue Aug 2, 2024 · 2 comments
Closed
1 task done

[Bug]: Unsolved Reference #2164

fcidev opened this issue Aug 2, 2024 · 2 comments

Comments

@fcidev
Copy link

fcidev commented Aug 2, 2024

What happened?

Project Specifications"

  1. I am using the latest one signal implementation 'com.onesignal:OneSignal:[5.0.0, 5.99.99]' dependency
  2. Gradle and AGP version 8.7 and 8.5.0
  3. Using JDK 17.0
    Previously i used the implementation("com.onesignal:OneSignal:[4.6.4, 5.0.0)") at that time everything was working fine, app was stable and i was receiving notification properly now after i updated the SDK to implementation 'com.onesignal:OneSignal:[5.0.0, 5.99.99]'

`

Below is my code

MainActivity

package com.myapp.notificationapp

import android.Manifest
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.os.PowerManager
import android.provider.Settings
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import com.onesignal.OneSignal

class MainActivity : AppCompatActivity() {

    private val ONESIGNAL_APP_ID = "My_app_id"
    private val PERMISSION_REQUEST_CODE = 1

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        // Enable verbose OneSignal logging to debug issues
        OneSignal.setLogLevel(OneSignal.LOG_LEVEL.VERBOSE, OneSignal.LOG_LEVEL.NONE)

        // OneSignal Initialization
        OneSignal.initWithContext(this)
        OneSignal.setAppId(ONESIGNAL_APP_ID)

        // Check and request permissions
        checkAndRequestPermissions()

        // Check battery optimization
        checkBatteryOptimization()

        // Start foreground service
        startForegroundService()
    }

    private fun checkAndRequestPermissions() {
        val permissionsNeeded = mutableListOf<String>()

        // Check INTERNET permission
        if (ContextCompat.checkSelfPermission(this, Manifest.permission.INTERNET) != PackageManager.PERMISSION_GRANTED) {
            permissionsNeeded.add(Manifest.permission.INTERNET)
        }

        // Check notification permission (for Android 13 and above)
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
            if (ContextCompat.checkSelfPermission(this, Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) {
                permissionsNeeded.add(Manifest.permission.POST_NOTIFICATIONS)
            }
        }

        // Check SYSTEM_ALERT_WINDOW permission
        if (!Settings.canDrawOverlays(this)) {
            permissionsNeeded.add(Manifest.permission.SYSTEM_ALERT_WINDOW)
        }

        if (permissionsNeeded.isNotEmpty()) {
            ActivityCompat.requestPermissions(this, permissionsNeeded.toTypedArray(), PERMISSION_REQUEST_CODE)
        }
    }

    private fun checkBatteryOptimization() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            val powerManager = getSystemService(Context.POWER_SERVICE) as PowerManager
            val packageName = packageName
            if (!powerManager.isIgnoringBatteryOptimizations(packageName)) {
                val intent = Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS)
                intent.data = Uri.parse("package:$packageName")
                startActivity(intent)
            }
        }
    }

    private fun startForegroundService() {
        val serviceIntent = Intent(this, ForegroundService::class.java)
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            ContextCompat.startForegroundService(this, serviceIntent)
        } else {
            startService(serviceIntent)
        }
    }

    override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults)
        if (requestCode == PERMISSION_REQUEST_CODE) {
            for (i in permissions.indices) {
                if (grantResults[i] != PackageManager.PERMISSION_GRANTED) {
                    // Handle permission not granted
                }
            }
        }
    }
}


MyNotificationOpenedHandler

package com.myapp.notificationapp

import android.content.Context
import android.content.Intent
import com.onesignal.OSNotificationOpenedResult
import com.onesignal.OneSignal

class MyNotificationOpenedHandler(val context: Context) : OneSignal.OSNotificationOpenedHandler {
    override fun notificationOpened(result: OSNotificationOpenedResult?) {
        // Handle the action when notification is opened
        val intent = Intent(context, MainActivity::class.java)
        intent.flags = Intent.FLAG_ACTIVITY_REORDER_TO_FRONT or Intent.FLAG_ACTIVITY_NEW_TASK
        context.startActivity(intent)
    }
}


My App level Build.gradle

plugins {
    alias(libs.plugins.android.application)
    alias(libs.plugins.jetbrains.kotlin.android)
}

android {
    namespace = "com.myapp.notificationapp"
    compileSdk = 34

    defaultConfig {
        applicationId = "com.myapp.notificationapp"
        minSdk = 26
        targetSdk = 34
        versionCode = 1
        versionName = "1.0"

        testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled = false
            proguardFiles(
                    getDefaultProguardFile("proguard-android-optimize.txt"),
                    "proguard-rules.pro"
            )
        }
    }

    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = "1.8"
    }
}

dependencies {
    implementation(libs.androidx.core.ktx)
    implementation(libs.androidx.appcompat)
    implementation(libs.material)
    implementation(libs.androidx.activity)
    implementation(libs.androidx.constraintlayout)
    implementation 'com.onesignal:OneSignal:[5.0.0, 5.99.99]'
    testImplementation(libs.junit)
    androidTestImplementation(libs.androidx.junit)
    androidTestImplementation(libs.androidx.espresso.core)
}

My settings.gradle

pluginManagement {
    repositories {
        google {
            content {
                includeGroupByRegex("com\\.android.*")
                includeGroupByRegex("com\\.google.*")
                includeGroupByRegex("androidx.*")
            }
        }
        mavenCentral()
        gradlePluginPortal()
    }
}
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
    }
}

rootProject.name = "Notification App Notification App"
include ':app'

My project level build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
alias(libs.plugins.android.application) apply false
    alias(libs.plugins.jetbrains.kotlin.android) apply false
}

This is my libs.version.toml

[versions]
agp = "8.5.0"
kotlin = "1.9.0"
coreKtx = "1.13.1"
junit = "4.13.2"
junitVersion = "1.2.1"
espressoCore = "3.6.1"
appcompat = "1.7.0"
material = "1.12.0"
activity = "1.9.1"
constraintlayout = "2.1.4"

[libraries]
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
junit = { group = "junit", name = "junit", version.ref = "junit" }
androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" }
androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" }
androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" }
material = { group = "com.google.android.material", name = "material", version.ref = "material" }
androidx-activity = { group = "androidx.activity", name = "activity", version.ref = "activity" }
androidx-constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version.ref = "constraintlayout" }

[plugins]
android-application = { id = "com.android.application", version.ref = "agp" }
jetbrains-kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }

when i was using implementation("com.onesignal:OneSignal:[4.6.4, 5.0.0)") app the building and running fine, now i am getting the above error. I tried contacting one signal but no help. My app is a simple app just to receive push notification nothing else. I am new to Android development. I would be grateful if anyone could help me.

Steps to reproduce?

Previously i used the implementation("com.onesignal:OneSignal:[4.6.4, 5.0.0)") at that time everything was working fine after i updated the SDK to implementation 'com.onesignal:OneSignal:[5.0.0, 5.99.99]' i am getting the error.

What did you expect to happen?

This is a simple app just to receive push notifications from backend through One Signal

OneSignal Android SDK version

implementation 'com.onesignal:OneSignal:[5.0.0, 5.99.99]'

Android version

14, 13, 12, 11, 10, 9, 8

Specific Android models

Android Studio Koala

Relevant log output

`Executing tasks: [:app:clean, :app:assembleDebugAndroidTest, :app:assembleDebug, :app:assembleDebugUnitTest] in project H:\Notification App NOTIFICATION - KOTLIN\V2\V2\BCNOTIFICATION0314PM27072024\notificationApp

> Task :app:clean
> Task :app:preBuild UP-TO-DATE
> Task :app:preDebugBuild UP-TO-DATE
> Task :app:generateDebugResValues
> Task :app:checkDebugAarMetadata
> Task :app:mapDebugSourceSetPaths
> Task :app:generateDebugResources
> Task :app:packageDebugResources
> Task :app:createDebugCompatibleScreenManifests
> Task :app:parseDebugLocalResources
> Task :app:extractDeepLinksDebug

> Task :app:processDebugMainManifest
package="com.myapp.notificationapp" found in source AndroidManifest.xml: H:\Notification App NOTIFICATION - KOTLIN\V2\V2\BCNOTIFICATION0314PM27072024\notificationApp\app\src\main\AndroidManifest.xml.
Setting the namespace via the package attribute in the source AndroidManifest.xml is no longer supported, and the value is ignored.
Recommendation: remove package="com.myapp.notificationapp" from the source AndroidManifest.xml: H:\Notification App NOTIFICATION - KOTLIN\V2\V2\BCNOTIFICATION0314PM27072024\notificationApp\app\src\main\AndroidManifest.xml.

> Task :app:processDebugManifest
> Task :app:javaPreCompileDebug
> Task :app:processDebugManifestForPackage
> Task :app:preDebugAndroidTestBuild SKIPPED
> Task :app:checkDebugAndroidTestAarMetadata
> Task :app:generateDebugAndroidTestResValues
> Task :app:mapDebugAndroidTestSourceSetPaths
> Task :app:generateDebugAndroidTestResources
> Task :app:mergeDebugAndroidTestResources
> Task :app:mergeDebugResources
> Task :app:processDebugAndroidTestManifest
> Task :app:javaPreCompileDebugAndroidTest
> Task :app:mergeDebugAndroidTestShaders
> Task :app:compileDebugAndroidTestShaders NO-SOURCE
> Task :app:generateDebugAndroidTestAssets UP-TO-DATE
> Task :app:mergeDebugAndroidTestAssets
> Task :app:compressDebugAndroidTestAssets
> Task :app:checkDebugAndroidTestDuplicateClasses
> Task :app:desugarDebugAndroidTestFileDependencies
> Task :app:mergeDebugAndroidTestJniLibFolders
> Task :app:mergeLibDexDebugAndroidTest
> Task :app:mergeDebugJniLibFolders
> Task :app:mergeDebugNativeLibs NO-SOURCE
> Task :app:mergeDebugAndroidTestNativeLibs NO-SOURCE
> Task :app:stripDebugAndroidTestDebugSymbols NO-SOURCE
> Task :app:validateSigningDebugAndroidTest
> Task :app:processDebugAndroidTestResources
> Task :app:writeDebugAndroidTestSigningConfigVersions
> Task :app:mergeDebugNativeDebugMetadata NO-SOURCE
> Task :app:mergeDebugShaders
> Task :app:compileDebugShaders NO-SOURCE
> Task :app:generateDebugAssets UP-TO-DATE
> Task :app:mergeDebugAssets
> Task :app:compressDebugAssets
> Task :app:desugarDebugFileDependencies
> Task :app:mergeDebugStartupProfile UP-TO-DATE
> Task :app:stripDebugDebugSymbols NO-SOURCE
> Task :app:validateSigningDebug
> Task :app:writeDebugAppMetadata
> Task :app:checkDebugDuplicateClasses
> Task :app:writeDebugSigningConfigVersions
> Task :app:preDebugUnitTestBuild UP-TO-DATE
> Task :app:javaPreCompileDebugUnitTest
> Task :app:mergeLibDexDebug
> Task :app:mergeExtDexDebugAndroidTest
> Task :app:processDebugResources
> Task :app:mergeExtDexDebug

> Task :app:compileDebugKotlin FAILED
e: file:///H:/Notification%20app%20NOTIFICATION%20-%20KOTLIN/V2/V2/BCNOTIFICATION0314PM27072024/notificationApp/app/src/main/java/com/myapp/notificationapp/MainActivity.kt:27:19 Unresolved reference: setLogLevel
e: file:///H:/Notification%20app%20NOTIFICATION%20-%20KOTLIN/V2/V2/BCNOTIFICATION0314PM27072024/notificationApp/app/src/main/java/com/myapp/notificationapp/MainActivity.kt:27:41 Unresolved reference: LOG_LEVEL
e: file:///H:/Notification%20app%20NOTIFICATION%20-%20KOTLIN/V2/V2/BCNOTIFICATION0314PM27072024/notificationApp/app/src/main/java/com/myapp/notificationapp/MainActivity.kt:27:70 Unresolved reference: LOG_LEVEL
e: file:///H:/Notification%20app%20NOTIFICATION%20-%20KOTLIN/V2/V2/BCNOTIFICATION0314PM27072024/notificationApp/app/src/main/java/com/myapp/notificationapp/MainActivity.kt:31:19 Unresolved reference: setAppId
e: file:///H:/Notification%20app%20NOTIFICATION%20-%20KOTLIN/V2/V2/BCNOTIFICATION0314PM27072024/notificationApp/app/src/main/java/com/myapp/notificationapp/MyNotificationOpenedHandler.kt:5:22 Unresolved reference: OSNotificationOpenedResult
e: file:///H:/Notification%20app%20NOTIFICATION%20-%20KOTLIN/V2/V2/BCNOTIFICATION0314PM27072024/notificationApp/app/src/main/java/com/myapp/notificationapp/MyNotificationOpenedHandler.kt:8:69 Unresolved reference: OSNotificationOpenedHandler
e: file:///H:/Notification%20app%20NOTIFICATION%20-%20KOTLIN/V2/V2/BCNOTIFICATION0314PM27072024/notificationApp/app/src/main/java/com/myapp/notificationapp/MyNotificationOpenedHandler.kt:9:5 'notificationOpened' overrides nothing
e: file:///H:/Notification%20app%20NOTIFICATION%20-%20KOTLIN/V2/V2/BCNOTIFICATION0314PM27072024/notificationApp/app/src/main/java/com/myapp/notificationapp/MyNotificationOpenedHandler.kt:9:45 Unresolved reference: OSNotificationOpenedResult

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction
   > Compilation error. See log for more details

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

For more on this, please refer to https://docs.gradle.org/8.7/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.

BUILD FAILED in 16s
47 actionable tasks: 46 executed, 1 up-to-date

Code of Conduct

  • I agree to follow this project's Code of Conduct
@michael-winkler
Copy link

@fcidev
Copy link
Author

fcidev commented Aug 2, 2024

@michael-winkler Thank You so much my issue is resolved now. I will post how I resolved this below so that someone else might find it helpful.

In the MainActivity i changed

OneSignal.initWithContext(this) OneSignal.setAppId(ONESIGNAL_APP_ID)

to

OneSignal.initWithContext(this, ONESIGNAL_APP_ID)

Then in the MyNotificationOpenedHandler

I removed
import com.onesignal.OSNotificationOpenedResult

and imported the following

import com.onesignal.OneSignal
import com.onesignal.notifications.INotificationReceivedEvent;
import com.onesignal.notifications.INotificationServiceExtension;

and then in the AndroidManifest i added the following line

<meta-data android:name="com.onesignal.NotificationServiceExtension"
  android:value="com.myapppackagename.NotificationServiceExtension" />   <!-- Replace mypackagename with your package name and NotificationServiceExtension with your class name -->

@fcidev fcidev closed this as completed Aug 2, 2024
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

2 participants