You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using the latest one signal implementation 'com.onesignal:OneSignal:[5.0.0, 5.99.99]' dependency
Gradle and AGP version 8.7 and 8.5.0
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)
}
}
// 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
`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:processDebugMainManifestpackage="com.myapp.notificationapp" found insource 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 FAILEDe: file:///H:/Notification%20app%20NOTIFICATION%20-%20KOTLIN/V2/V2/BCNOTIFICATION0314PM27072024/notificationApp/app/src/main/java/com/myapp/notificationapp/MainActivity.kt:27:19 Unresolved reference: setLogLevele: 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_LEVELe: 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_LEVELe: file:///H:/Notification%20app%20NOTIFICATION%20-%20KOTLIN/V2/V2/BCNOTIFICATION0314PM27072024/notificationApp/app/src/main/java/com/myapp/notificationapp/MainActivity.kt:31:19 Unresolved reference: setAppIde: file:///H:/Notification%20app%20NOTIFICATION%20-%20KOTLIN/V2/V2/BCNOTIFICATION0314PM27072024/notificationApp/app/src/main/java/com/myapp/notificationapp/MyNotificationOpenedHandler.kt:5:22 Unresolved reference: OSNotificationOpenedResulte: file:///H:/Notification%20app%20NOTIFICATION%20-%20KOTLIN/V2/V2/BCNOTIFICATION0314PM27072024/notificationApp/app/src/main/java/com/myapp/notificationapp/MyNotificationOpenedHandler.kt:8:69 Unresolved reference: OSNotificationOpenedHandlere: file:///H:/Notification%20app%20NOTIFICATION%20-%20KOTLIN/V2/V2/BCNOTIFICATION0314PM27072024/notificationApp/app/src/main/java/com/myapp/notificationapp/MyNotificationOpenedHandler.kt:9:5 'notificationOpened' overrides nothinge: file:///H:/Notification%20app%20NOTIFICATION%20-%20KOTLIN/V2/V2/BCNOTIFICATION0314PM27072024/notificationApp/app/src/main/java/com/myapp/notificationapp/MyNotificationOpenedHandler.kt:9:45 Unresolved reference: OSNotificationOpenedResultFAILURE: 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 16s47 actionable tasks: 46 executed, 1 up-to-date
Code of Conduct
I agree to follow this project's Code of Conduct
The text was updated successfully, but these errors were encountered:
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 -->
What happened?
Project Specifications"
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
MyNotificationOpenedHandler
My App level Build.gradle
My settings.gradle
My project level build.gradle
This is my libs.version.toml
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?
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
Relevant log output
Code of Conduct
The text was updated successfully, but these errors were encountered: