Android Question Separating between two libraries

jackdev65

Member
Licensed User
Hi

I am currently using a modified NFC script that was written in 2014, I have an existing app thats using methods from the latest NFC version. I want to use both libraries as the modified nfc script allows me to access NFCV tag data which i need to add for my existing app. Is there any known way of running both scripts and referencing the new one for the existing app logic and the old script for the NFCV capabilities I am adding?

1715683229844.png



1715683290195.png


This doesn't actually compile but just to show what I require:
example:
Private nfc As NFC.NFC
Private nfcold As NFCOld.NFC

Thanks
 

jackdev65

Member
Licensed User
edit NFCold.xml and change the ShortName.
At least do it on a copy.

BTW: Only NFC Library should be in internal dir.
All others should be in the additional libs folder.
Hi @DonManfred Thank you for this, only just getting round to testing this and getting the below error:

I have tried:

Renaming the <name> to ...objects.NFCOld.NfcVWrapper - no luck
Changing all the <name> attributes to ...objects.NFCOld.xxx - no luck

Hoping it's something simple as i really need both versions of this NFC library (the nfc old one supporting NFCV scanning)

1716976070533.png

1716976077599.png

1716976084238.png
 
Upvote 0

jackdev65

Member
Licensed User
i NEVER told you to rename the files. I told you to CHANGE the XML and change the ShortName inside.

Thanks for the quick reply, apologies I am a little confused as I thought the old NFCV library needed to have a differently named .jar and .xml file.

So in Internal Dir I have the latest NFC library .jar and .xml
In External Libraries I have the NFCV-supported one (named NFCOld.jar with NFCOld.xml)
I was under the impression they needed to be named like this?
I have only changed the shortname (from NFC to NFCOld) in the NFCOld.xml file and that error is what shows

Where exactly have I gone wrong?

Thanks :)
 
Upvote 0

jackdev65

Member
Licensed User
DO NOT change any FILENAME.

Again (and the last time): EDIT the libary XML-File. Change the ShortName annotation in it to another name. Save the XML.
Reload the library in xyou project and try again.
Okay so have done as you say:

Internal Dir:
1716980540372.png

Additional Libraries:
1716980503199.png

AdditionalLibraries/NFC.xml
1716980567513.png

Refresh in B4A - Now it's Only showing internal NFC lib
1716980579723.png

Not finding NFCOld shortname
1716980621821.png


Feel like its almost there, I appreciate your help
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
1. REMOVE the files NFC.* from yopur additional libs folder. You can not have two Libs of the same NAME.
Rename the nfc.* files in your ADDITIONAL library folder to nfcnew or something. At least another name than NFC

Edit the NFC.XML inside the internal library folder. Change shortName to NFCold.


B4A_MEablE1imZ.png
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
I think you will still have a problem as the class name is same same in both files 'anywheresoftware.b4a.objects.NFC' - the linker won't know which one to use, and probably the last one entered will overwrite the previous one.
 
Upvote 0

jackdev65

Member
Licensed User
Sure thing, the first two are internal, second two are the NFCV one
 

Attachments

  • NFC.jar
    12.2 KB · Views: 86
  • NFC.xml
    8.2 KB · Views: 98
  • NFC.jar
    28 KB · Views: 109
  • NFC.xml
    12 KB · Views: 85
Upvote 0

jackdev65

Member
Licensed User
I think you will still have a problem as the class name is same same in both files 'anywheresoftware.b4a.objects.NFC' - the linker won't know which one to use, and probably the last one entered will overwrite the previous one.
Yeah this was my thought as when i had NFC and NFCOld, the error would change depending on which one I enabled first
 
Upvote 0

jackdev65

Member
Licensed User
1. REMOVE the files NFC.* from yopur additional libs folder. You can not have two Libs of the same NAME.
Rename the nfc.* files in your ADDITIONAL library folder to nfcnew or something. At least another name than NFC

Edit the NFC.XML inside the internal library folder. Change shortName to NFCold.


B4A_MEablE1imZ.png
Also, "NFCOld" is the NFCV library since it's based on an older version of the NFC library, so I believe this is the one that needs to be in the additional libraries and have its shortname changed correct?
 
Upvote 0

MicroDrie

Well-Known Member
Licensed User
Longtime User
Also, "NFCOld" is the NFCV library since it's based on an older version of the NFC library, so I believe this is the one that needs to be in the additional libraries and have its shortname changed correct?
A few thoughts on my part. First, there is a challenge when you use the same library name for both an internal and an external library. In that case, the IDE must choose the internal library that may be found first, but can also choose to choose an external library to override the internal library.

In addition, to display a help text in the IDE, the IDE uses the corresponding XML doctype file with the same file name with the extension xml. If you give the XML file a different name, you break that relationship. This argues for renaming the jar file and the associated XML Doctype file name to the same filename (NFC and NFCOld).

Finally, renaming a java source file in Eclipse also requires renaming the java class name to prevent an error.

Based on these thoughts, I advice to try the following:
  1. Choose the NFC as the file name for the most commonly used library (probably the new one because that is the way to go in the future).
  2. Rename the old NFC short name if it is NFC to NFCOld.
  3. Rename the library shortname to NFCOld.jar
  4. Rename the Doctype help file to NFCOld.xml.
  5. If necessary, adjust the text to reflect the difference between NFC and NFCOldin the NFCOld.xml file.
Note I use the term filename meaning without the jar or xml extension.
 
Upvote 0

jackdev65

Member
Licensed User
A few thoughts on my part. First, there is a challenge when you use the same library name for both an internal and an external library. In that case, the IDE must choose the internal library that may be found first, but can also choose to choose an external library to override the internal library.

In addition, to display a help text in the IDE, the IDE uses the corresponding XML doctype file with the same file name with the extension xml. If you give the XML file a different name, you break that relationship. This argues for renaming the jar file and the associated XML Doctype file name to the same filename (NFC and NFCOld).

Finally, renaming a java source file in Eclipse also requires renaming the java class name to prevent an error.

Based on these thoughts, I advice to try the following:
  1. Choose the NFC as the file name for the most commonly used library (probably the new one because that is the way to go in the future).
  2. Rename the old NFC short name if it is NFC to NFCOld.
  3. Rename the library shortname to NFCOld.jar
  4. Rename the Doctype help file to NFCOld.xml.
  5. If necessary, adjust the text to reflect the difference between NFC and NFCOldin the NFCOld.xml file.
Note I use the term filename meaning without the jar or xml extension.
Thank you for this,
I believe steps 1-4 are what I've done, I have NFCOld.jar and NFCOld.xml in the AdditionalLibraries folder with the .xml having the shortname "NFCOld"
1717061171037.png

Which is where I was at to start, as it shows that same error
1717061220050.png
Can you confirm if thats steps 1-4 done correctly, and guide me through step 5 as I'm slightly confused what you mean!

Thanks
 
Upvote 0

MicroDrie

Well-Known Member
Licensed User
Longtime User
Can you confirm if thats steps 1-4 done correctly, and guide me through step 5 as I'm slightly confused what you mean!

5. If necessary, adjust the text to reflect the difference between NFC and NFCOldin the NFCOld.xml file.
Well, simply put, you should be aware that this difference:
Private nfc As NFC.NFC
Private nfcold As NFCOld.NFC
is expressed in both XML Doclet files for the distinction when you use both libraries at the same time to prevent the two libraries from being used interchangeably.
 
Upvote 0

jackdev65

Member
Licensed User
Well, simply put, you should be aware that this difference:

is expressed in both XML Doclet files for the distinction when you use both libraries at the same time to prevent the two libraries from being used interchangeably.
I still don't understand, steps 1-4 were what I had done before making this post initially, I'm confused about what else needs doing?

Thanks
 
Upvote 0

MicroDrie

Well-Known Member
Licensed User
Longtime User
I still don't understand, steps 1-4 were what I had done before making this post initially, I'm confused about what else needs doing?

Thanks
For the experts its easy to see why your solution leads to compiler errors. Simply put: if you paint a red car blue on the outside, the inside will still remain red colered. If you then say to someone: use the car with the red colored inside, there are still two equal options. Then there are two and that is one possibility too many.

And when we look inside that blue-painted red car, it turns out that it also has an old engine. Back to the jar, this old jar does not work in the current Android version in the current B4A environment.

All you can do is to adapt the old NFC script to the current internal NFC version.

There is also a chance that old NFC hardware will no longer be supported by Android API 33 in the current new jar and B4A versions.

What I don't quite understand how to help is this comment:

I want to use both libraries as the modified nfc script allows me to access NFCV tag data which i need to add for my existing app.
The internal structure and therefore also the method of calling the jar has changed. We can't help you without the script. Without the script nobody can't help you with this.

You can also send the script to me in a private email so that I can help you with the conversion.
 
Upvote 0
Top