Titanium JIRA Archive
Appcelerator Community (AC)

[AC-2361] Android: eval doesn't reference properly to functions and variables when compiling for distribution

GitHub Issuen/a
TypeBug
Priorityn/a
StatusClosed
ResolutionCannot Reproduce
Resolution Date2013-04-02T19:01:53.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsTitanium SDK & CLI
Labelstriage
ReporterClaudio Caronia
AssigneeMauro Parra-Miranda
Created2012-09-12T09:37:15.000+0000
Updated2017-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)

Comments

  1. Daniel Sefton 2013-04-02

    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.
  2. Ivan Markovic 2017-10-22

JSON Source