4

I'm writing an application that is compatible with Android 1.6, but I would like to give users running Android 2.2 the option of moving the application installation to their sd card.

How can I compile my application for 1.6, but still allow 2.2 users to install it to their sd?

Cristian
  • 198,401
  • 62
  • 356
  • 264
Kleptine
  • 5,089
  • 16
  • 58
  • 81

2 Answers2

12

In your manifest:

  • In <manifest>, add "android:installLocation="preferExternal"
  • Keep your current uses-sdk as "<uses-sdk android:minSdkVersion="4">"

Then go to Project > Properties > Android (on the left), change the build target to 2.2, and you're all set.

Your project will build using 2.2 (but still only requires 1.6), but devices running 1.6 will simply ignore your new "installLocation" setting in the manifest. Just be careful not to add any 2.2-introduced material in your actual code, since the compiler will no longer catch it.

Andy Zhang
  • 8,285
  • 1
  • 37
  • 24
  • 1
    You can find more info here: http://developer.android.com/guide/appendix/install-location.html under "Backward Compatibility" – Andy Zhang Jul 22 '10 at 21:31
  • 3
    One recommendation: Before you roll out a new version, set the build target version back to 1.6 and do a clean build. If you get any compile errors, you know that you accidentally introduced 2.2-specific features, and your app will crash under 1.6. If everything is fine, switch back to 2.2. – EboMike Oct 25 '10 at 02:52
0

This is not quite as seamless as the developer guide suggests. First, the application does not build when the installLocation is present in the manifest and the build target is set to anything other than 2.2:

error: No resource identifier found for attribute 'installLocation' in 
package 'android'

So in order to test backwards-compatibililty by setting the build target to 1.6, the manifest must be edited as well.

Second, once the build target is set to 2.2, I don't get to pick an emulator with a lower API level for testing. I can still manually start an 1.6 emulator and run the app on it, though, but I am curious if my app will appear on Android Market for 1.6 devices if my build target is 2.2 (even though minSdkVersion=4). I don't have an actual device to test. Can someone confirm that this does not affect the availability on the market?

Lastly, this warning remains:

Attribute minSdkVersion (4) is lower than the project target API level (8)
cdonner
  • 37,019
  • 22
  • 105
  • 153
  • I can confirm, that the availability on the market is not affected. I use the described approach from the official Android developer pages. The market place requirements for my app are displayed as "Android version 1.6. or higher". I was able to discover, download and run the app from the market without problems using a HTC Magic running Android 1.6. – Philipp Jul 12 '11 at 14:29