Changing API 23 to API 21 - android

I am developing app in API level 23 (Marshmallow) but some methods and libraries are deprecated in API 23 i need to downgrade project to API 21 or API 22. But when i change my API level and build my project it gives error
I have tried all methods all things that are mentioned on this forum but none could helped me..
is give error for some value-23.xml file.. i have changed the name of that file from value-23.xml to value-22.xml but android studio said "FILE usder the build folder are generated and should not be edited"

You have changed your compileSdkVersion below 23, but you are still trying to use a version-23 edition of appcompat-v7. Change your appcompat-v7 statement in the dependencies of your build.gradle file, choosing a version that matches your compileSdkVersion. Or, move your compileSdkVersion back to 23 and address your deprecation issues in some other fashion.

Related

How does Android Studio know about backwards compatibility issues?

I am trying to understand how Android Studio determines if a code is available in a certain API. When using MediaStore.setRequireOriginal, Android Studio warns me that "this call requires API level 29". Does Android Studio check that this code is available in previous Android version sources?
photoContentUri = MediaStore.setRequireOriginal(photoContentUri)
I am trying to understand how it knows this.
The linter just knows all the APIs in all the versions. You don't need to download all the previous Android version sources (I was wondering how Android Studio's Linter knew about older versions when I only had API level 29 and 30 sources downloaded on my machine).
As you can see, lint now has a database of the full Android API such that it knows precisely which version each API call was introduced in.
Lint API Check page
The Short Answer:
It's set by the developer, And Android Studio just compares your minSdkVersion set in build.gradle file with the required api level.
The Longer Answer:
When you get this warning on a method, just CTRL+click on it to go to the source class, and there you will find it annotated #RequiresApi or/and #TargetApi, for example :
class MediaStore{
#RequiresApi(api = 29)
#TargetApi(29)
void setRequiredOriginal(...){}
}
Your build.gradle file:
defaultConfig {
minSdkVersion 23
...
}
Android Studio compares minSdkVersion to #RequiresApi or/and #TargetApi at the time you call the method MediaStore.setRequiredOriginal(...); and warn you if minSdkVersion is less that the recommended api.
Please note that there are differences between #RequiresApi and #TargetApi, sometimes you find them used along with each other but sometimes just one of them.
For more about difference between the two see: https://stackoverflow.com/a/50578783/10005752
There is something in build.gradle of application module like:
defaultConfig {
minSdkVersion 23
targetSdkVersion 30
}
So you can change the "minSdkVersion" to 29, and the warning message disappear ...
And if not:
With android OS version >= 29: your code works normally
With android OS version <29: might be an exception occurs

Android Studio API level error for Android Wear

I am trying to run and test a simple android application using android studio(version 3.0.1) on a smartwatch, I am getting the below error with respect to the gradle sync. (I am creating an new project by selecting the wear with the API level of 22 which is same as smartwatch API level).
Error:Execution failed for task ':app:processDebugManifest'.
Manifest merger failed : uses-sdk:minSdkVersion 22 cannot be smaller than version 23 declared in library [com.android.support:wear:26.1.0] C:\Users\Sai.gradle\caches\transforms-1\files-1.1\wear-26.1.0.aar\5b2a40104c2cc0843c9e44597771b49a\AndroidManifest.xml as the library might be using APIs not available in 22
Suggestion: use a compatible library with a minSdk of at most 22,
or increase this project's minSdk version to at least 23,
or use tools:overrideLibrary="android.support.wear" to force usage (may lead to runtime failures)
I have looked up for this error in most of the stackoverflow post's and they suggested to change the minimum SDK version in the build.GRADLE (app module) file in the defaultConfig section to 23, and the error doesn’t appear when I change the version to 23 as below.
defaultConfig {
applicationId "com.example.sai.wearexample"
minSdkVersion 23
targetSdkVersion 26
versionCode 1
versionName "1.0"
}
But, if I change the minSdkVersion version to 23 then there is the below error while I want to run the application on the smartwatch.
I have looked into many of the answers in the stackoverflow but I am not able to get any of the specific resolutions for this question. I am stuck in between these two errors, any help would be appreciated.
You should not use com.android.support:wear for api <23.
For the views you can add:
provided 'com.google.android.wearable:wearable:2.3.0'
compile 'com.google.android.support:wearable:2.3.0'
And change in your java and xml the code for use the tools of
com.google.android.wearable
instead
com.google.android.support:wearable
For example, use android.support.wearable.view.BoxInsetLayout instead of android.support.wear.widget.BoxInsetLayout.
I hope I have helped.

Can't update the project to Nougat (api 25)

I have an Android Studio project. The target- and compileSdkVersion for it - is 21. I want to change it to 25.
When I do this, some of the classes of the Android standard library become unavailable. For example org.apache.http.client.HttpClient.
here are some screenshots
Android classes before the rise of SDK version. You can see how many classes in org.apache.http.*
And Android classes after the rise of SDK version:
I also looked into the android reference, and saw that there is as little classes for 25 api, and (I was confused) for 21 api also. And I noticed that they are the same as I have after upgrade
Why in the case of 21 api, I have more classes? And how to fix it? Waiting for help. Thanks.
Since Api 23 (Marshmallow - Android 6.0), the Apache HTTP Client has been removed.
To continue using the Apache HTTP APIs, you must first declare the
following compile-time dependency in your build.gradle file:
android {
useLibrary 'org.apache.http.legacy'
}

How to make imported projects use older api level?

I have a relatively old android device that works under api level 15, and I want to make some simple programs for it. Right now I just watch examples. I'm importing them from the sdk/samples/android-15 directory via the import command, they are imported as android-21 projects, then I go to module config and change api level to 15. This seemed to long for me, so I tried to fix it by deleting all sdk except 15. Now it doesn't import at all.
Where I can tell android studio to use sdk 15?
You dont need to change anything in the module configuration.
Go to your build.gradle file and check the next:
compileSdkVersion 21 //the version of the API the app is compiled against
buildToolsVersion "21.1.2"
defaultConfig {
// put here the minimum Api version compatible, in your case 15 or lower
minSdkVersion 15
targetSdkVersion 21
}
dependencies {
//be sure you add the dependencies with the support library
compile 'com.android.support:support-v4:21.0.3'
compile 'com.android.support:appcompat-v7:21.0.3'
}
have you enabled the developer options in your device?
http://developer.android.com/tools/device.html
SDK manager: Check out that you didn't delete the minimun sdk tools required:
http://developer.android.com/sdk/installing/adding-packages.html
You dont need to download all the api version abailable, those are

How to make a gradle android app compatible with above api version

I have an app that works fine on API 19. However, I want it to work well in other API's as well. I'm targeting API 10 and above.
My gradle build looks like this:
android {
compileSdkVersion 18
buildToolsVersion "19.0.1"
defaultConfig {
minSdkVersion 10
targetSdkVersion 18
}
}
But when I run the app on API 10 the AVD manager says compatible: no
How should I change my build so that it is compatible for API 10 and above?
Your gradle config looks correct. Be sure to check your virtual device settings and compare to what you have defined in your manifest file. Also be sure to check any other modules you may have added to the project and their respective gradle and manifest files.

Categories

Resources