[TIMOB-23933] Hyperloop - Android: JS Wrappers not being generated for org.json .JAR
| GitHub Issue | n/a |
| Type | Bug |
| Priority | Critical |
| Status | Closed |
| Resolution | Fixed |
| Resolution Date | 2018-01-31T19:45:26.000+0000 |
| Affected Version/s | n/a |
| Fix Version/s | Hyperloop 3.0.2 |
| Components | Hyperloop |
| Labels | android, hyperloop, json |
| Reporter | Rodolfo Perottoni |
| Assignee | Jan Vennemann |
| Created | 2016-09-16T00:47:18.000+0000 |
| Updated | 2018-02-05T16:53:27.000+0000 |
Description
I'm trying to import the lib *org.json* into a Hyperloop project by placing it inside *app/platform/android*. The lib is contained inside a *jar* file.
I'm building my project and somehow the JS wrappers for this lib are not being generated.
At first I thought jars were not supported, but then I saw that the Hyperloop examples project is using a *.jar* (volley.jar) without any problems.
I've attached the .jar with the mentioned lib so you can try and reproduce the same error.
Attachments
| File | Date | Size |
| json.jar | 2016-09-21T04:01:09.000+0000 | 84697 |
We cannot work with this ticket at this moment. Please provide: - full trace-log - reproducible example-code - related jar-file
Hey Hans. Sorry for the bad description. I must've had a bad day when I wrote this ticket and didn't notice how poorly described it was. * Full trace log is not necessary in this case - there is no error. * Jar file is attached. Example will be provided in the next comment.
var OAuth = require('io.oauth.OAuth'), OAuthCallback = require('io.oauth.OAuthCallback'), Activity = require('android.app.Activity'), OAuthJSONCallback = require('io.oauth.http.OAuthJSONCallback'), callbackOauth, oauth; $.getView().activity.onResume = function() { oauth = new Activity($.getView().activity); oauth.initialize('BOYep66tMyWO46oe5Q7B8l9odaQ'); callbackOauth = new OAuthCallback({ onFinished: function(data) { if (data.status == "error") { alert('oops'); } else { // Retrieves the user informations var callback = OAuthJSONCallback.extend({ onFinished: function(me) { Ti.API.error(me); }, onError: function(message) { Ti.API.error(message); } }); data.me(new callback()); } } }); oauth.popup("google", callbackOauth); }It fails also with SDK 6.0.0 and Hyperloop 2.0. Requiring
does not generate the proper files('org.json.JSONObject')[~gmathews] I just noticed that we have [this line](https://github.com/garymathews/hyperloop.next/blob/c704f700041b3ea665188c86cf681774320e67d7/android/plugins/hyperloop/hooks/android/metabase/metabase.js#L75) in our metabase. Could that be something hardcoded that prevents us from adding the
json.jarmanually?Hi, for me, replacing line 66 in JavaMetabaseGenerator.java with this:
does the trick and the bindings for json.jar are generated.if (((filename.endsWith("android.jar")/* && whitelist.matcher(entry).find()*/) || true)/* && !blacklist.matcher(entry).find() */&& isClass.matcher(entry).find())PR: https://github.com/appcelerator/hyperloop.next/pull/268
[~lchoudhary], follow these steps to validate this ticket:
Place the attached
json.jarunderplatform/androidAdd the following code to use the JSON library:
var JSONObject = require('org.json.JSONObject'); var data = new JSONObject(); data.put('foo', 'bar'); data.put('solution', 42); console.log('JSON string: ' + data.toString());Run the app
*Expected behavior* The build succeeds and the app starts without any errors. The following string should be printed to the logs:[INFO] JSON string: {"foo":"bar","solution":42}Verified the fix with hyperloop 3.0.2. Closing. Studio Ver: 5.0.0.201712081732 SDK Ver: 7.0.2.v20180201155017 OS Ver: 10.13.2 Xcode Ver: Xcode 9.2 Appc NPM: 4.2.11 Appc CLI: 7.0.2-master.7 Daemon Ver: 1.0.1 Ti CLI Ver: 5.0.14 Alloy Ver: 1.10.12 Node Ver: 8.9.1 NPM Ver: 5.5.1 Java Ver: 1.8.0_101 Devices: ⇨ google Nexus 5 --- Android 6.0.1 ⇨ google Pixel --- Android 7.1.1