Probably a simple question but I've developed an app that has always been using a build target of 1.5 without issue. However, now I'm adding TextToSpeech which was introduced in 1.6. I've created a TextToSpeech wrapper that encapsulates the TextToSpeech code and I have checks in the activity so that when it does run, it should only work for 1.6 devices and above. But the trick is to get the code to run in Eclipse with a build target of 1.5. When I try to do that, of course, I get the following errors tied to my TextToSpeech wrapper class:
"TextToSpeech cannot be resolved."
I've played around with exporting as jar, creating a library project, etc. but I cannot seem to get those to work. For a library project, it says that dependent projects must have the same or higher API level so it won't work. Some relevant code excerpts:
AndroidManifest.xml
<uses-sdk
android:minSdkVersion="3"
android:targetSdkVersion="8"
/>
activity class
static {
try {
TextToSpeechWrapper.checkAvailable();
androidTextToSpeechAvailable = true;
} catch (Throwable t) {
androidTextToSpeechAvailable = false;
}
}
wrapper class
import java.util.HashMap;
import java.util.Locale;
import android.content.Context;
import android.speech.tts.TextToSpeech;
/*
* A wrapper class for the newer Android text-to-speech library that is only found in
* Android OS 1.6 and above (Donut and above). This is useful so that the app can
* be loaded on pre-Donut devices without breaking the app.
*/
public class TextToSpeechWrapper {
private TextToSpeech mTextToSpeech;
// class initialization fails when this throws an exception
static {
try {
Class.forName("android.speech.tts.TextToSpeech");
} catch (Exception e) {
throw new RuntimeException(e);
}
}
// Some static vars from the text-to-speech class
public static int SUCCESS = TextToSpeech.SUCCESS;
public static int QUEUE_FLUSH = TextToSpeech.QUEUE_FLUSH; <--- Eclipse errors point here cause it does not exist in 1.5.
So my question is how do I make the project use a build target of 1.5 again w/ the emulator so I can test and feel confident my app still works for 1.5 and above?