84

I currently have an Android project in Eclipse.

I created it with a target build of 1.5 (sdk 3).

Now I want to change it so that it has a minSdk of 3 and targetSdk of 8.

To do this I see that I must build against the newest SDK (2.2)

To do this in Eclipse I right click on my project, go to properties, click on Android and change the project build target to Android 2.2 and click apply and then ok.

However this appears to have no affect and when I try it again the target build is set back at Android 1.5.

Am I missing a step or something?

Donal Rafferty
  • 19,707
  • 39
  • 114
  • 191

13 Answers13

95

Right click the project and click "Properties". Then select "Android" from the tree on the left. You can then select the target version on the right.

(Note as per the popular comment below, make sure your properties, classpath and project files are writable otherwise it won't work)

James Oravec
  • 19,579
  • 27
  • 94
  • 160
Ryan Conrad
  • 6,870
  • 2
  • 36
  • 36
  • 20
    turns out my properties, classpath and project files were set as unwritable which is why it didnt work, works now, thanks – Donal Rafferty Jul 27 '10 at 13:29
  • 3
    I hit this same problem. Source control caused the files to not be writable and prevented the switch. You don't get any kind of warning or indication there is a problem...it just doesn't switch. If others encounter this, make sure you "check out for edit" or whatever the right action is in your source control library. – Michael Stoner Aug 26 '12 at 15:06
  • Any way to set the DEFAULT option? With multiple APK's its kind of annoying having to set this every time... – MBillau May 14 '13 at 15:21
  • @DonalRafferty how to check if they are writeable or not? and how to make them writeable? – Muhammad Babar Sep 30 '14 at 07:56
  • @Muhammad Babar I was using Visual Source safe which was automatically making the files Read Only. I just unchecked the Read only box on the files, I was using a windows machine at the time. – Donal Rafferty Sep 30 '14 at 10:32
  • In Android Studio: right click the module and click "Open Module Settings". – eldes Oct 04 '16 at 03:04
25
  1. You can change your the Build Target for your project at any time:

    Right-click the project in the Package Explorer, select Properties, select Android and then check the desired Project Target.

  2. Edit the following elements in the AndroidManifest.xml file (it is in your project root directory)

    In this case, that will be:

    <uses-sdk android:minSdkVersion="3" />
    <uses-sdk android:targetSdkVersion="8" />
    

    Save it

  3. Rebuild your project.

    Click the Project on the menu bar, select Clean...

  4. Now, run the project again.

    Right Click Project name, move on Run as, and select Android Application

By the way, reviewing Managing Projects from Eclipse with ADT will be helpful. Especially the part called Creating an Android Project.

Alan Will
  • 251
  • 3
  • 3
  • 5
    Tipp: After going through all this steps, restart your Eclipse. This can do wonders. – cimnine Nov 22 '11 at 23:54
  • Agreed! I couldn't get this working until Eclipse was restarted. – Pedro Mar 16 '12 at 01:01
  • In Android Studio, I had to merge these lines together. Not sure if this is specific to Android studio, or if the manifest format has required the change since this was posted. eg: `` – Eric Farraro Oct 25 '14 at 20:54
  • @Alan Will I'm dense aff but where on earth do u click that 1st point... Package Explorer... I don't see any Properties anywhere! :- ( – Dariusz Nov 09 '20 at 21:41
11

Another way on the command line if you are using ant is to use the android.bat script (Windows) or android script (Mac). It's in $SDK_DIR/tools.

If you say,

android.bat update project --path .  --target "android-8"

it will regenerate your build.xml, AndroidManifest.xml, etc.

Scott C Wilson
  • 19,102
  • 10
  • 61
  • 83
7

There are three ways to resolve this issue.

  1. Right click the project and click "Properties". Then select "Android" from left. You can then select the target version from right side.

  2. Right Click on Project and select "run as" , then a drop down list will be open.
    Select "Run Configuration" from Drop Down list.Then a form will be open , Select "Target" tab from "Form" and also select Android Version Api , On which you want to execute your application, it is a fastest way to check your application on different Target Version.

  3. Edit the following elements in the AndroidManifest.xml file

xml:

<uses-sdk android:minSdkVersion="3" />
<uses-sdk android:targetSdkVersion="8" />
Dan Beaulieu
  • 19,406
  • 19
  • 101
  • 135
Rank
  • 900
  • 9
  • 17
3

Well I agree with Ryan Conrad on how to do it in eclipse, have you ensured you have changed your manifest.xml?

 <uses-sdk android:minSdkVersion="3" />
 <uses-sdk android:targetSdkVersion="8" />
stealthcopter
  • 13,964
  • 13
  • 65
  • 83
3

The file default.properties is by default read only, changing that worked for me.

Andro Selva
  • 53,910
  • 52
  • 193
  • 240
notBanana
  • 157
  • 2
  • 9
3

The problem sometimes occurs when there are errors in the project.

For instance, if your project is configured with a target of 3.2 but the 3.2 libraries are not available, you will not be able to change the version to 4.0!

The usual (perhaps brutal) solution I use is to create a new project with the correct target and copy src, res and manifest into the new project.

Update:

This seems to work:

  1. Change the selected through the build properties as normal
  2. Manually edit project.properties AND default.properties to make sure they both reflect the desired target.
  3. Close the project and re-open it

I always run Android Tools | Fix Project Properties after making any changes to the build target.

Mike Way
  • 41
  • 1
  • 4
2

You should not have multiple "uses-sdk" tags in your file. ref - docs

Use this syntax:
    <uses-sdk android:minSdkVersion="integer"
          android:targetSdkVersion="integer"
          android:maxSdkVersion="integer" />
javaProgrammer
  • 1,185
  • 1
  • 10
  • 11
1

as per 2018, the targetSdkVersion can be set up in your app/build.gradle the following way:

android {
    compileSdkVersion 26
    buildToolsVersion '27.0.3'

    defaultConfig {
       ...
       targetSdkVersion 26
    }
    ...
}

if you choose 26 as SDK target, be sure to follow https://developer.android.com/about/versions/oreo/android-8.0-migration

Piotr Z
  • 864
  • 11
  • 11
1

I had this problem too. What worked for me was to first un-check the previously selected SDK version before checking the new desired version. Then click okay.

Adukra
  • 181
  • 4
1

As Mike way says. Change target BEFORE doing anything in your project that requires a higher target like android:installLocation="auto".

user1164035
  • 1,101
  • 2
  • 7
  • 5
0

right click on project->properties->android->select target name --set target-- click ok

Shubhamhackz
  • 7,333
  • 7
  • 50
  • 71
0

to get sdk 29- android 10:

Click Tools > SDK Manager.

In the SDK Platforms tab, select Android 10 (29).

In the SDK Tools tab, select Android SDK Build-Tools 29 (or higher).

Click OK to begin install.

batsheva
  • 2,175
  • 1
  • 20
  • 32