don / cordova-plugin-ble-central

Bluetooth Low Energy (BLE) Central plugin for Apache Cordova (aka PhoneGap)
Apache License 2.0
941 stars 601 forks source link

Failed to build L2CAPContext.java and Peripheral.java #977

Closed nikolaof closed 9 months ago

nikolaof commented 11 months ago

Hello.

I'm trying to build an ionic project that uses this plugin and 4 months earlier I was able to build it but no more.

More specifically here is what I'm getting:

/home/user/dev/ionic-app/platforms/android/app/src/main/java/com/megster/cordova/ble/central/Peripheral.java:35: error: cannot find symbol
import androidx.annotation.RequiresPermission;
                          ^
  symbol:   class RequiresPermission
  location: package androidx.annotation
/home/user/dev/ionic-app/platforms/android/app/src/main/java/com/megster/cordova/ble/central/L2CAPContext.java:6: error: cannot find symbol
import androidx.annotation.RequiresApi;
                          ^
  symbol:   class RequiresApi
  location: package androidx.annotation
/home/user/dev/ionic-app/platforms/android/app/src/main/java/com/megster/cordova/ble/central/Peripheral.java:1000: error: cannot find symbol
    @RequiresPermission("android.permission.BLUETOOTH_CONNECT")
     ^
  symbol:   class RequiresPermission
  location: class Peripheral
/home/user/dev/ionic-app/platforms/android/app/src/main/java/com/megster/cordova/ble/central/Peripheral.java:1028: error: cannot find symbol
    @RequiresPermission("android.permission.BLUETOOTH_CONNECT")
     ^
  symbol:   class RequiresPermission
  location: class Peripheral
/home/user/dev/ionic-app/platforms/android/app/src/main/java/com/megster/cordova/ble/central/Peripheral.java:1076: error: cannot find symbol
    @RequiresPermission("android.permission.BLUETOOTH_CONNECT")
     ^
  symbol:   class RequiresPermission
  location: class Peripheral
/home/user/dev/ionic-app/platforms/android/app/src/main/java/com/megster/cordova/ble/central/L2CAPContext.java:110: error: cannot find symbol
    @RequiresApi(api = Build.VERSION_CODES.M)
     ^
  symbol:   class RequiresApi
  location: class L2CAPContext
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
6 errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileReleaseJavaWithJavac'.

The environment of mine is quite old but I'm not sure if that's the issue.

$ npm list -g

/home/user/.nvm/versions/node/v16.9.0/lib
├── @angular/cli@8.3.29
├── @ionic/cli@6.17.1
├── cordova@10.0.0
├── ionic@5.4.16
└── npm@7.21.1

$ java -version
java version "1.8.0_301"

In Ionic's config file I have set <preference name="android-targetSdkVersion" value="31" />

Plugin's version: 1.7.0

peitschie commented 11 months ago

Hi @nikolaof

This sounds very similar to https://github.com/don/cordova-plugin-ble-central/issues/957

I've raised https://github.com/don/cordova-plugin-ble-central/pull/978 to add the missing dependency, but I suspect you'll run into a permissions issue next like this:

ERROR:/home/runner/work/cordova-plugin-ble-central/cordova-plugin-ble-central/temp/android/app/build/intermediates/packaged_manifests/debug/AndroidManifest.xml:26: AAPT: error: attribute android:usesPermissionFlags not found.

What version of cordova-android are you using in your project there?

nikolaof commented 11 months ago

I'm using cordova-android in 9.1.0

So I added the <framework src="androidx.annotation:annotation:*"/> line manually in the plugin.xml as mentioned in #978.

Then tried to rebuild and I got this error back:

* What went wrong:
Execution failed for task ':app:mergeDebugResources'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
   > Could not find androidx.annotation:annotation:*.
     Searched in the following locations:
       - https://repo.maven.apache.org/maven2/androidx/annotation/annotation/*/annotation-*.pom
       - https://dl.google.com/dl/android/maven2/androidx/annotation/annotation/*/annotation-*.pom
       - https://jcenter.bintray.com/androidx/annotation/annotation/*/annotation-*.pom
       - file:/home/user/dev/ionic-app-demo/platforms/android/app/libs/annotation-*.jar
       - file:/home/user/dev/ionic-app-demo/platforms/android/app/libs/annotation.jar
     Required by:
         project :app

EDIT:

From a search I did, is seems that all the links it tries to fetch it arel not working. :/ How can this be the case?

EDIT 2:

So after updating into cordova-android 12.0.0, and JDK 11 the app get's compiled.