How to upgrade project targetSdk from 19 to 23 - android

Currently I am using target 19 (Android 4.4) and i have attached support library v4 in jar. I want to upgrade targetSdk to API 23 to handle Runtime Permissions, hovewer there is no clear explonation in web how to do it, and changing targetSdk in Manifest and gradle isn't enough because classes responsible for runtime permission from API 23 are not found.. could you tell me step by step what should i do ?
And second one : should i use android-support v4 or v7 or other version ? what you would advice ?

support library v4 in jar
Why jar and not compile ... in build.gradle?
hovewer there is no clear explonation in web how to do it
There tons of posts and plenty of libs that can help. Just google for it.
changing targetSdk in Manifest and gradle isn't enough because classes responsible for runtime permission from API 23 are not found
You need to change build SDK to API 23 to compile that code.
should i use android-support v4 or v7 or other version
Runtime Permissions are not related to support library. Leave it as is.

Related

Androidx min sdk

What is androidx min sdk? I just migrated to androidx and i need to support minsdk 14. But my build fails indicating that androidx.browser:browser:1.0.0 has minsdk 15.
I can't find it in release notes or anywhere else
androidx.browser:browser:1.0.0 requires the minSdk = 15 (see) in order to function properly, so generally theres no way to support minSdk = 14 while still using androidx.browser:browser:1.0.0.
So basically you have these options:
a. Set minSdkVersion to 15 in app level build.gradle file(and stop supporting minSdkVersion 14)
However if u 'must' have to support minSdkVersion 14 :
b. You can add this line in AndroidManifest.xml file just before application tag:
<uses-sdk tools:overrideLibrary="androidx.browser"/>
this will ensure the project will run properly in most cases but it might lead to run time crashes in few occasions.If you are not really using some feature of the class that absolutely requires sdkVersion 15 then u might just get lucky.
c. Look for alternative classes that can do similar behaviour with minSdkVersion 14 (this might be extremely unlikely)
d. You can consider reverting back to android support libraries instead of androidx. Since, android support libraries will continue to stay around in the google's maven repo for a while.
As stated here:
Starting with Support Library release 26.0.0 (July 2017), the minimum supported API level across most support libraries has increased to Android 4.0 (API level 14) for most library packages.
AndroidX has started with the support library for API Level 28, so minSdk 14 will be the requirement.
For your artifact, the current stable version requires minSdk 15 and the current latest alpha release (1.2.0-alpha09) requires minSdk 16.
AndroidX browser is afaik a replacement / androidX version of Chrome Custom Tabs which had required minSdk 16, maybe this explains the sdk requirement.
By the way you can find the release notes here.

Android support libraries, compile SDK version and minimum SDK version

I have some general questions about the use of support libraries but I can't find good resources to answer them.
Context :
The app I'm working on has a minimum SDK target set to 9. I'm working with support libraries v4 and v7 that I import with gradle using
compile 'com.android.support:support-v4:22.2.1'
compile 'com.android.support:appcompat-v7:22.2.1'
I also declare the version of sdk to compile against and the minimum SDK version with
minSdkVersion 9
compileSdkVersion 22
Now this will compile and build an apk without error. But when I change the compileSDKVersion to 19, I will get a lot of errors such as
Error:(2) Error retrieving parent for item: No resource found that
matches the given name 'android:TextAppearance.Material.Inverse'.
telling me that the SDK I'm compiling with does not contain some resources used by the compatibility libraries, I should instead use previous compatibility libraries.
Questions:
What is the minimum SDK version I can compile against using both v4 and v7 (or what is the minimal SDK version supported by both v4 and v7) ? Is there a way to see all the versions available in the Android Support Repository ?
Is it risky to set the minimum SDK version to 9 and the compileSDKVersion to 22 and use elements provided by the Support library targetting API 22? I mean: may I get runtime exception due to missing classes/resources ?
Is there a way to configure Gradle to show some potential incompatibilities ? I know sometimes I get a compiling error when using methods present in higher API than the minimum one. But does it generalize to xml as well (such as themes or resources) ?
I know that I get compiling errors when a (support) library references a resource that is not present in the compiled SDK. Is there a way to get similar warnings/errors for the minimum SDK as well ?
Sorry if the questions are too vague, let me know if you need some precisions ! If you know interesting resources that might answer part of a question, don't hesitate to share here ;)
Error:(2) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Inverse'.
It happens because the support libraries v22 require API 22.
You can't compile with API 19.
What is the minimum SDK version I can compile against using both v4 and v7 (or what is the minimal SDK version supported by both v4 and v7)
Usually the minSdk is in the name of the library.
It is api4 for the v4 and api7 for the appcompat.
Is there a way to see all the versions available in the Android Support Repository ?
You can check it inside the folder androidsdk\extras\android\m2repository\com\android\support opening the aar file for example.
Is it risky to set the minimum SDK version to 9 and the compileSDKVersion to 22 and use elements provided by the Support library targetting API 22? I mean: may I get runtime exception due to missing classes/resources ?
No if you are using the support libraries v22.
I know that I get compiling errors when a (support) library references a resource that is not present in the compiled SDK. Is there a way to get similar warnings/errors for the minimum SDK as well ?
No for my experience.
There is a general rule.
The library major version number is the minimun compile sdk version.
It means:
support libraries v21.x.x -> requires API 21
support libraries v22.x.x -> requires API 22
support libraries v23.x.x -> requires API 23

How can I download an old version of the Android support library?

I'm targeting Android 19 (because that's what my phone is running). I want to add a notification with buttons; it seems the right approach is to use appcompat-v7.app.NotificationCompat.
However, when I add appcompat-v7 from the Android Support repository revision 22.2 (via a build.gradle dependency), it includes a file app/build/intermediates/exploded-aar/com.android.support/appcompat-v7/22.2.0/res/values-v21/values-v21.xml that doesn't compile because it assumes the target is 21+.
I tried deleting that file, but it gets regenerated.
There doesn't seem to be a way to exclude a file from the build.
So, I need to get an older version of the support library or repository, that doesn't include 21 stuff.
I guess I could import all the sources directly (and leave out the v21 stuff), rather than thru the dependency? I'm not clear where to start with that.
I can use the SDK manager to get older versions of the SDK, but it only offers the latest version of the support library.
to directly answer your question it's all that one line on gradle:
compile 'com.android.support:appcompat-v7:22.2.0'
That last part is the version you're getting. 22.2.0 on the example above.
and on this link you can check the revisions numbers:
https://developer.android.com/tools/support-library/index.html#revisions
But you have a fundamentally wrong approach to your issue. You don't have to target the API for the device you have with you. You can easily and safely target the latest API, use the latest AppCompat features and bug fixes.
Lint will give you a warning every time you try to use a feature that is not from your minimumApi, regardless of the targetAPI
In your gradle build file change the dependency to be the 19 version (the version of the library should match the sdk you are compiling with):
dependencies {
compile 'com.android.support:appcompat-v7:19.1.+'
...
}
Edit: If v19 of the support lib doesn't have NotificationCompat, then you can't use that unless you compile against a later SDK. You can't include a support library with a higher version than your compiled SDK - that's the issue you are running into.
In this case change:
android {
compileSdkVersion 22
...
}
and leave the dependency set to the 22 version of the appcompat support lib

Can I use Widgets from support library of Android L Preview in current Android Version?

I am trying to use RecyclerView & CardView in existing Android version. They said it is in support library. So, I should be able to use those with put "compileSdkVersion" to "Android-L". Right ?
I am trying to use those widgets without Android L Preview device or emulator.I have checked other questions on this matter. But, seems they all are trying Android-L with Android-L version.
Here is my dependencies.
compile 'com.android.support:support-v4:13.0.+'
compile 'com.android.support:recyclerview-v7:+'
Here is my target config
minSdkVersion 15
targetSdkVersion 20
Thanks in advance for any idea.
I just found the solution.
The reason why I can't build the App with RecyclerView & CardView while the targetSdkVersion and minSdkVersion is not "Android-L" is because internally Google designed to treat the preview version of OS differently comparing with original releases.
When I compile the App which contains the components from Android-L, the build tools locked minSdkVersion and targetSdkVersion to same level. The new supports libraries (RecyclerView, CardView, Palette, etc) are also locked into the L API level.
This behaviour is only happening on this Android-L preview release.
The fix for it is to put the following in AndroidManifest.xml.I didn't need to change anything on my gradle script.
<uses-sdk
tools:node="replace" />
Since version 0.11 of Android Gradle Plugin, it turned on a new Manifest Merger by default. It allows us to do some niffy stuffs. This specific configuration tells the manifest processor to replace any attributes from uses-sdk nodes in lower-priority manifest (such as library manifest in this case) with this attributes.
Since Gradle also inserts minSdkVersion and targetSdkVersion from your build.gradle into this uses-sdk node, that's all we really need to add.
Check here for more information related to this issue.
Check here for the info related to Manifest Merger.
The best solution is RecyclerViewLib. The support library has been pulled into a repo and published on maven central. It'll be safe even after L is released as all L dependent code has been removed. The author explains it here in his blog post.
To use it in your project just add the following line in your build.gradle dependencies:
compile 'com.twotoasters.RecyclerViewLib:library:1.0.+#aar'
Good luck!
No you must set targetSdkVersion above 7. You can use android support library v7 with project that support android above 7 api level.
And one more. Android L has api level 'android-L', not 20. Under the hood it has api level 21 (20 is 4.4W, KitKat for wearables).

Set merge strategy on AndoridManifest when using gradle and library projects

I have a gradle project that uses a library with a minSdkVersion set to api level 11. My application has a minSdkVersion of 9. When compiling I get the following error.
Main manifest has <uses-sdk android:minSdkVersion='9'> but library uses minSdkVersion='11'
I have seen a similar question titled manifest-merging-failed-android-studio but the solution was to change the library to have the same minSdk version. If you dont have control over the library that isnt possible.
The library is only used in situations where the minSdkVersion is higher than 11 so actual use isnt an issue.
Is there anyway to get the advantages manifest merging and let the library have a higher minSdk than your main project?
Workarounds that I have thought of but havent found a way to do.
Set priority if manifests conflict
Ignore minsdk for library projects
Remove minSdk from arr before merging starts

Categories

Resources