[AC-2361] Android: eval doesn't reference properly to functions and variables when compiling for distribution
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | n/a |
Status | Closed |
Resolution | Cannot Reproduce |
Resolution Date | 2013-04-02T19:01:53.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | Titanium SDK & CLI |
Labels | triage |
Reporter | Claudio Caronia |
Assignee | Mauro Parra-Miranda |
Created | 2012-09-12T09:37:15.000+0000 |
Updated | 2017-10-22T15:49:31.000+0000 |
Description
When developing, eval recognizes properly functions and variables declared in its same namespace, both on emulator and on device (I tried on different devices with Android 2.3.3, 3.2 and 4.0, and it always worked installing from Titanium Studio).
When compiling for distribution and installing on a device it gives a Runtime Error that reports a variable (involved in an eval function... but this is not specified in the error) is undefined.
Follows a trivial example:
var win = Ti.UI.createWindow({
backgroundColor : "#FFF"
});
var func_a = function(p) {
return ++p;
}
var func_b = function(p) {
return --p;
}
var param = 10;
if (param > 5) {
var f = "b";
} else {
var f = "a";
}
var result = eval("func_" + f + "(param)");
alert(f + ": " + result);
win.open();
This would work correctly when running on the emulator or on a device installing from Titanium Studio, but would give the following error when using the app after compiling for distribution:
*_Runtime Error_*
*Location:*
[1,1] undefined
*Message:*
Uncaught ReferenceError: func_b is not defined
*Source:*
func_b(param)
Cannot reproduce with Ti SDK 3.0.2 GA with Samsung Galaxy S2 Android 2.3.6. I installed to the device through studio in development mode, worked fine. I uninstalled the app. I then packaged the app for distribution, installed with "adb install", ran it, and it still worked fine.