@@ -218,27 +218,21 @@ export default class AndroidGenerator implements ContainerGenerator {
218
218
config . outDir ,
219
219
'lib/src/main' ,
220
220
) ;
221
+
221
222
if ( semver . gte ( reactNativePlugin . version , '0.60.0' ) ) {
222
- const filesWithSupportLib : string [ ] = [ ] ;
223
- shell . pushd ( relPathToPluginSource ) ;
224
- shell . ls ( '**/*.java' ) . forEach ( ( file ) => {
225
- if ( shell . grep ( 'android.support' , file ) . trim ( ) . length !== 0 ) {
226
- filesWithSupportLib . push ( file ) ;
227
- }
228
- } ) ;
229
- if ( filesWithSupportLib . length !== 0 ) {
223
+ const convertedFiles = this . convertToAndroidX (
224
+ relPathToPluginSource ,
225
+ ) ;
226
+ if ( convertedFiles > 0 ) {
230
227
log . info (
231
228
`${ plugin . name } contains source files with references to the Android Support Library (android.support.*)` ,
232
229
) ;
233
- filesWithSupportLib . forEach ( ( file ) => {
234
- shell . sed ( '-i' , 'android.support' , 'androidx' , file ) ;
235
- } ) ;
236
230
log . info (
237
- `${ filesWithSupportLib . length } files successfully converted to use AndroidX (androidx.*)` ,
231
+ `${ convertedFiles } files successfully converted to use AndroidX (androidx.*)` ,
238
232
) ;
239
233
}
240
- shell . popd ( ) ;
241
234
}
235
+
242
236
shell . cp ( '-R' , relPathToPluginSource , absPathToCopyPluginSourceTo ) ;
243
237
}
244
238
@@ -707,10 +701,51 @@ You should replace "${annotationProcessorPrefix}:${dependency}" with "annotation
707
701
'lib/src/main/java/com/walmartlabs/ern/container/plugins' ,
708
702
) ;
709
703
shell . cp ( pathToPluginConfigHook , pathToCopyPluginConfigHookTo ) ;
704
+
705
+ if ( semver . gte ( rnVersion , '0.60.0' ) ) {
706
+ const filesConverted = this . convertToAndroidX (
707
+ pathToCopyPluginConfigHookTo ,
708
+ ) ;
709
+ if ( filesConverted > 0 ) {
710
+ log . info (
711
+ `${ plugin . name } contains source files with references to the Android Support Library (android.support.*)` ,
712
+ ) ;
713
+ log . info (
714
+ `${ filesConverted } files successfully converted to use AndroidX (androidx.*)` ,
715
+ ) ;
716
+ }
717
+ }
710
718
}
711
719
}
712
720
}
713
721
722
+ /**
723
+ * Convert files in a directory from support library to AndroidX
724
+ * eg: import android.support.annotation.NonNull => import androidx.annotation.NonNull
725
+ */
726
+ public convertToAndroidX ( dir : string ) : number {
727
+ const filesWithSupportLib : string [ ] = [ ] ;
728
+ shell . pushd ( dir ) ;
729
+ shell
730
+ . ls ( '-R' , '.' )
731
+ . filter ( ( file ) => file . match ( / \. ( j a v a | k t ) $ / ) )
732
+ . forEach ( ( file ) => {
733
+ if ( shell . grep ( 'android.support' , file ) . trim ( ) . length !== 0 ) {
734
+ filesWithSupportLib . push ( file ) ;
735
+ }
736
+ } ) ;
737
+
738
+ if ( filesWithSupportLib . length !== 0 ) {
739
+ filesWithSupportLib . forEach ( ( file ) => {
740
+ shell . sed ( '-i' , 'android.support' , 'androidx' , file ) ;
741
+ } ) ;
742
+ }
743
+
744
+ shell . popd ( ) ;
745
+
746
+ return filesWithSupportLib . length ;
747
+ }
748
+
714
749
public async buildAndroidPluginsViews (
715
750
plugins : PackagePath [ ] ,
716
751
mustacheView : any ,
0 commit comments