Skip to content

Commit

Permalink
Add library name override for AndroidX compatibility
Browse files Browse the repository at this point in the history
If you allow an override of the library name as well, the jetifier package works to make this
package AndroidX compatible in combination with an android/build.gradle ext{} block in apps that
override things to 'androidx.core' for coreLibName and '1.0.2' for supportLibVersion
  • Loading branch information
mikehardy authored Jun 25, 2019
1 parent 091c237 commit 0c76619
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ dependencies {
compileOnly('com.facebook.react:react-native:+') {
exclude group: 'com.android.support'
}
implementation "com.android.support:appcompat-v7:${safeExtGet('supportLibVersion', '28.0.0')}"
implementation "${safeExtGet('coreLibName', 'com.android.support:appcompat-v7')}:${safeExtGet('supportLibVersion', '28.0.0')}"
implementation "com.google.android.gms:play-services-base:${safeExtGet('playServicesVersion', '16.1.0')}"
implementation "com.google.android.gms:play-services-maps:${safeExtGet('playServicesVersion', '16.1.0')}"
implementation 'com.google.maps.android:android-maps-utils:0.5'
Expand Down

2 comments on commit 0c76619

@christocracy
Copy link
Contributor

@christocracy christocracy commented on 0c76619 Jul 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think coreLibName could be determined programmatically by comparing the supportLibVersion.

A non-AndroidX supportLibVersion will typically take the form 26.x.x or 27.x.x or 28.x.x, etc, while AndroidX starts at 1.x.x. As a temporary stop-gap, we could add some logic to express the fact "If the major component of supportLibVersion is < 20 (eg: 1.0.2), we're dealing with AndroidX.

By the time the version of androidx.appcompat:appcompat gets anywhere near 20.x.x (will take years), AndroidX migration will be long behind us. I suspect React Native won't even exist by then :)

@christocracy
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to work:

dependencies {
    def supportLibMajorVersion = supportLibVersion.split('\\.')[0] as int
    def appCompatLibName =  (supportLibMajorVersion < 20) ? "androidx.appcompat:appcompat" : "com.android.support:appcompat-v7"

    implementation "$appCompatLibName:$supportLibVersion"
    .
    .
    .
}

Please sign in to comment.