So how do we detect the Android SDK version so that the AndCoooper build tool can be used if the SDK is updated? Goolge/OHA through the SDK provide us with a ANT target property located in default.properties that is generated by the SDK. Normally, ANT does not support conidiotnal logic to hook into this but if you use a differnet optional task library such as ANTXtras you can integrate with this target property to determine not only the SDK version by adjust the classpaths for the tools and apis such as:

<!-- SDK Version setup -->
		<emit message="target: ${target}">
		<domatch property="target">
			<equals value="android-6">
<property name="android.sdk.version" value="android-3.0">
			</property>
			<equals value="android-5">
<property name="android.sdk.version" value="android-2.5">
			</property>
			<equals value="android-4">
<property name="android.sdk.version" value="android-2.0">
			</property>
			<equals value="android-3">
<property name="android.sdk.version" value="android-1.5">
			</property>
			<equals value="android-2">
<property name="android.sdk.version" value="android-1.1">
			</property>
			<!-- 1.0 is no longer supported in SDKs and thus not needed -->
		</equals>
		<emit message="android.sdk.version: ${android.sdk.version}">
		<!-- Set aidl framework location based on android.sdk.version value  -->
<property name="android.aild" value="${sdk.location}/platforms/${android.sdk.version}/framework.aidl">
<property name="android.jar" value="${sdk.location}/platforms/${android.sdk.version}/android.jar">
        <domatch property="mapapi">
		    <equals value="yes">
				<domatch property="oem">
					<equals value="no">
<path id="sdk.apis.classpath">
<pathelement path="${sdk.location}/platforms/${android.sdk.version}/android.jar">
<pathelement path="${sdk.location}/add-ons/google_apis-3/lib/maps.jar">
						</pathelement>
<property name="android.target.classpath" value="sdk.apis.classpath">
					</property>
					<equals value="yes">
<path id="sdk.apis.classpath">
<pathelement path="${sdk.location}/platforms/${android.sdk.version}/android.jar">
<pathelement path="${sdk.location}/add-ons/google_apis-3/lib/maps.jar">
<pathelement path="${sdk.location}/add-ons/${oem-vend-add-name}/${oem-vend-add-jarname}.jar">
						</pathelement>
<property name="android.target.classpath" value="sdk.apis.classpath">
					</property>
				</pathelement>
			</pathelement>
			<equals value="no">
				<domatch property="oem">
					<equals value="no">
<path id="sdk.apis.classpath">
<pathelement path="${sdk.location}/platforms/${android.sdk.version}/android.jar">
							</pathelement>
<property name="android.target.classpath" value="sdk.apis.classpath">

						</property>
					    <equals value="yes">
<path id="sdk.apis.classpath">
<pathelement path="${sdk.location}/platforms/${android.sdk.version/android.jar">
<pathelement path="${sdk.location}/add-ons/${oem-vend-add-name}/${oem-vend-add-jarname}.jar">
					    	</pathelement>
<property name="android.target.classpath" value="sdk.apis.classpath">

						</property>

					</pathelement>

				</path>

			</equals>
			<emit message="android.target.classpath set to:${android.target.classpath}">
<property name="sdk-location" value="${sdk.location}">

I also included some alpha code to integrate with OEM add-ons.

Reblog this post [with Zemanta]
Advertisements
Comments
  1. You'reSlightlyOffThere says:

    Android 2.0.1 was API Level 6, 2.0 is 5, 1.6 is 4, 1.5 is 3.

    2.5 is likely gonna be API Level 7 if there is indeed going to be a 2.5.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s