Android Question Trying to compile Anywhere Software BlePeripheral2.java [SOLVED]

Peter Simpson

Expert
Licensed User
Longtime User
Hello all,
I'm trying to recompile Anywhere Software BlePeripheral2.java into a new test library, please note that I've not changed anything in original BlePeripheral2.java file but I'm getting an error whilst compiling.

Below is the file that I'm trying to compile, I've not changed anything. I've just downloaded the file from Anywhere Software Github page and placed it into src\anywheresoftware\b4a\objects folder.
[/URL]

Below is the error message that I'm seeing with absolutely changes to the original code.
Starting step: Compiling Java code.
javac 1.8.0_381
C:\Users\peter\Desktop\Test P2\src\anywheresoftware\b4a\objects\BlePeripheral2.java:76: error: cannot find symbol
public void Initialize(BA ba, String EventName, BleManager2 Ble) {
^
symbol: class BleManager2
location: class BlePeripheral2
Note: C:\Users\peter\Desktop\Test P2\src\anywheresoftware\b4a\objects\BlePeripheral2.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
1 error


Error.

I've been trying to get BlePeripheral2.java to compile into a library for days, but to no avail. With very little actual java coding experience I'm finding it impossible to fix the error message and compile. I personally DO NOT code in java, so any help would be seriously appreciated.


Thank you.
Peter...
 
Last edited:

Daestrum

Expert
Licensed User
Longtime User
It looks like the class you need is defined in BLEManager2.java

You could try import anywheresoftware.b4a.objects.BLEManager2 and hope the compiler/linker can find it on the classpath.
 
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
It looks like the class you need is defined in BLEManager2.java

You could try import anywheresoftware.b4a.objects.BLEManager2 and hope the compiler/linker can find it on the classpath.

Sorry, I was just in the middle of editing my original post when you posted your response.

Thank you for that @Daestrum, I've just tried your suggestion but to no avail. But it does seem that there's been a step forward.
Starting step: Compiling Java code.
javac 1.8.0_381
C:\Users\peter\Desktop\Test P2\src\anywheresoftware\b4a\objects\BlePeripheral2.java:129: error: incompatible types: Object cannot be converted to Entry<Object,Object>
for (Entry<Object, Object> e : manufacturerData.getObject().entrySet()) {
^
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
1 error


Error.

Thank you.
Peter...
 
Last edited:
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
I would guess BLE2 and BLE2Peripheral were compiled together - so peripheral has access to the missing class.
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
are you using slc to compile? if so, if you put BleManager2.java and BlePeripheral2.java in the same folder and compile at the same time, you get a bit farther...
 
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
are you using slc to compile? if so, if you put BleManager2.java and BlePeripheral2.java in the same folder and compile at the same time, you get a bit farther...
Hello @drgottjr,
Firstly thank you for replying to my question.

As you can see from the screenshots below. I've already added the two files into the same folder plus I've added the import line.

1701980794208.png

1701980655276.png
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
remove the import line. you're importing something you're attempting to build at the same time. if you were extending the BlePeripheral2 class, i think it would be a different story.
 
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
remove the import line. you're importing something you're attempting to build at the same time. if you were extending the BlePeripheral2 class, i think it would be a different story.

Thank you.
I've replaced the two files with the original files directly from Anywhere Software GitHub and clicked compile. I'm still getting the exact same error as before just one line number lower.
Starting step: Compiling Java code.
javac 1.8.0_381
C:\Users\peter\Desktop\Test P2\src\anywheresoftware\b4a\objects\BlePeripheral2.java:129: error: incompatible types: Object cannot be converted to Entry<Object,Object>
for (Entry<Object, Object> e : manufacturerData.getObject().entrySet()) {
^
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
1 error


Error.
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
i build a ble2.jar using slc with the 2 java files in the same folder and no import of the blemanager2 class.
there was an error, but it wasn't the one you're seeing. it's a typing error which, i was hoping, you would see too. then you could move on to it.
if i comment a couple lines of code out relating to that error, the library builds. there is also an issue with the accompaning xml file. but, here again, i was hoping you would see that as well.

in any case, i'm writing this just to show that it is possible to build the thing.
 

Attachments

  • ble2.jar
    16.7 KB · Views: 145
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
i build a ble2.jar using slc with the 2 java files in the same folder and no import of the blemanager2 class.
there was an error, but it wasn't the one you're seeing. it's a typing error which, i was hoping, you would see too. then you could move on to it.
if i comment a couple lines of code out relating to that error, the library builds. there is also an issue with the accompaning xml file. but, here again, i was hoping you would see that as well.

in any case, i'm writing this just to show that it is possible to build the thing.

Thank you for the feedback @drgottjr.
Can you quickly explain how you got it to compile, I need to make some changes to the file before compiling but it's not compiling at my end. I keep getting the same incompatible types issue. I don't do java so this is not the easiest thing for me to get my head around. What I have to change in the file does not look too difficult, but I just can't compile the original file even if I do no change it at all.
 
Last edited:
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
i use my normal setup for building libraries (see attached). i run slc, point it to the folder (ble2) and give the output a name (ble2). tap compile button.
in my case, there was an error relating to manufacturersid data. i commented out a couple of lines relating to that, and compiled again. success! but there were some error messages relating to creating the xml file. i don't know what the issue is there, but i was keen to show you that it was possible to compile a library.
the manufacturersid data error can proabably be resolved. i don't know what the deal is with the xml. i know there have been problems relating to it when using java 11 with slc. i tried both with java 11 and 8. same story.
 

Attachments

  • setup.png
    setup.png
    116.3 KB · Views: 118
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
that said, i didn't realize bleperipheral2 was separate from b4a's ble2.jar. (i don't do much with bt). i don't know if erel uses slc when creating libs for b4a, but, clearly, he was able to compile bl2peripheral2.java into a .jar. it may not be (easily) doable with slc. but with both java files in place, it does seem possible.
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
here's how to do it: in the folder where you're building the lib, you have a "src" folder. create a "libs" folder at the same level and copy Ble2.jar from b4a's internal libraries to it.
in your ble2peripheral.java source, add these lines:

import anywheresoftware.b4a.BA.DependsOn;

@DependsOn(values="{anywheresoftware.b4a.objects.BLE2}")

this will resolve unknown class problem. in my case the source compiled and there were no xml errors. i still commented out the error relating to manufacturersid (maybe i didn't have to; i just did it out of habit at this point)


the error is a casting error, i think. i've tried several variations, but i can't get it yet.
 
Last edited:
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
Greetings :)

Some time ago I had the same problem. As I was in a hurry (and felt lazy to investigate), tried replacing the only usage of the unresolved dependency to something equivalent (at least in Android, I supposed). I could compile it and, as far as I remember, could develop my project with it.
(To avoid confussion with the existing BLEPeripheral2 just renamed the file and class to BLEPeripheral3)

B4X:
    public void Initialize(BA ba, String EventName/*, BleManager2 Ble*/) {
//        blueAdapter = Ble.blueAdapter;
        blueAdapter = BluetoothAdapter.getDefaultAdapter();
        this.ba = ba;
        this.eventName = EventName.toLowerCase(BA.cul);
        advertiser = blueAdapter.getBluetoothLeAdvertiser();
    }
Hope it helps!
 
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
Greetings :)

Some time ago I had the same problem. As I was in a hurry (and felt lazy to investigate), tried replacing the only usage of the unresolved dependency to something equivalent (at least in Android, I supposed). I could compile it and, as far as I remember, could develop my project with it.
(To avoid confussion with the existing BLEPeripheral2 just renamed the file and class to BLEPeripheral3)

B4X:
    public void Initialize(BA ba, String EventName/*, BleManager2 Ble*/) {
//        blueAdapter = Ble.blueAdapter;
        blueAdapter = BluetoothAdapter.getDefaultAdapter();
        this.ba = ba;
        this.eventName = EventName.toLowerCase(BA.cul);
        advertiser = blueAdapter.getBluetoothLeAdvertiser();
    }
Hope it helps!
That's a good idea, I'll try that later...
 
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
I can confirm that you must use Java 8 when compiling with SLC otherwise the XML file will probably either be written incorrectly or cause an XML generation error.
You are 100% correct Andrew. I was already using Java 8. I had a typo in a folder name, instead of libs, it read lids. So even though the ble2.jar file was in there, my typo meant that I was adding blemanager2.java to the main folder when I didn't really have to. Renaming the folder to libs and removing the blemanager2.java file fixed all my issues.

As I said previously, I don't code in java. This experience took a lot longer than it should have done due to my inadequacies in java.

Thank you for responding Andrew, cheers ?
 
Last edited:
Upvote 0
Top