caseydavenport / biermacht

Homebrewer's Companion for Android
Apache License 2.0
23 stars 10 forks source link

Cannot import BeerSmith2 (.bsmx) files #49

Closed KarlR83 closed 8 years ago

KarlR83 commented 8 years ago

I try to use the Import Recipe feature of the Android App, but it always fails.

When I select a .bsmx file from Google drive, it says "Found 0 Recipes". When I try to select a .bsmx file from phone's local storage, the file isn't even available (shown in Phone's Explorer) to select it.

It seems BeerMacht doesn't recognize the .bsmx files at all.

The recipe.bsmx seems to be valid though (see attachment) English Pale Ale.zip .

caseydavenport commented 8 years ago

Thanks for raising this - I'm traveling until the end of next week so likely won't get to investigate until then, but I'll look into it as soon as I'm back.

caseydavenport commented 8 years ago

@KarlR83 - I've tried importing the English Pale Ale recipe you provided and it seems to work for me.

I was able to import from Dropbox, local storage (via Astro) and Google Drive just fine.

Do you know what version of the app you're using? It might also help if you share your phone model and what version of Android is installed so I can try to replicate it.

KarlR83 commented 8 years ago

Strange... I'm using Beermacht 4.5 on Xiaomi NotePro with Android 6.0.1

KarlR83 commented 8 years ago

screenshot_2016-06-05-17-05-39_com android settings

KarlR83 commented 8 years ago

Is there any debugging / logging switch in Beermacht, which I could activate and send you the log files to track the problem down?

KarlR83 commented 8 years ago

Hi Casey. Any progress, or anything I could help to solve the issue?

caseydavenport commented 8 years ago

@KarlR83 - Really sorry... I've been pretty swamped with work things and haven't had a chance to dig into this yet. I do promise I will get to this - hopefully soon.

I'm not at the moment aware of any way to get the necessary logs from your phone from a production APK, it is something I'll have to research - I might be able to send you a debug APK to figure out what is going on.

KarlR83 commented 8 years ago

Sorry, I understand :-)

You could send me a debug APK, I'm able to install 3rd party APKs on my phone.

caseydavenport commented 8 years ago

@KarlR83 - I've hosted a debug APK here: https://github.com/caseydavenport/biermacht/releases/tag/DebugAPK

This should do a couple of things.

1) I've modified it to alert you of any exceptions in the code that parses the XML files, so it should warn you (in some failure circumstances) if it's having trouble parsing the file (this is my guess for the "Found 0 Recipes" case).

2) We should be able to get the logging output from the app using ADB if we need to.

I'm hoping the first point above will be enough to figure out what is going on. Try installing this APK and importing the recipe again from Google Drive.

Another thought might be to try using a BeerXML (.xml) file instead of .bsmx. BeerSmith will export these as well. If one works but the other doesn't it will help me pinpoint where things are going wrong.

KarlR83 commented 8 years ago

screenshot_2016-07-30-11-45-05_com biermacht brews screenshot_2016-07-30-11-45-10_com biermacht brews screenshot_2016-07-30-11-45-15_com biermacht brews screenshot_2016-07-30-11-45-19_com biermacht brews

Thanks a lot!

I installed the debug version and get parse errors, trying to import the .bsmx file from Gdrive. I attached the error message

Will try to import a .xml file later.

caseydavenport commented 8 years ago

OK - I've figured out what is going on! Here's another debug APK if you want to check and make sure it works. I'll be putting the fix into the next release.

https://github.com/caseydavenport/biermacht/releases/tag/DebugAPK


In case you're interested in what the problem was:

https://github.com/caseydavenport/biermacht/blob/master/src/com/biermacht/brews/utils/IngredientHandler.java#L348

The above code tries to determine if a file is a .bsmx or .xml file.

https://github.com/caseydavenport/biermacht/blob/master/src/com/biermacht/brews/frontend/MainActivity.java#L467

The above line generates the title from the file name and the file extension. However it doesn't include the . in between! So, you can somtimes get something like this for .bsmx files (if the filename already includes the extension)

my_recipe.bsmxbsmx

The first link fails to recognize that as a .bsmx file, tries to parse it as a .xml file, and obviously fails.

I've now been able to reproduce this myself. I'm not sure what was going on before / why I wasn't able to reproduce this originally. Either way, those screenshots helped me locate what was going on pretty quickly :)


Thanks a lot for your patience and working with me through this - I've fixed the issue in this PR https://github.com/caseydavenport/biermacht/pull/50/files

KarlR83 commented 8 years ago

I tried your updated debug APK, but it still doesn't work.

When I import from Gdrive, Beermacht crashes. When I try select a local stored file on the phone, it's still not listed (just as in the beginning).

Thanks a lot for your support so far!

caseydavenport commented 8 years ago

Hmm. OK.

I think the local import is because the MIME types for import are set wrong. I've tried relaxing the MIME types to allow import of any file type here.

As for Google Drive crashing, that's less clear to me. When in the import process does it happen (e.g before selecting a file, after selecting a file, after loading the file)? How comfortable are you using adb to get error logs from your phone?

KarlR83 commented 8 years ago

I tried the file from your last answer.

Importing a local stored file: I can finally select it (it shows in the file explorer), but then Brewmacht crashes while it is parsing/importing the file.

Importing a Google drive file: parse error (see pictures) screenshot_2016-07-31-21-19-05_com biermacht brews screenshot_2016-07-31-21-19-12_com biermacht brews screenshot_2016-07-31-21-19-20_com biermacht brews screenshot_2016-07-31-21-19-24_com biermacht brews

Regarding the crash importing from Google drive (https://github.com/caseydavenport/biermacht/releases/tag/DebugAPK), same situation there. I can select the file, then Brewmacht starts working (parsing/importing) and crashes before finishing the import.

I'm not familiar with adb, but I know I can enable debug access to my phone, if necessary. So should be possible to get these logs, maybe with a bit of help from you. Please tell me what/how to do it.

caseydavenport commented 8 years ago

I think getting the logcat output would be useful to see what you're hitting. As far as I can tell from the info I have right now, you shouldn't be hitting that case shown in the screenshots above.

I've updated the APK here to include a bit more debug information. You'll also need to have adb installed.

If you're on a Mac, the first comment here works: http://stackoverflow.com/questions/31374085/installing-adb-on-mac-os-x

Then, connect your phone with Biermacht running over USB, open a terminal and run the following commands:

1) Get the process ID for biermacht (it should output a number if successful)

 export pid=$(adb shell ps | grep com.biermacht.brews | cut -c10-15) && echo $pid

2) Start writing logs to file using adb:

adb logcat -v process | grep $pid > log_output.txt

3) Replicate the failure by importing the .bsmx file.

4) Stop gathering logs by typing ctrl+c in your terminal.

You should then be able to open log_output.txt and see the logs generated by the app.

If you're using Windows, it's probably a similar approach, but I haven't done it myself, so let me know and I can investigate options there.

KarlR83 commented 8 years ago

Since I'm using Windows it took me a while to figure everything out, but finally successful. Please find attached the logfile from Brewmacht crash, trying to import the locally stored .bsmx file log_output.txt

KarlR83 commented 8 years ago

I'm not sure I installed your last debug APK (the one with more debug information) before I created the logfile

So I made another logfile, with your latest APK, you can also check that one log_output2.txt

caseydavenport commented 8 years ago

@KarlR83 - Awesome, thanks a lot for that.

That trace exposes something quite interesting - apparently it seems your installation of Biermacht is picking up a different version of the StringEscapeUtils library used when parsing XML files.

The org.apache.commons v3.3.4 library is packaged with Biermacht, but after some research it appears that apparently some versions of Android come with their own (older) version of that lib, which seems to be preferred by the app and is causing it to crash.

I've tried re-packaging in a way that will make this unambiguous... could you give it a shot?

I've updated the APK at https://github.com/caseydavenport/biermacht/releases/tag/DebugAPK

KarlR83 commented 8 years ago

Now it finally worked, both importing from GDrive or locally stored file. Thanks a lot for your support!

I think my Xiaomi phone (Chinese manufacturer) uses a special customized version of Android (MiUI) That could be the reason for the old version of the lib

caseydavenport commented 8 years ago

Phew! Glad to have figured it out.

I'll cut a new release of Biermacht hopefully tonight or tomorrow that includes it. Thanks a lot for all your help tracking it down.