How to change the minSdk version in Android Studio? - android

I am trying to get a basic hello world program running on my phone, however Android Studio keeps on reverting to minSDK level 20, when I specified 14. Here is the process I am using:
-Start Android Studio 0.8.2
-Select New Project
-Select Minimum SDK as API 14: Android 4.0
-Select Blank Activity
-The new project is now open. My android device, running 4.4.2 API 19 is plugged in.
-Select "Run app"
-The "Choose Device" dialog opens, shows my android device, but shows compatibility as No, minSdk(API 20, L preview)!= deviceSdk(API19)
The following is my build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 'android-L'
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "com.example.victor.myapplications"
minSdkVersion 14
targetSdkVersion 'L'
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
Changing 'compileSdkVersion' to 14 results in an error, "failed to find target android-14".
Any ideas? Thanks!

The "L" Developer Preview is a special snowflake that breaks all the normal rules for version management. :-(
Unless you are an experienced Android developer specifically testing on "L", change compileSdkVersion to something like 19 (note: may require you to download the SDK Platform for API Level 19 from the SDK Manager) and change targetSdkVersion to 19.
Changing 'compileSdkVersion' to 14 results in an error, "failed to find target android-14".
You need to download the API Level 14 "SDK Platform" in the SDK Manager.

try this:
android {
compileSdkVersion 20
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "com.example.victor.myapplications"
minSdkVersion 14
targetSdkVersion 20
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
If the target keep giving to you this problem try putting a lower version like CommonsWare said !

Related

Android Studio is changing my API level from 23 to 26

Thanks for stopping by. I have been working on an app at API 23. Now Android Studio is "upgrading" it to API 26. This is not what I want. I want to keep it at API 23. Everytime I make a new app its 26. Downgrading doesn't work; I get a bunch of errors.
Thanks
You can change it as you like.
1.Click on your project folder > app > build.gradle
An example of build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "25.0.3"
defaultConfig {
applicationId "com.stackoverflow.answer"
minSdkVersion 21
targetSdkVersion 26
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dependencies {
androidTestCompile 'junit:junit:4.12'
compile fileTree(dir: 'libs', include: ['*.jar'])
}
2.Open your Android Studio, and go to Menu.
File >Project Structure. In project Structure window, select app module in the list given on left side.
Select the Flavors tab and under this you will have an option for setting “Min Sdk Version” and for setting “Target Sdk Version”.
Select both the versions and Click OK.
Keep in mind that if you're uploading it to the play store, it's going to have to target 26, soon to be 27. That's probably why AS is trying to update your version.

Failed to load AppCompat ActionBar with unknown error. sdk 28 seems to be cause

This is my gradle file where I make the changes but anything I do with SDK 28 doesn't help me but when I change it to 27. It works. Please help me to make it work with SDK 28. Thank you.
//This is my app gradle(Module:base)
apply plugin: 'com.android.feature'
android {
compileSdkVersion 28 //Change is made here
baseFeature true
defaultConfig {
minSdkVersion 16
targetSdkVersion 28 //Change is made here
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
api 'com.android.support:appcompat-v7:28.0.0-beta01'//Change is made here
api 'com.android.support.constraint:constraint-layout:1.1.2'
application project(':app')
feature project(':project')
}
//If I change the SDK version to 27, it works. I really want to find out how to make it work in SDK version 28
//Thank you for helping
Click Tools > SDK Manager.
In the SDK Platforms tab, select Android P Preview.
In the SDK Tools tab, select Android SDK Build-Tools 28-rc2 (or higher).
Click OK to begin install.
Make sure you have Android Studio 3.1 or higher.

Cannot install platform plugind for android-28 in Android Studio 3.2 preview version

I'm trying to refactor my code to androidX. To do so android asked me to update the compiled version to at lease 28. So I changed my compiled version to compileSdkVersion 28 in bulid.gradle.
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.myapplication"
minSdkVersion 17
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
But once I sync project I'm unable to download the platform plugins and the following error shows up in build window.
Failed to find target with hash string 'android-28' in: /Users/work/Library/Android/sdk
Your compile version should be android-p. They're using the version name now.
compileSdkVersion 'android-P'
And target should be just P
targetSdkVersion 'P'
See here to know how to set up Android P SDK.
Edit:
If your getting an error/warning "minSdkVersion (21) is greater than targetSdkVersion (1)" this is done on purpose, see here.
As Android P is still Preview, the 'P' in the targetSdkVersion will work as a version 1. Once it's out of preview it will be replaced with the usual 28. For now, to fix this you'd need to raise the minSdkVersion to also 'P'.

Android Studio: Can't install app on the Android device

SOLUTION
In build.gradle file, I set both minSdkVersion and targetSdkVersion to 19 (my Android device's API level).
Also, compileSdkVersion's value must be less than your device's level API.
Issue was:
I cannot install my app I developed in Android Studio, in my Android device (LG G3).
When I try to install my app, this window comes.
When I click OK, the log outputs this.
This was my build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 'android-L'
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "*AppID*"
minSdkVersion 15
targetSdkVersion 'L'
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
What I've tried to do:
1. Modify build.gradle to (Changed compileSdkVersion's value to 15):
apply plugin: 'com.android.application'
android {
compileSdkVersion 15
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "*AppID*"
minSdkVersion 15
targetSdkVersion 'L'
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
2. Clean the project: i.imgur.com/lbdeXGe.png.
Take a look at Failure [INSTALL_FAILED_OLDER_SDK] Android-L
Recently there was a post here regarding the L SDK's incompatibility with prior versions of Android. I've been digging in
AOSP repositories for quite a few hours now, and determined that the
tools behave this way because they are designed to treat preview
platforms differently. If you compile against a preview SDK
(android-L), the build tools will lock minSdkVersion and
targetSdkVersion to that same API level. This results in the produced
application being unable to be installed on devices running older
releases of Android, even if your application isn't doing anything
specific to L. To make matters worse, the new support libs (CardView,
RecyclerView, Palette, etc.) are also locked into the L API level,
even though--according to their repository names--they should work on
API level 7 just fine (and they do!).
The error means your device has an Android version that is less than your specified minSdkVersion. Set the minSdkVersion to the device's version. If that's not possible, there's really nothing you can do other than using a newer device.
Edit:
Now seeing userM1433372's answer ... That should be the actual issue. Thought you already tried a different SDK version, but you only changed compileSdkVersion to 15 without changing targetSdkVersion! I would suggest setting both targetSdkVersion and compileSdkVersion to 19 (which is the latest non-preview-version).

INSTALL_FAILED_OLDER_SDK with minSdkVersion lower than device API version

On a brand new install of the latest AndroidStudio running the New Project template with min SDK selection of 15 (ICS) trying to run on a Nexus 5 running API 19, I get the INSTALL_FAILED_OLDER_SDK error with the following output. I have made no changes to the project from what the template has generated, so this would be a clean first run that I would expect to work.
Waiting for device.
Target device: lge-nexus_5-{device id}
Uploading file
local path: /home/{my user name}/AndroidStudioProjects/MyApplication/app/build/outputs/apk/app-debug.apk
remote path: /data/local/tmp/com.example.{my user name}.myapplication
Installing com.example.{my user name}.myapplication
DEVICE SHELL COMMAND: pm install -r "/data/local/tmp/com.example.{my user name}.myapplication"
pkg: /data/local/tmp/com.example.{my user name}.myapplication
Failure [INSTALL_FAILED_OLDER_SDK]
This is the default build.gradle file generated for the app
apply plugin: 'com.android.application'
android {
compileSdkVersion 'android-L'
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "com.example.{my user name}.myapplication"
minSdkVersion 15
targetSdkVersion 'L'
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
Check the doc at http://developer.android.com/preview/setup-sdk.html.
You have to use
minSdkVersion 'L'
and you have to run the app in device with Android-L or an emulator with Android-L.
The build system when compileSdkVersion is 'android-L' or targetSdkVersion is 'L' forces the minSdk to 'L' to prevent apps published with the API in preview.

Categories

Resources