Problem with building .apk (JSON-related)

68 views
Skip to first unread message

Rune Thelen

unread,
Nov 3, 2019, 6:14:19 AM11/3/19
to DroidScript

Hi

Made a comment on the thread with .apk-build issues, but recommended to make separate thread for my issue.

I am building an app to let users input their meals, and to calculate kcal, protein, fat and carbo, and a balance between these.
The user can also enter personal data, and from these the app will calculate daily recommended balance of kcal.
There will also be a day and week menu option.

All data is saved as JSON and when running the app within DroidScript everything workes fine.
However, when building the app with APK builder, the app gives an error about a JSON-file,
that I had during development, but rectified, and now working as it should (within DroidScript that is...).

All JSON-files has been tested within the app; userdata.JSON, food.JSON, meal.JSON, and they work as intended,
data appears as it should, and values/text is correct according to what the files contain.

I have tried several times to make an .apk but same issue. Tried deleting the old APK, of course uninstalling app, before installing new .APK
I have narrowed (probably) the problem,
by copying all code/data from all files into a new project, and when making an .apk in the new project
the same problem appears. By this I am tempted to conclude that there is a difference in how DroidScript
interprets .JSON-data and how APK-builder does, since the app works well within DroidScript.

the meal.JSON-file looks like this (merely a test-file for now):

[{"ID":105,"vekt":35},
{"ID":203,"vekt":31},
{"ID":150,"vekt":69},
{"ID":300,"vekt":90},
{"ID":590,"vekt":120},
{"ID":592,"vekt":250}
]

and all the others files have the same format, and all the .JSON-files is loaded with this function:

function getJSONfil(filnavn) {
     return JSON.parse(app.ReadFile(filnavn));
}

Enclosed also the error message.

Any idea of possible solutions or known issues that might cause this behaviour?

best regards
Rune Thelen, Norway
Screenshot_20191103-121142.jpg
Message has been deleted

Steve Garman

unread,
Nov 3, 2019, 7:58:28 AM11/3/19
to DroidScript
One thing I would look at is the names of the json files.

Files in APKs are more case-sensitive than in the device. Make sure the name in your code is identical to the actual file name.

Steve Garman

unread,
Nov 3, 2019, 9:10:41 AM11/3/19
to DroidScript
The attached spk works in the DroidScript IDE but throws an error in an APK because .JSON is upper-case in the code but lower-case in the file extension.

Because it cannot find the file, app.ReadFile() returns an empty string which JSON.parse() recognises as invalid JSON.

temptest.spk

Rune Thelen

unread,
Nov 4, 2019, 2:24:27 AM11/4/19
to DroidScript
Hi and thanks

Fast response, and it did the trick.
A little slip-up in one of the functions loading a .json and by correcting,
everything worked just fine.
Excellent work, and excellent solution for making apps a breeze.

RT
Reply all
Reply to author
Forward
0 new messages