2

react-native run-android failed after linking with react-native-ble-plx

Task :react-native-ble-plx:compileDebugJavaWithJavac FAILED

This is a newly created app with react-native init, didn't change anything except the min sdk. Already tried to clean project, set min sdk to 18, tried to build with android studio to get more specific error but still can't understand where is the problem coming from.

The Error i get:

Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/5.4.1/userguide/command_line_interface.html#sec:command_line_warnings
12 actionable tasks: 2 executed, 10 up-to-date
warning: [options] source value 7 is obsolete and will be removed in a future release
warning: [options] target value 7 is obsolete and will be removed in a future release
warning: [options] To suppress warnings about obsolete options, use -Xlint:-options.
/Users/oriamd/Documents/MyDev/DudeWheresMyCar/node_modules/react-native-ble-plx/android/src/main/java/com/polidea/reactnativeble/converter/RxBleScanResultConverter.java:3: error: package android.support.annotation does not exist
import android.support.annotation.NonNull;
                                 ^
/Users/oriamd/Documents/MyDev/DudeWheresMyCar/node_modules/react-native-ble-plx/android/src/main/java/com/polidea/reactnativeble/wrapper/Characteristic.java:5: error: package android.support.annotation does not exist
import android.support.annotation.NonNull;
                                 ^

full logs here : https://pastebin.com/NJAmjUJm

Can supply more information if needed. Thank you

Kreator
  • 59
  • 1
  • 11

3 Answers3

2

This issue is similar to this issue.

As mentioned in @Kreator answer it is related to some packages that are not converted to AndroidX.

To fix this issue you can use jetifier.

I have the same issue mentioned in the question and these steps solved it and application run again.

  1. First, use Android Studio's refactoring tool to convert your app re: the Android developer docs
  2. npm install --save-dev jetifier
  3. npx jetify
  4. npx react-native run-android (your app should correctly compile and work)
  5. Call npx jetify run in the postinstall target of your package.json (Any time your dependencies update you have to jetify again)
MBS
  • 673
  • 2
  • 16
  • 48
1

Problem was that i was using Android Studio Preview, and with that AndroidX and more unsupported packages.

Kreator
  • 59
  • 1
  • 11
0

I HAD THIS SAME ISSUE.

"Task :react-native-ble-plx:compileDebugJavaWithJavac FAILED FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ':react-native-ble-plx:compileDebugJavaWithJavac'. 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. Run with --scan to get full insights.

  • Get more help at https://help.gradle.org

BUILD FAILED in 54s

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.

Solution

this was my build.gradle project:

buildscript {
    ext {
        buildToolsVersion = "30.0.2"
        minSdkVersion = 21
        compileSdkVersion = 31
        targetSdkVersion = 31
        ndkVersion = "21.4.7075529"
        kotlin_version = "1.6.0" // Update this to your version
    }
    repositories {
        google()
        mavenCentral()
    }
...
}

I changed the some version to as following:

    compileSdkVersion = 29
    targetSdkVersion = 29

And now the Build is successful!