Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-17156] Supporting per user configuration for build.properties for Android modules

GitHub Issuen/a
TypeImprovement
PriorityMedium
StatusOpen
ResolutionUnresolved
Affected Version/sRelease 3.2.3
Fix Version/sn/a
Componentsn/a
Labelsandroid, ant, cb-tooling, module_build
ReporterKevin Frugier
AssigneeUnknown
Created2014-06-06T21:05:05.000+0000
Updated2018-02-28T20:03:52.000+0000

Description

In Titanium 3.2.3 GA, it's impossible to work as a team on the development of modules since the paths in build.properties are hardcoded. The only solution is to have all the team members store the SDKs in the same location but it becomes quite tricky when some are on OSX and some on Windows.

Step 1 : jar files

The jar files are inserted in the .classpath of the module with their absolute path. It's a trivial task to change them to use Classpath variables that each user can set in Preferences > Java > Build Path > Classpath Variables No problem here and nothing needs to be changed, this manual step doesn't need to be automated.

Step 2 : build.properties

At first glance it looks like this file is used as part of the ant build so we are tempted to do like before and set our custom properties in Preferences > Ant > Runtime > Properties. The variables that need to be defined: * ANDROID_SDK_ROOT (parent folder of platforms & add-ons) * android.ndk * TITANIUM_MOBILE_PATH (xxx\mobilesdk\win32\3.2.3.GA for instance) Then we change build.properties as such (for an android module):
titanium.platform=${TITANIUM_MOBILE_PATH}/android
android.platform=${ANDROID_SDK_ROOT}/platforms/android-10
google.apis=${ANDROID_SDK_ROOT}/add-ons/addon-google_apis-google-10
Now everything inside Ant looks fine except when it comes to the *docgen* target which can't decipher the android.platform. We wouldn't expect it to even have to read the file since it's an Ant file. However we find this ugly part in module/builder.py:
build_properties = read_properties(open(os.path.join(project_dir, 'build.properties')))
android_sdk_path = os.path.dirname(os.path.dirname(build_properties['android.platform']))
Python trying to read an Ant file seems to be an ugly hack. Instead I suggest doing the following:

1. Changing in module/android/build.xml the macro titanium as such:

	<macrodef name="titanium">
		<attribute name="command"/>
		<element name="args" implicit="true" optional="true"/>
		<sequential>
			<python file="${titanium.py}">
				<env key="android.platform" file="${android.platform}"/>
				<arg value="@{command}"/>
				<args/>
			</python>
		</sequential>
	</macrodef>
Doing so, we inject in the environment of the python execution the proper variable expanded by Ant.

2. Then, we change builder.py as such:

	if is_android(platform):
		if 'android.platform' in os.environ:
			android_sdk_path = os.path.dirname(os.path.dirname(os.environ['android.platform']))
		else:
			build_properties = read_properties(open(os.path.join(project_dir, 'build.properties')))
			android_sdk_path = os.path.dirname(os.path.dirname(build_properties['android.platform']))
		android_sdk = AndroidSDK(android_sdk_path)
I left the old code because I don't want to risk side effects but at least when Ant has properly set android.platform in the env of python before calling the titanium script, we make use of it, reducing the need to manually read a file we shouldn't even be looking into. Those slight changes allow manual tweeking of the module project (for those interested) so that it can be worked on by users having stuff on different locations. (A proper mention of this possibility would be nice on the wiki as well if those changes are accepted).

Attachments

FileDateSize
build.xml2014-06-06T21:05:05.000+000017650
builder.py2014-06-06T21:05:05.000+00008162

Comments

  1. Ritu Agrawal 2014-06-13

    [~kayl] Great writeup. Much appreciated. Moving this improvement request to engineering for further evaluation and prioritization.

JSON Source