Closed Robyer closed 7 years ago
Hmm--true. Currently it's set up this way so that preparetests.sh
(or preparetests.cmd
) can be run from the command line to install the training data into a known/standard location and clean up files before running the tests. If Environment.getExternalStorageDirectory()
were used instead, then the install location wouldn't be known prior to runtime and the setup scripts wouldn't be usable as-is.
Do you have a suggestion for how to remove the hard-coded path in a way that also makes it easy to set up a device for testing?
Oh, I see... I googled a bit and found a possible solution: https://android.stackexchange.com/a/14109/199338
So adb shell echo $EXTERNAL_STORAGE
in preparetests.cmd (on Windows it works without escaping), and for linux perhaps adb shell echo \$EXTERNAL_STORAGE
(but I didn't test this). This will give us in my case /sdcard
string.
Then in Java we can use System.getenv("EXTERNAL_STORAGE")
which will give us the same value /sdcard
. Note when using Environment.getExternalStorageDirectory().getAbsolutePath()
I will get /storage/emulated/0
in my case (Samsung Galaxy S7),but I believe it points to the same directory in filesystem as I tried using both in TessBaseAPITest and both worked.
So this works:
static final String TESSBASE_PATH = System.getenv("EXTERNAL_STORAGE") + "/";
I just re-read your second comment and I see that your suggestion differs a little from the change I just pushed. Let me know if that change doesn't work for you.
It works 👍
TessBaseAPITest.java
uses hardcoded path"/sdcard/tesseract/"
instead ofEnvironment.getExternalStorageDirectory()
(or similar) as Lint warns. Why is the warning supressed? In current state everyone have to hardcode their own path when they want to run tests.See https://github.com/rmtheis/tess-two/blob/master/tess-two-test/src/com/googlecode/tesseract/android/test/TessBaseAPITest.java#L50-L51
EDIT: Furthermore, this path is not consistent with your readme for end users, see:
But tests currently uses
<sdcard>/tesseract/tessdata
instead of<sdcard>/tessdata
as readme suggests. It would be good to use same path in tests.