Restrict Android Studio's layout editor to a specific API level - android

Is there a way to restrict Android layout editor to generate attributes for a specific API level?
I am dragging and dropping and looking at the generated XML. Though I chose "API level 16" on the preview dropdown, it seems Android Studio still adds attributes like "layout_alignParentStart" which are API Level 17. Is there a way to restrict the elements it adds to API Level 16.
Part of my project's gradle configuration:
android {
compileSdkVersion 23
buildToolsVersion "19.1.0"
defaultConfig {
applicationId "com.github.dht.holodeck"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
...

Related

Which compileSdkVersion should I use in my android project?

I'm using latest dependencies in my project. My minSdkVersion is set as 15 and targetSdkVersion is 26. Which build tools and compileSdkVersion should I use so that the app can be run even in Adnroid 5.
Here are the details-
compileSdkVersion 28
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "com.app.shoppingbull"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
}
Will these work fine in all devices or I have to reduce the CompileSdkVersion?
Always follow this,
minSdkVersion <= targetSdkVersion <= compileSdkVersion
Because, when you develop app always target the latest SDK so that you provide the latest features of Google to your user.
According to source.android.com if you want to make your App can be run in Adnroid 5 and newer, you should set the minSdkVersion to 21
tip: don't make your minSdkVersion lower than 21
Your application will work in the range of minSdkVersion and targetSdkVersion api level.
You should target your app to the latest version of Android SDK version (see SDK Platform release notes) to make sure you've covered all the Android version. It also force you to check if your code is working correctly with the latest version.
So, change your app build.gradle to something like this:
compileSdkVersion 28
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "com.app.shoppingbull"
minSdkVersion 15
targetSdkVersion 28 // latest stdk
versionCode 1
versionName "1.0"
Ideally, your targetSdkVersion and compileSdkVersion should be the same, and the latest. That's 28 at the current time of writing.
minSdkVersion dictates the minimum version your app will support, so having a compile/target of 28 will still let you run on 15.

Compiling for multiple sdk versions

I have installed SDK 16 (android 4.1), 20 (android 4.4) and 27 (android 8.1) and the code is configured with the following specs
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
applicationId "com.test.android"
minSdkVersion 16
targetSdkVersion 25
versionCode 25
versionName "2.6.7"
vectorDrawables.useSupportLibrary = true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
I want to make sure that the app is fine when installing on an android 4.1. Is that enough to modify compileSdkVersion to 16? Or I have to change buildToolsVersion accordingly?
target and compile level should be the highest possible and you must do so as Google will happen to reject low targets in the future.
Incompatible code will be noted in the IDE as red warnings as you develop. Usually with such a warning as: "Code XX need a newer version (22) and minSdk is 16"
Those errors make your app incompatible for older for versions.

Minimum Sdk support doesn't work for my app. How to resolve this?

I've just developed an app. I set API23 while creating project. Now I changed Min Sdk version to API 16 via File>Project Structure > app>flavors. But app won't run other than API 23 (Marshmallows).... What do I do now??
Did you change the minSdk to 16 in the build.gradle?
Try to add minSdkVersion to 16 in your app>build.gradle file:
android {
defaultConfig {
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
}

How to make android app compatible with lower versions from 6.0 [duplicate]

This question already has answers here:
How can I make sure my Android Application will run in lower and higher versions?
(3 answers)
Closed 6 years ago.
I am using api 23 and my app doesn't work on lower versions. Please suggest any solution for creating compatibility with lower versions in android studio.
In build.gradle
Change minSdkVersion to the version you want it to work.
example
defaultConfig {
applicationId "com.example.myname.myprj"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
You can set the minimum version of API on which you want to run your application in your app module's build.gradle file right under defaultConfig section
defaultConfig {
applicationId "com.example.me"
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0"
multiDexEnabled true
}
Check it out, maybe right now it may be 23 or something, This minSdkVersion decides the minimum number above which application can run.

How to set android target level 21

I recently finished developing my app. and I want to change the target API level of the app to 21. Should I change it to 21 or leave it at 19?
Also what changes would I have to make to the gradle file to make the target set to 21?
Thanks
Go to the module's build.gradle file (NOT the one for the project) and replace 19 with 21. It should look similar to below
compileSdkVersion 21
buildToolsVersion '21.1.2'
defaultConfig {
minSdkVersion 8
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
Also change this in the manifest
<uses-sdk android:targetSdkVersion="21"></uses-sdk>

Categories

Resources