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
Related
I have a Motorola Devour phone, which is quite old, and runs android 1.6. I have been trying to write my own apps for it, but I can't run the gradle sync because my minSdkVersion is 4. It comes out with this error:
Manifest merger failed : uses-sdk:minSdkVersion 4 cannot be smaller than version 14 declared in library [com.android.support:animated-vector-drawable:28.0.0] C:\Users\mccra\.gradle\caches\transforms-1\files-1.1\animated-vector-drawable-28.0.0.aar\19bf506067f85ca5d48da2fd39d59695\AndroidManifest.xml as the library might be using APIs not available in 4
Suggestion: use a compatible library with a minSdk of at most 4,
or increase this project's minSdk version to at least 14,
or use tools:overrideLibrary="android.support.graphics.drawable" to force usage (may lead to runtime failures)
I included the tools:overrideLibrary in the android manifest as
<uses-sdk tools:overrideLibrary="android.support.v7.appcompat, android.support.fragment, android.support.graphics.drawable, android.support.coreui, android.support.coreutils, android.support.loader, android.support.v7.viewpager, android.support.coordinatorlayout, android.support.drawerlayout, android.support.slidingpanelayout, android.support.customview, android.support.swiperefreshlayout, android.support.asynclayoutinflater, android.support.compat, androidx.versionedparcelable, android.support.cursoradapter, android.arch.lifecycle, android.support.documentfile, android.support.localbroadcastmanager, android.support.print, android.arch.lifecycle.viewmodel, android.arch.lifecycle.livedata, android.arch.lifecycle.livedata.core, android.arch.core, android.support.interpolator"/>
as it gave an error for every single api. When I run the gradle sync, I keep getting the same errors as before I overrode them. Then I tried to change the minSdkVersion on each library, but there must be a better way to do this.
Again, I am trying to make this app run on Doughnut, which is android 1.6, and API 4.
You need to get rid of all of those dependencies, as none of them will work on Android 1.6.
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.
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).
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" />