3

We are maintaining an Android Library. Lately we upgraded gradle, compileSdkVersion and support library versions. (only using com.android.support:design). Also we upgraded gcm-play-services The library is published to Artifactory with its dependencies also in a pom file. This upgrade works perfectly on projects with upto-date build tools and support libraries. However we are facing an issue with outdated projects that uses our library. Here is the versions of library.

gradle android plugin -> 3.2.1
compileSdkVersion -> 28
targetSdkVersion -> 28
support library version -> 28.0.0

Here is the versions of project

compileSdkVersion -> 26
targetSdkVersion 26
support library version -> 26.0.1

and client support library dependencies

implementation 'com.android.support:cardview-v7:' + androidSupportV
implementation 'com.android.support:recyclerview-v7:' + androidSupportV
implementation 'com.android.support:appcompat-v7:' + androidSupportV
implementation 'com.android.support:design:' + androidSupportV
implementation 'com.android.support:support-v4:' + androidSupportV
implementation 'com.android.support:support-annotations:28.0.0'

after trying to build the project with new library, build fails with this log.

AGPBI: {"kind":"error","text":"error: resource android:attr/dialogCornerRadius not found.","sources":[{"file":"/Users/umutyusuf/.gradle/caches/transforms-1/files-1.1/appcompat-v7-28.0.0.aar/d4439e502685c256006fa4bec8edb713/res/values-v28/values-v28.xml","position":{"startLine":8,"startColumn":4,"startOffset":447,"endLine":11,"endColumn":12,"endOffset":684}}],"original":"","tool":"AAPT"}
AGPBI: {"kind":"error","text":"error: resource android:attr/dialogCornerRadius not found.","sources":[{"file":"/Users/umutyusuf/Documents/repo/core-bootstrap/core-android-client-app/PointrSample-Ozion-v5.0.8/app/build/intermediates/incremental/mergeDebugResources/merged.dir/values-v28/values-v28.xml","position":{"startLine":10}}],"original":"","tool":"AAPT"}
AGPBI: {"kind":"error","text":"error: resource android:attr/fontVariationSettings not found.","sources":[{"file":"/Users/umutyusuf/.gradle/caches/transforms-1/files-1.1/appcompat-v7-28.0.0.aar/d4439e502685c256006fa4bec8edb713/res/values/values.xml","position":{"startLine":1303,"startColumn":4,"startOffset":70911,"endColumn":68,"endOffset":70975}}],"original":"","tool":"AAPT"}
AGPBI: {"kind":"error","text":"error: resource android:attr/ttcIndex not found.","sources":[{"file":"/Users/umutyusuf/.gradle/caches/transforms-1/files-1.1/appcompat-v7-28.0.0.aar/d4439e502685c256006fa4bec8edb713/res/values/values.xml","position":{"startLine":1303,"startColumn":4,"startOffset":70911,"endColumn":68,"endOffset":70975}}],"original":"","tool":"AAPT"}

We avoid to do any manipulations in project code, so tried to solve it in library.

We downgrade the all versions to match the project versions. And published it with again with

compileSdkVersion -> 26
targetSdkVersion 26
support library version -> 26.0.1

But after that, we face a manifest merge error

Error:
    Attribute meta-data#android.support.VERSION@value value=(26.0.1) from [com.android.support:cardview-v7:26.0.1] AndroidManifest.xml:25:13-35
    is also present at [com.android.support:support-v4:26.1.0] AndroidManifest.xml:28:13-35 value=(26.1.0).
    Suggestion: add 'tools:replace="android:value"' to <meta-data> element at AndroidManifest.xml:23:9-25:38 to override

This is originated from gcm-play-services which has support-v4:26.1.0 transitive dependency listed in dependency tree.

and to resolve it, added this to manifest

<meta-data
            tools:node="replace"
            tools:replace="android:value"
            android:name="android.support.VERSION"
            android:value="26.0.1" />

This made it all work. But now what would be the drawbacks of putting this meta tag to AndroidManifest file?

We tested this approach with all of compileSdkVersion 26, 27, 28 and all corresponding support library version. All seem to work.

We are search for better approaches to this.

Alternative solution we tried

We published the support library dependency in provided scope. But in this case projects using library should add their support design library to be able to use the with no problem. But even though they add the support library, would it be a problem if project had different support library version other then what library is compiled with?

malik_cesur
  • 312
  • 2
  • 8

1 Answers1

1

This manifest meta-data may cause issues if your client uses a support library that forces another version of android.support the same way in its manifest. So avoid using this line in your SDK. Publishing with scope 'provided' will also not work and cause crashes if your client does not provide a support library as you said.

The solution I found was to use support:design:27.1.0 . This is the magical library that does not conflict with any other versions of the support libraries. After days of trying I was very happy to see that it resolves this issue, and does not cause crashes if the third-party uses another version of support design. Hope it solves your problem as well.

Elican Doenyas
  • 596
  • 6
  • 9