I have read other answers in context of "What is minSDKVersion and targetSDKVersion?" on SO and those were good enough for understanding but they talked about eclipse, not that it really matters that much.
Anyway, I wanted to ask in context of Android Studio, that when creating new app, it asks for minSDKVersion only but no targetSDKVersion as it used to do in Eclipse. Why is this? Is it insignificant?
The other thing I wanted to ask is, when I did create a new app infact with minSDKVersion as IceCreamSandwich(4.0.3), the class MyActivity extended from ActionBarActivity and not from Activity. Why is this happening?
Are minSDKVersion and targetSDKVersion equal in this case? and if this is the case, Would I get the base class as Activityif I were to change the targetSDKVersion explicitly to say, API 21?
In Android Studio, everything turns around Gradle.
Your build.gradle file has this in it:
android {
compileSdkVersion 22
buildToolsVersion '22.0.1'
defaultConfig {
applicationId 'your.package.name'
minSdkVersion 14
targetSdkVersion 22 // default is latest
versionCode 1
versionName '1.0.0'
}
}
Here you can see the minSdkVersion and targetSdkVersion.
Nothing is required in the AndroidManifest.xml file anymore, regarding API levels.
Regarding your Activity issue:
ActionBarActivity is a child class of Activity.
ActionBarActivity is given automatically provided as it's the newest support tool available w.r.t. the minSDKVersion. If you simply want to use Activity, just change it in the code and remove unused methods.
Related
everyone!
I'm new to android programming, so simple things sometimes become a problem.
I have my application. It should work on devices with Android 5 and higher.
The question is what is proper strategy of sdkVersion defining?
What I mean.
For example, I need to acheive permision to use bluetooth.
If my target sdkVersion is 7 and minimum sdkVersion is 5 I should ask permission in manifest file and then acheive it in runtime. Like this
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
...
}
But if my target sdkVersion is 5 even Build.VERSION_CODES.M cannot be resolved.
So the question is : what is proper approach to choose sdkVersion? Where can I read about it?
I read here https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#target
but I didn't get what is best practice. So please share your experience.
Read this article from Ian Lake: Picking your compileSdkVersion, minSdkVersion, and targetSdkVersion
compileSdkVersion:
compileSdkVersion is your way to tell Gradle what version of the
Android SDK to compile your app with. Using the new Android SDK is a
requirement to use any of the new APIs added in that level.
minSdkVersion:
If compileSdkVersion sets the newest APIs available to you,
minSdkVersion is the lower bound for your app. The minSdkVersion is
one of the signals the Google Play Store uses to determine which of a
user’s devices an app can be installed on.
targetSdkVersion:
The most interesting of the three, however, is targetSdkVersion.
targetSdkVersion is the main way Android provides forward
compatibility by not applying behavior changes unless the
targetSdkVersion is updated. This allows you to use new APIs (as you
did update your compileSdkVersion right?) prior to working through the
behavior changes.
Ideally, the relationship would look more like this in the steady state:
minSdkVersion (lowest possible) <=
targetSdkVersion == compileSdkVersion (latest SDK)
I suppose you are using Android Studio and build.gradle. If not, I recommend you to get it. All of the following is relevant for Android Studio and gradle build system.
Your main mistake is that SDK version in build.gradle of app module is not the same as Android Version. Here is the list of Platform Codenames, Versions, API Levels. What you need for SDK version is number in API level column of first table.
This is how android section of build.gradle for app targeting Android 5.0 and newer should look like.
android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
applicationId "net.eraga.myobjectives"
minSdkVersion 21
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
Read more about targetSdkVersion, minSdkVersion and compileSdkVersion here.
In this case, your minSdkVersion should be 21 (android 5.0) and targetSdkVersion along with compileSdkVersionshould be 25 (android 7.1).
I created an app with the API 22 and I want to know if is necessary create a new project to make it compatible with the previous versions (for example with the API 19) or if I can do something simpler and efficient
If you're using gradle just set the minSdkVersion to the number you'd like to use:
defaultConfig {
applicationId "com.example.mypackage"
minSdkVersion 16
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
in the app's build.gradle file
There are 2 way,
1) Set your "minSdkVersion" from gradle file
or
2) In Android Studio,
File --> Project Structure --> app (on left menu) --> Flavors
then set "Min Sdk Version"
Please help me regarding developing android app. If I developed that app upon API 21 or 23 then Is it run?
You don't need that version of build tool.
In the build.gradle, set minSdkVersion or targetSdkVersion (or both) to API-17. For your case below is recommended:
defaultConfig {
...
minSdkVersion 17
targetSdkVersion 23
...
}
I'm creating an Android app in Android Studio. When I open the layout editor, I see that gray "popup window" on top of the layout, which says that it
Couldn't resolve resource #style/Widget.Holo.Light.ActionMode.Inverse.
This happens when I change the "rendering version" to API 15 (Android 4.0.3).
It worked a minute ago, but when I switched back to the layout, I just got this error.
Edit: I use the AppCompat library.
The theme is defined like this
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar" />
The app works fine when I run it, but doesn't render correctly (at least it's giving me the error) in the editor.
I would be glad if someone could help me with this. Thanks!
This problem occured to me when updating Android Studio to version 1.1.0 and opening an old project without changing anything.
For me only changing the preview's rendering API to 19 or above makes the message disappear.
Hey I faced the same problem and the solution that i figured out was - In android studio Open the Select Theme Dialog and under the All category select NoTitleBar.OverlayActionModes and press okay.
The problem would be solved. But it can show up into a dark theme.
Make you project API Level newer.
For me,the problem occured when my build.gradle content like this:
compileSdkVersion 16
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.xiaoguang.xx"
minSdkVersion 16
targetSdkVersion 16
versionCode 1
versionName "1.0"
}
After i download the sdk 19 and change build.gradle, the problem was fixed.
compileSdkVersion 19
buildToolsVersion "19.1.0"
defaultConfig {
applicationId "com.xiaoguang.xx"
minSdkVersion 19
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
change preview'api
I am about to release my first app and targeted lollipop when writing it in the hope that the uptake would of been greater by the time I was done. As well all know, it is still awful.
In my build.gradle I have this line:
android {
signingConfigs {
}
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.xxx.xxxx.toolbox"
minSdkVersion 21
targetSdkVersion 21
versionCode 7
versionName "1.15"
}
If I change the min SDK version to 19, the app will try and install on a device running API level 19. It crashes, but does not give me any feedback as to why (I have obviously used some methods from higher APIs). Is there any way to quickly figure out which methods I have used that need to be changed?
thanks,
Matt
If you set minSdkVersion to some version and recompile your application, Lint should automatically mark all instances where you use higher API as errors. That is, unless you annotate it with #TargetApi.
Also, if your application crashes, check LogCat. There will be an exception describing what went wrong and where.