React-native-push-notification: Execution failed for task ':react-native-push-notification:compileReleaseJavaWithJavac'

Created on 1 Aug 2018  路  34Comments  路  Source: zo0r/react-native-push-notification

Hi,

I'm sorry if this has been resolved already, but I've been stuck with this for a while now. I've installed the package, and did the link as per the README. Added the extra info in the AndroidManifest.xml after doing a link. I even tried to install the package and do a manual installation for android. It keeps failing to build.

My build.gradle looks like this

defaultConfig { applicationId "exampleProject" minSdkVersion 16 targetSdkVersion 22 versionCode 1 versionName "1.0" ndk { abiFilters "armeabi-v7a", "x86" } }

The error that I get is:

:react-native-push-notification:compileReleaseJavaWithJavac
:react-native-push-notification:compileReleaseJavaWithJavac - is not incremental (e.g. outputs have changed, no previous execution, etc.).
/Users/umair/Desktop/Projects/*****/node_modules/react-native-push-notification/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotificationHelper.java:7: error: cannot find symbol
import android.app.NotificationChannel;
                  ^
  symbol:   class NotificationChannel
  location: package android.app
/Users/umair/Desktop/Projects/*****/node_modules/react-native-push-notification/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotificationHelper.java:162: error: constructor Builder in class Builder cannot be applied to given types;
            NotificationCompat.Builder notification = new NotificationCompat.Builder(context, NOTIFICATION_CHANNEL_ID)
                                                      ^
  required: Context
  found: Context,String
  reason: actual and formal argument lists differ in length
/Users/umair/Desktop/Projects/*****/node_modules/react-native-push-notification/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotificationHelper.java:480: error: cannot find symbol
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O)
                                                       ^
  symbol:   variable O
  location: class VERSION_CODES
/Users/umair/Desktop/Projects/*****/node_modules/react-native-push-notification/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotificationHelper.java:488: error: cannot find symbol
        int importance = NotificationManager.IMPORTANCE_DEFAULT;
                                            ^
  symbol:   variable IMPORTANCE_DEFAULT
  location: class NotificationManager
/Users/umair/Desktop/Projects/*****/node_modules/react-native-push-notification/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotificationHelper.java:489: error: cannot find symbol
        NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, name, importance);
        ^
  symbol:   class NotificationChannel
  location: class RNPushNotificationHelper
/Users/umair/Desktop/Projects/*****/node_modules/react-native-push-notification/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotificationHelper.java:489: error: cannot find symbol
        NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, name, importance);
                                          ^
  symbol:   class NotificationChannel
  location: class RNPushNotificationHelper
Note: /Users/umair/Desktop/Projects/*****/node_modules/react-native-push-notification/android/src/main/java/com/dieam/reactnativepushnotification/helpers/ApplicationBadgeHelper.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
6 errors
:react-native-push-notification:compileReleaseJavaWithJavac FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':react-native-push-notification:compileReleaseJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

Any help or suggestions would be greatly appreciated. Thanks

Stale

Most helpful comment

Just fixed it by adding this to android/build.gradle file:

subprojects {
    afterEvaluate {project ->
        if (project.hasProperty("android")) {
            android {
                compileSdkVersion 27
                buildToolsVersion "27.0.2"
            }
        }
    }
}

All 34 comments

I got this error too after updated to version 3.1.1

@ahmedu007 I think that error is referred to #801 and also @danferd is right, I had to downgrade to version 3.0.2

You need to use at least SDK 26. Your app will not be accepted on Play store if you target an older SDK than 26.

@Gp2mv3 any reason why Play store would reject the app? And downgrading to the version 3.0.2, Would I have problems with Play store?

@Gp2mv3 thanks 馃槵!!

@Gp2mv3 is it only the targetSdkVersion that i must update to 26 or compileSdkVersion also?

I'm using targetSdkVersion 26 but still failed to sign the apk.

compileSdkVersion: 26
minSdkVersion: 16
targetSdkVersion: 26

Just fixed it by adding this to android/build.gradle file:

subprojects {
    afterEvaluate {project ->
        if (project.hasProperty("android")) {
            android {
                compileSdkVersion 27
                buildToolsVersion "27.0.2"
            }
        }
    }
}

Going back to 3.0.2 fixed the issue. I've also updated the SDK to use 27 now. But it still wont build on the latest version. The same error comes back

Fixed this issue by following instructions in the First step of Android manual installation

In your android/build.gradle

ext {
    ...
    compileSdkVersion = <Your compile SDK version> // default: 23
    buildToolsVersion = "<Your build tools version>" // default: "23.0.1"
    targetSdkVersion = <Your target SDK version> // default: 23
    supportLibVersion = "<Your support lib version>" // default: 23.1.1
}

Im using :

compileSdkVersion 27
buildToolsVersion "27.0.3"
minSdkVersion 23
targetSdkVersion 27

and still get this error.

I've already got that in the android/build.gradle

        compileSdkVersion 27
        buildToolsVersion "27.0.3"
        minSdkVersion 16
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }

I solved this issue by keeping the version same both side.

Inside my project:

android/build.gradle:

dependencies {
        classpath 'com.android.tools.build:gradle:2.2.3'
    }

android/app/build.gradle:

    compileSdkVersion 26
    buildToolsVersion "26.0.2"
       ...
    defaultConfig {
        ...
        minSdkVersion 16
        targetSdkVersion 22
        ...
    }

Inside react-native-push-notification/android/build.gradle

dependencies {
        classpath 'com.android.tools.build:gradle:2.2.3'  //-----> Changed this from 2.1.3
 }
def DEFAULT_COMPILE_SDK_VERSION = 26           //Changed
def DEFAULT_BUILD_TOOLS_VERSION = "26.0.2"    //Changed
def DEFAULT_TARGET_SDK_VERSION = 22           //Changed
def DEFAULT_SUPPORT_LIB_VERSION = "26.+"       //Changed
def DEFAULT_GOOGLE_PLAY_SERVICES_VERSION = "+"
def DEFAULT_FIREBASE_MESSAGING_VERSION = "+"

This configuration worked for me.

Change values to these inside react-native-push-notification/android/build.gradle

def DEFAULT_COMPILE_SDK_VERSION = 27
def DEFAULT_BUILD_TOOLS_VERSION = "27.0.3"
def DEFAULT_TARGET_SDK_VERSION = 26
def DEFAULT_SUPPORT_LIB_VERSION = "26.+"

@emilisb - where did you add these changes?

@magick93 inside react-native-push-notification/android/build.gradle

Ok thanks. But then I will need to commit this module to git?
I use jenkins to build may app, and that is a clean environment every build - it downloads all node modules every build.
So I dont think this hack will work in the build server.

no need to change nodemodules just use this "android/build.gradle"

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

buildscript {
repositories {
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}

}

allprojects {
repositories {
mavenLocal()
jcenter()
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
maven {
url 'https://maven.google.com/'
name 'Google'
}
maven { url "https://jitpack.io" }
}
}

ext {
compileSdkVersion = 27
targetSdkVersion = 27
buildToolsVersion = "27.0.2"
supportLibVersion = "27.0.2"
googlePlayServicesVersion = "11.8.0"
androidMapsUtilsVersion = "0.5+"
}

`

@neel132
I get this error

C:\Users\Wilson\Desktop\NotificationApp\node_modules\react-native-push-notification\android\src\main\java\com\dieam\reactnativepushnotification\modules\RNPushNotificationHelper.java:162: error: constructor Builder in class Builder cannot be applied to given types;
NotificationCompat.Builder notification = new NotificationCompat.Builder(context, NOTIFICATION_CHANNEL_ID)
^
required: Context
found: Context,String
reason: actual and formal argument lists differ in length
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
1 error
:react-native-push-notification:compileReleaseJavaWithJavac FAILED

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':react-native-push-notification:compileReleaseJavaWithJavac'.

    Compilation failed; see the compiler error output for details.

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 51.93 secs

Inside my Project
android\app\build.gradle

compileSdkVersion 27
buildToolsVersion "27.0.3"

defaultConfig {
    applicationId "com.notificationapp"
    minSdkVersion 16
    targetSdkVersion 26
    versionCode 1
    versionName "1.0"
    ndk {
        abiFilters "armeabi-v7a", "x86"
    }

android\build.gradle
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
}

Inside react-native-push-notification/android/build.gradle

dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
}
def DEFAULT_COMPILE_SDK_VERSION = 27
def DEFAULT_BUILD_TOOLS_VERSION = "27.0.3"
def DEFAULT_TARGET_SDK_VERSION = 26
def DEFAULT_SUPPORT_LIB_VERSION = "26.+"
def DEFAULT_GOOGLE_PLAY_SERVICES_VERSION = "+"
def DEFAULT_FIREBASE_MESSAGING_VERSION = "+"

Any help or suggestions would be greatly appreciated. Thanks

I merger PR #826 that should fix this issue. Can you confirm ?

@Gp2mv3

BUILD FAILED

Total time: 1 mins 0.69 secs
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/getting-started.html

C:\Users\Wilson\Desktop\Desktop\React Native Projects\NotificationApp>react-native run-android
Scanning folders for symlinks in C:\Users\Wilson\Desktop\Desktop\React Native Projects\NotificationApp\node_modules (29ms)
Starting JS server...
Building and installing the app on the device (cd android && gradlew.bat installDebug)...
File C:\Users\Wilson.android\repositories.cfg could not be loaded.

FAILURE: Build failed with an exception.

  • What went wrong:
    A problem occurred configuring project ':app'.

    Could not resolve all dependencies for configuration ':app:_debugApk'.
    A problem occurred configuring project ':react-native-push-notification'.
    Could not resolve all dependencies for configuration ':react-native-push-notification:_debugPublishCopy'.
    Could not find com.android.support:appcompat-v7:27.1.1.
    Searched in the following locations:
    file:/C:/Users/Wilson/AppData/Local/Android/Sdk/extras/android/m2repository/com/android/support/appcompat-v7/27.1.1/appcompat-v7-27.1.1.pom
    file:/C:/Users/Wilson/AppData/Local/Android/Sdk/extras/android/m2repository/com/android/support/appcompat-v7/27.1.1/appcompat-v7-27.1.1.jar
    file:/C:/Users/Wilson/Desktop/Desktop/React Native Projects/NotificationApp/android/sdk-manager/com/android/support/appcompat-v7/27.1.1/appcompat-v7-27.1.1.jar
    Required by:
    NotificationApp:react-native-push-notification:unspecified
    Could not find com.android.support:appcompat-v7:27.1.1.
    Searched in the following locations:
    file:/C:/Users/Wilson/AppData/Local/Android/Sdk/extras/android/m2repository/com/android/support/appcompat-v7/27.1.1/appcompat-v7-27.1.1.pom
    file:/C:/Users/Wilson/AppData/Local/Android/Sdk/extras/android/m2repository/com/android/support/appcompat-v7/27.1.1/appcompat-v7-27.1.1.jar
    file:/C:/Users/Wilson/Desktop/Desktop/React Native Projects/NotificationApp/android/sdk-manager/com/android/support/appcompat-v7/27.1.1/appcompat-v7-27.1.1.jar
    Required by:
    NotificationApp:react-native-push-notification:unspecified > com.facebook.react:react-native:0.55.4

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 16.869 secs
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/getting-started.html

Inside my Project
android\app\build.gradle

compileSdkVersion 27
buildToolsVersion "27.0.3"

defaultConfig {
applicationId "com.notificationapp"
minSdkVersion 16
targetSdkVersion 27
versionCode 1
versionName "1.0"
ndk {
abiFilters "armeabi-v7a", "x86"
}
android\build.gradle
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
}

Inside react-native-push-notification/android/build.gradle

dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
}
def DEFAULT_COMPILE_SDK_VERSION = 27
def DEFAULT_BUILD_TOOLS_VERSION = "27.0.3"
def DEFAULT_TARGET_SDK_VERSION = 27
def DEFAULT_SUPPORT_LIB_VERSION = "27.1.1"
def DEFAULT_GOOGLE_PLAY_SERVICES_VERSION = "+"
def DEFAULT_FIREBASE_MESSAGING_VERSION = "+"

after manual link on android, install older version with "npm install --save [email protected]" fixed Javac issue

@GabrielScalici
thanks! fixed!

Had the same issue. The fix was not to set the support lib version at all.
ext {
compileSdkVersion = 26
targetSdkVersion = 22
buildToolsVersion = "26.0.2"
}

We also hit this issue with version 3.1.1 and RN 0.55.4.

Here's a patch of the commit which fixed this for our project

https://gist.github.com/epeli/e5b192c3b75ba84e5ec695d124de1e86

We also hit some compatibility issues with react-native-maps too... Hence the changes for com.google.android.gms:play-services-maps

I also manually merged https://github.com/zo0r/react-native-push-notification/pull/826 to my node_modules.

@epeli Thank you so much. you save me.

Only works with downgrade...
Version 3.0.2 is the only one that works without any problem, all the others after it gave problem here.
And adding this to android/build.gradle file:
subprojects { afterEvaluate {project -> if (project.hasProperty("android")) { android { compileSdkVersion 27 buildToolsVersion "27.0.2" } } } }
Do not waste your time trying to use new versions, unfortunately the developer support sucks.

@GleidsonDaniel I've been using 3.1.1 since release without any problems.

Here's the configurations that I've been using on my android/build.gradle

```
subprojects {
afterEvaluate {project ->
if (project.hasProperty("android")) {
android {
compileSdkVersion 27
buildToolsVersion '27.0.3'
}
}
}
}

ext {
compileSdkVersion = 27
buildToolsVersion = "27.0.3"
targetSdkVersion = 26
supportLibVersion = "27.1.0"
}
```

When will we have an official release with the right fix instead of doing workaround like above?

ext {
    buildToolsVersion = "27.0.3"
    minSdkVersion = 16
    compileSdkVersion = 27
    targetSdkVersion = 27
}

@haotangio put this code at the end of the android/build.gradle
It is not work-around. The issue is coming because lastest changes related to Android notifications are not getting compiled due to the old SDK version. Doing the above changes will use the latest SDK version to compile and it compiles properly.

I'm still getting this error with the latest version of the lib (3.1.2). @emilisb solution worked though.

Can this be fixed upstream? We have to apply this patch every time you npm install

_(use lower version to avoid the issues :-)_
If You use push notification version @3.1.3 then try like this

in your (package.json)
"react": "^16.6.3",
"react-native": "^0.58.5",
"react-native-push-notification": "^3.1.3",

and in your (android/build.gradle)
ext {
googlePlayServicesVersion = "16.+" // default: "+"
firebaseVersion = "17.6.0" // default: "+"
buildToolsVersion = "27.0.3"
minSdkVersion = 21
compileSdkVersion = 27
targetSdkVersion = 26
supportLibVersion = "27.1.1"
}
like that
i hope this will work for you all and the same it works for me....

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 30 days if no further activity occurs. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

anativ picture anativ  路  3Comments

selimonline picture selimonline  路  3Comments

ssolida picture ssolida  路  3Comments

halaharr picture halaharr  路  3Comments

GastonEDiaz picture GastonEDiaz  路  3Comments