如何改变 Android 项目的目标构建?

我目前在 Eclipse 中有一个 Android 项目。

我创建它的目标版本是1.5(sdk 3)。

现在我要改变它,使它的 minSdk 为3,targetSdk 为8。

要做到这一点,我认为我必须根据最新的 SDK (2.2)进行构建

要在 Eclipse 中做到这一点,我右键单击我的项目,转到属性,单击 Android 并将项目构建目标更改为 Android 2.2,然后单击 application,然后 OK。

然而,这似乎没有影响,当我再次尝试时,目标构建设置回 Android 1.5。

我错过了什么吗?

163393 次浏览

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)

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" />

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

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.

  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.

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.

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.

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

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" />

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" />

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

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

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.