Android minSdk and dependencies - android

I read that my app will be able to run on the minimum SDK version, 16 in this case:
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.github.dht.screenger"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
...
So what will happen with level 23 dependencies when running on an API 16 device?
Dependencies
compile 'com.android.support:appcompat-v7:23.2.0'
compile 'com.android.support:recyclerview-v7:23.2.0'
....

IT mainly depends on the feature and have you used support library or not, cause in case you have used a feature from the support library that's backward compatible then the library takes care of it else the native behavior kicks in,
Lets take the most common scenario, The status bar
IN API level 16 there is no status bar color tinting but a black status bar is shown but from API 21 on-wards it's there so here as we can see the native behavior of that particular version kicks-in
now lets see the com.android.support:recyclerview-v7:23.2.0
As you can see the v7 specifies that the library is backward compatible till version API version 7( ECLAIR_MR1) so the support library does that for you.
The final case using methods available only in that particular version
of SDK
When this happens the compiler throws an error saying you cant use this since the min supported version does not have this methods.

Related

Flutter project exceeds .dex Method Reference Count limit

Why does a Flutter project exceed 64K method reference in its .dex file?
I am wondering what the cause of this could be:
In a rather small Flutter project I use 13 plugins. Without Multidex, the Android build fails because it vastly exceeds the method reference limit.
Is there any trick (e.g. Gradle related) that would allow to shrink the method reference count because I think that such a project should not exceed the limit?
(if you want further information on why I think that this is odd, please take a look at older revisions of this question)
I had the same problem and the fix for me was increasing the minSdkVersion in the app/build.bradle like this
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
minSdkVersion 21 // change this to 21
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
If you are using minSdkVersion less than 21, you can do the following to enable multidex.
In your app level build.gradle change as follows:
Add multiDexEnabled true to defaultConfig
defaultConfig {
minSdkVersion 15
targetSdkVersion 28
...
multiDexEnabled true
}
Add multidex dependency
dependencies {
...
implementation 'androidx.multidex:multidex:2.0.1'
}
You can refer this for more information.
in your android/app/build file increase the minsdkversion from 16 to 21 under defautConfig.
Some have even increased it to 28 but it worked for me at 21.
Here is the link to the issue on git
Edit: multiDexEnabled: true also works for some under the same defautConfig.
in the build.gradle under the defaultConfig add the multiDexEnabled true
minSdkVersion 16
targetSdkVersion 30
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
multiDexEnabled true
}
Use ProGuard to eliminate unused classes at compile time. This will reduce your method count by a considerable amount.
You will need to adjust the ProGuard rules to work with Flutter like the Flutter documentation explains here.
I successfully migrated the app to androidx using the below link and the second step:
1) Flutter Projects & Android X Migration Issues
2) In your android/app/build file increase the minsdkversion from 16 to 21 under defaultConfig. Some have even increased it to 28 but it worked for me at 21.
There is another solution without multidex or increasing min SDK. But it's need R8, just enable minify on App level build.gradle
buildTypes {
release {
minifyEnabled true
}
debug {
minifyEnabled true
}
}
from github comment
or to run debug without minify github comment
buildTypes {
release {
minifyEnabled true
}
debug {
defaultConfig.minSdkVersion 21
}
}
Option 1: use the multidex Library.
Option 2: increase your min SDK to 21 or higher
Detailed explanation on using Multidex Library:
Versions of the platform prior to Android 5.0 (API level 21) use the Dalvik runtime for executing app code. By default, Dalvik limits apps to single classes.dex bytecode file per APK. In order to get around this limitation, you can add the multidex library to the module-level build.gradle file:
Steps to fixing it: set multiDex enabled to true
defaultConfig {
minSdkVersion 15
targetSdkVersion 28
...
multiDexEnabled true
}
Add multidex dependency:
dependencies {
implementation "androidx.multidex:multidex:2.0.1" }
Detailed explanation on why increasing your min SDK to 21 in your android/app/build.gradle works is:
Android 5.0 (API level 21) and higher uses a runtime called ART which natively supports loading multiple DEX files from APK files. ART performs pre-compilation at app install time which scans for classesN.dex files and compiles them into a single .oat file for execution by the Android device. Therefore if you have your min SDK set to 21 or higher, you do not need the multidex Library.
Here is a more detailed write up about the issue:
https://developer.android.com/studio/build/multidex

Android API level - gradle compiles - will it run?

I changed the API level in my android project for test purposes from 22 down to 7 in the build.gradle file.
Gradle has no problems to build the project and it runs on my (Android 5.1 OS) withouth problems.
Does the successfull build indicates the app would run without problems on lower OS (down to API level 7)? If not - how can I check which API is the lowest appropriate for my application?
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.myapplication"
minSdkVersion 7
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.0'
compile 'com.android.support:design:23.2.0'
}
The Gradle tooling, especially Lint, is nowadays very good to figure out whether or not your minSdkVersion really works for your app and will usually block a release build in the lintVitalRelease task when you use API that is not available on your min SDK level.
And of course, you always could (and should) create an API level 7 emulator and test-drive your app there as well. Even if it does not crash right away, some things might behave weird / different or might plainly be not working or visible at all, because compat API calls you were using have been converted to noops on lower API levels.

compiled dependencies not supported by targetSdkVersion

In my app build.gradle
compileSdkVersion 23
minSdkVersion 16
targetSdkVersion 23
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:recyclerview-v7:23.0.1'
since API 24 cameout, I changed the targetSdkVersion to 24, but then the last 2 dependencies show the squiggly-red-underline (not happy with using lower version than targetSdkVersion), I could not find dependencies libraries that support API 24.
According to my understanding of Jim Mixon post, I did not expect this problem. How can it be fixed?
in my Android SDK Manager window where Packages are listed, under Tools, I have the first line "name:Android SDK Tools, API:"BLANK", Rev.:24.4, Status:Installed). is not that a SDK 24 being installed?
As mentioned by CommonsWare, the API or SDK version 24 is not available yet.
If you want to change your build version (<= 23) and two dependencies, you can follow these steps:
1- click and right-click your project or module. Choose 'Open Module Setting' option.
2- In the list that can be viewed menu, you can your build version and just below the related API.
3- In the tab 'Dependencies' you can click the + button and add a dependency. choose option '1 Library Dependency'.
If your build version is < 23 you can manually add to your .gradle file
example:
android {
compileSdkVersion 19
buildToolsVersion '19.1.0'
defaultConfig {
minSdkVersion 10
targetSdkVersion 19
versionCode 65
versionName "2.4.1"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:support-v4:19.1.0'
}
p.s.Sorry for English. It's not my native language
I hope it can help you =]
since API 24 cameout
There is no API 24 at the present time.
How can it be fixed?
Do not refer to API levels that do not presently exist.

Which version of RenderScript should I be using?

This is my gradle file in AndroidStudio:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion '22.0.1'
defaultConfig {
applicationId "com.apps.foo.bar"
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName "1.0"
//renderscriptTargetApi 21
//renderscriptSupportModeEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.0'
}
Now if you check this link
It says:
We recommend you set this value to the highest available API level
and set renderscriptSupportModeEnabled to true.
What is the highest API Level Available? is it 22? 18? 19? Where can I find out? I know 19 works because I tried it, in another app, I was just wondering which one is hte latest I can use.
You shouldn't be just arbitrarily setting the highest API level. The docs are wrong and I just filed a bug to get that cleaned up internally. You should be setting it to the API level that your app is targeting. If you need to raise it for additional RenderScript functionality, it will be noted in the docs (i.e. this API only shows up in v19 -> set to 19). If you don't think you need much beyond the basic support library and runtime, please try to use 18 in general.

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).

Categories

Resources