64

I have been building a project and testing it on the Android emulator.

I realized that I set the minSdkVersion to 10. Now, I have a phone to test the program on, but its sdk version is 7.

I tried to go into the manifest file, and change the sdk version to 7, but every time I run the program, it crashes.

How can I rebuild or change the sdk version to a lower number (from 10 to 7), so that I can make sure my app is able to run on older phones?

nbro
  • 12,226
  • 19
  • 85
  • 163
Peter
  • 4,740
  • 22
  • 74
  • 114
  • 2
    look here, update build.gradle and sync project files http://stackoverflow.com/questions/19465049/changing-api-level-android-studio –  Dec 08 '13 at 15:13

9 Answers9

57

In your app/build.gradle file, you can set the minSdkVersion inside defaultConfig.

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
        applicationId "com.name.app"
        minSdkVersion 19    // This over here
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
juil
  • 2,017
  • 3
  • 16
  • 16
44

Set the min SDK version within your project's AndroidManifest.xml file:

<uses-sdk android:minSdkVersion="4"/>

What exactly causes the crash? Iron out all crashes/bugs in minimum version and then test in higher versions.

Kon
  • 25,664
  • 11
  • 56
  • 84
  • 6
    I have done this, but it seems android studio still says minSdk use old version before change the file. – GusDeCooL Dec 07 '13 at 18:08
  • 2
    If you do that you'll have the following error: `The minSdk version should not be declared in the android manifest file. You can move the version from the manifest to the defaultConfig in the build.gradle file`. The good answer is the one of juil – Sébastien B Sep 18 '19 at 12:36
11

Create a new AVD with the AVD Manager and set the Target to API Level 7. Try running your application with that AVD. Additionally, make sure that your min sdk in your Manifest file is at least set to 7.

WindsurferOak
  • 4,681
  • 1
  • 27
  • 36
  • 10
    Why do we need to create a new AVD, why we cannot simply change the manifest file? – nbro Jun 22 '15 at 12:52
9

This is what worked for me:

In the build.gradle file, setting the minSdkVersion under defaultConfig:

enter image description here

Good Luck...

Aakash
  • 14,077
  • 4
  • 77
  • 63
  • I would just add that there are two build.gradle files and the one we are looking for, in a Flutter project resides in android -> app -> build.gradle – mikes Nov 11 '20 at 21:42
4

check it: Android Studio->file->project structure->app->flavors->min sdk version and if you want to run your application on your mobile you have to set min sdk version less than your device sdk(API) you can install any API levels.

A.J
  • 141
  • 1
  • 1
  • 6
3

Set the min SDK version in your project's AndroidManifest.xml file and in the toolbar search for "Sync Projects with Gradle Files" icon. It works for me.

Also look for your project's build.gradle file and update the min sdk version.

3

Open the app/build.gradle file and check the property field compileSdkVersion in the android section. Change it to what you prefer.

If you have imported external libraries into your application (Ex: facebook), then make sure to check facebook/build.gradle also.

spenibus
  • 4,079
  • 11
  • 23
  • 33
3

Delete this line:

<uses-sdk android:targetSdkVersion="..." />

in the file:

AndroidManifest.xml
user_MGU
  • 772
  • 9
  • 10
0

If you use a cordova to build your app, for me the best soluction is change the argument cdvMinSdkVersion=15 to cdvMinSdkVersion=19 in the file platforms\android\gradle.properties

fcdt
  • 2,151
  • 5
  • 9
  • 24