@@ -50,11 +50,7 @@ public void OnPostGenerateGradleAndroidProject(string basePath) {
5050 var changed = false ;
5151 var androidManifest = new AndroidManifest ( GetManifestPath ( basePath ) ) ;
5252
53- AddWebkitPermissions ( ref changed , androidManifest , basePath ) ;
54-
55- if ( ! nofragment ) {
56- AddCorePermissions ( ref changed , androidManifest , basePath ) ;
57- }
53+ AddAndroidXDependencies ( ref changed , androidManifest , basePath , ! nofragment ) ;
5854
5955 changed = ( androidManifest . SetExported ( true ) || changed ) ;
6056 changed = ( androidManifest . SetWindowSoftInputMode ( "adjustPan" ) || changed ) ;
@@ -75,78 +71,39 @@ public void OnPostGenerateGradleAndroidProject(string basePath) {
7571 }
7672 }
7773
78- private void AddCorePermissions ( ref bool changed , AndroidManifest androidManifest , string basePath ) {
74+ private void AddAndroidXDependencies ( ref bool changed , AndroidManifest androidManifest , string basePath , bool includeCoreDependency ) {
7975 changed = androidManifest . AddFileProvider ( basePath ) || changed ;
8076 {
8177 string path = GetBuildGradlePath ( basePath ) ;
8278 string [ ] lines0 = File . ReadAllText ( path ) . Replace ( "\r \n " , "\n " ) . Replace ( "\r " , "\n " ) . Split ( new [ ] { '\n ' } ) ;
8379 {
8480 List < string > lines = new ( ) ;
85- bool independencies = false ;
81+ bool inDependencies = false ;
82+ bool hasWebkit = false ;
83+ bool hasCore = false ;
8684 foreach ( string line in lines0 ) {
8785 if ( line == "dependencies {" ) {
88- independencies = true ;
89- } else if ( independencies && line == "}" ) {
90- independencies = false ;
91- lines . Add ( " implementation 'androidx.core:core:1.6.0'" ) ;
92- } else if ( independencies ) {
93- if ( line . Contains ( "implementation(name: 'core" )
94- || line . Contains ( "implementation(name: 'androidx.core.core" )
95- || line . Contains ( "implementation 'androidx.core:core" ) ) {
96- break ;
86+ inDependencies = true ;
87+ } else if ( inDependencies && line == "}" ) {
88+ if ( ! hasWebkit ) {
89+ lines . Add ( " implementation 'androidx.webkit:webkit:1.12.0'" ) ;
90+ hasWebkit = true ;
9791 }
98- }
99-
100- lines . Add ( line ) ;
101- }
102-
103- if ( lines . Count > lines0 . Length ) {
104- File . WriteAllText ( path , string . Join ( "\n " , lines ) + "\n " ) ;
105- }
106- }
107- }
108- {
109- string path = GetGradlePropertiesPath ( basePath ) ;
110- string lines0 = "" ;
111- string lines = "" ;
112- if ( File . Exists ( path ) ) {
113- lines0 = File . ReadAllText ( path ) . Replace ( "\r \n " , "\n " ) . Replace ( "\r " , "\n " ) + "\n " ;
114- lines = lines0 ;
115- }
116-
117- if ( ! lines . Contains ( "android.useAndroidX=true" ) ) {
118- lines += "android.useAndroidX=true\n " ;
119- }
120-
121- if ( ! lines . Contains ( "android.enableJetifier=true" ) ) {
122- lines += "android.enableJetifier=true\n " ;
123- }
124-
125- if ( lines != lines0 ) {
126- File . WriteAllText ( path , lines ) ;
127- }
128- }
129- }
130-
131- private void AddWebkitPermissions ( ref bool changed , AndroidManifest androidManifest , string basePath ) {
132- changed = androidManifest . AddFileProvider ( basePath ) || changed ;
133- {
134- string path = GetBuildGradlePath ( basePath ) ;
135- string [ ] lines0 = File . ReadAllText ( path ) . Replace ( "\r \n " , "\n " ) . Replace ( "\r " , "\n " ) . Split ( new [ ] { '\n ' } ) ;
136- {
137- List < string > lines = new ( ) ;
138- bool independencies = false ;
139- foreach ( string line in lines0 ) {
140- if ( line == "dependencies {" ) {
141- independencies = true ;
142- } else if ( independencies && line == "}" ) {
143- independencies = false ;
144- lines . Add ( " implementation 'androidx.webkit:webkit:1.12.0'" ) ;
145- } else if ( independencies ) {
92+ if ( includeCoreDependency && ! hasCore ) {
93+ lines . Add ( " implementation 'androidx.core:core:1.6.0'" ) ;
94+ hasCore = true ;
95+ }
96+ inDependencies = false ;
97+ } else if ( inDependencies ) {
14698 if ( line . Contains ( "implementation(name: 'webkit" )
14799 || line . Contains ( "implementation(name: 'androidx.webkit.webkit" )
148100 || line . Contains ( "implementation 'androidx.webkit:webkit" ) ) {
149- break ;
101+ hasWebkit = true ;
102+ }
103+ if ( line . Contains ( "implementation(name: 'core" )
104+ || line . Contains ( "implementation(name: 'androidx.core.core" )
105+ || line . Contains ( "implementation 'androidx.core:core" ) ) {
106+ hasCore = true ;
150107 }
151108 }
152109
0 commit comments