My app has a minSdkVersion of 8. I would like to use a library with a minSdkVersion of 14 on devices that support it and fallback to a different component if not. Theoretically, this might be possible using the new manifest merger, but it looks like there's a special case for minSdkVersion:
Defaults to 1.
The higher priority document's version will be used but importing a library with a more recent version will generate an error.
Is there a way to force gradle to include the library dependency so that I can deal with the SDK version issues?
Thanks to #CommonsWare's suggestion, I found the proper incantation. Everything works fine if I add this line to the AndroidManifest.xml:
<uses-sdk tools:node="replace" />
Related
I've deployed a Nativescript app to Google Play for my beta testers to use. My app is only intended to support Android version 4.4 and above. So I thought setting this in the AndroidManifest would get the job done.
<uses-sdk
android:minSdkVersion="19"
android:targetSdkVersion="__APILEVEL__"/>
Yet once deployed the Play store is still saying that those running Android versions lower than 4.4 can still download the app. What else do I need to do to prevent this?
Follow the thread below where a solution is shown on how to modify your minimum SDK version with app.gradle
https://github.com/NativeScript/android-runtime/issues/575#issuecomment-251584253
Basically as Plamen5kov has shown, you have to do the following:
what you can do is go to app/App_Resources/Android/app.gradle and
change the default configuration to meet your requirements.
android {
defaultConfig {
minSdkVersion 19 ....
Gradle overrides the AndroidManifest.xml that's why you need to change
the configuration in gradle, rather than in the manifest file.
I'm a newbie to Android, and I'm trying to run an existing application.
In the file project.properties I have this line:
target=android-20
While in the manifest file, I have this line:
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="14" />
Shouldn't these 2 directives refer to the same SDK version?
Is there any error in the app I'm trying to run?
Both of the two are different things.
minSDKVersion specifies that the app is supported minimum from which API level.
whereas targetSDKVersion mentions that which build-tool API version to be used to build the project. Both could have any value of Android API level but targetSDKVersion should not be less than minSDKVersion. Eclipse also gives error for this.
You might have noticed: when you use library method for old API than minSDKVersion API, It will raise an error asking to change the minSDKVersion. And the targetSDKVersion you are choosing in manifest file, you should have build-tool of that particular API.
When using the new Android widgets CardView and RecyclerView I've noticed that they require minSdkVersion L. So if your project uses for example minSdkVersion 14, you will get an error like this:
> Manifest merger failed : uses-sdk:minSdkVersion 14 cannot be smaller than version L declared in library com.android.support:cardview-v7:21.0.0-rc1
I know there is a workaround that is telling Gradle to ignore the minSdkVersion of the library and use the one of the project instead.
<uses-sdk tools:node="replace" />
However if the library requires Android L, is it safe to ignore this error and use it anyway with older versions? and why did Google decided to not make them work with pre-L versions? I assume it's because it's not the final version?
All of the APIs Google released at I/O (including CardView and RecyclerView) are currently only intended as previews and should not be used for production applications.
This is Google's method of preventing these libraries from showing up in production applications before they are completed and released.
If you do want to use either of these with earlier versions of Android right now it's really easy. Just add RecyclerViewLib as a dependency in your build.gradle file.
compile 'com.twotoasters.RecyclerViewLib:library:1.0.+#aar'
The author talks about it in his blog post. All code depending on L has been removed so this is safe to use. Good luck!
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).
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