Given the time needed to develop submarines and the years it took to get the very first ones into a condition considered suitable to be commissioned, as opposed to be suitable for testing but not formally in the navy, the odds of Spain being able to do this in the 1880s is pretty much nil.
A much wealthier and industrialized society...wouldn't be able to do it either.
The first submarine would not enter service until the 20th Century and that first sub, tiny with poor speed and range, miserable conditions and a single torpedo tube, needed an additional 3+ years of work before the US Navy would declare it a navy ship.
You might notice that the Peral submarine was not a success despite several years and generous funding. Go to the link for the sub as the first Wiki link is lacking in details and has some very strange jumps in the material.
Had several been built you would then have a class of submarines which had to be towed or carried to Cuba, no facilities in Cuba to support them, with extremely limited combat ability, too slow to catch any ship in motion and whose existance would certainly be well known.
The Spanish navy was not rotten, except for the antiques in Manila Bay, it was simply woefully outgunned with an American battleship for every Spanish cruiser and the one Spanish battleship undergoing work.
Grey Wolf, the Spanish Army in Cuba made no real effort to resist the Americans so perhaps that was why the Spanish Navy felt the need to make a stand at Cuba instead of raiding operations which would seem far more sensible for a woefully inferior fleet?
As I've mentioned before, had the Spanish massed the 5000 soldiers available in the province where the Americans landed a disaster for the US would have been certain. Indeed, historians have noted that the 300 Spanish actually on the spot could have raked the Americans as they pleased.