In Ionic development, gradle files need to be modified in many ways. Android: Ionic Cordova Platform add [email protected];
Files that need to be modified
./platforms/android/app/build.gradle
./platforms/android/build.gradle
./platforms/android/CordovaLib/build.gradle
Content to add
maven { url 'http://maven.aliyun.com/nexus/content/repositories/google' }
maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' }
maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' }
Copy the code
Modify via shell script (MacOS)
Modifying Script 1(MacOS)
#! /bin/bash
#clear;
### File that needs to be modified
#./platforms/android/app/build.gradle
#./platforms/android/build.gradle
#./platforms/android/CordovaLib/build.gradle
### sed example of modifying a file
#sed -i 'na\x'File.txt -- Add x content before NTH line (newline)
### Content to add
#maven { url'http://maven.aliyun.com/nexus/content/repositories/google' }
#maven { url'http://maven.aliyun.com/nexus/content/groups/public/' }
#maven { url'http://maven.aliyun.com/nexus/content/repositories/jcenter'}
#File name start subscriptFunction change(){file=$1 startIndex=$2 echo '$file $startIndex $[startIndex + 1] $[startIndex + 2] gsed -i "${startIndex}a maven { url 'http://maven.aliyun.com/nexus/content/repositories/google' } // add@duweiquan" $file gsed -i "$[startIndex + 1]a maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' } // add@duweiquan" $file gsed -i "$[startIndex + 2]a maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' } // add@duweiquan" $file }#22 is the number of rows of repositories
change './platforms/android/build.gradle' 22
change './platforms/android/build.gradle' $[37+3]
change './platforms/android/app/build.gradle' 23
change './platforms/android/app/build.gradle' $[38+3]
change './platforms/android/CordovaLib/build.gradle' 26
Copy the code
Modifying Script 2(MacOS)
#! /bin/bash # clear; # define method: # cahnge_2 filename "${arr[*]}" # change_2 './a.log' '22 37' function change_2(){file=$1 lines=$2 index=0 for line in ${lines[@]}; $index $line; $file $startIndex $[startIndex + 1] =$[index * 3 + line] index= 'expr $index + 1' echo ' $[startIndex + 2] gsed -i "${startIndex}a maven { url 'http://maven.aliyun.com/nexus/content/repositories/google' } // add@duweiquan" $file gsed -i "$[startIndex + 1]a maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' } // add@duweiquan" $file gsed -i "$[startIndex + 2]a maven { url 'http://maven.aliyun.com/nexus/content/repositories/jcenter'} / / add @ duweiquan "$file} # modified change_2 execution './platforms/android/build.gradle' '22 37' change_2 './platforms/android/app/build.gradle' '23 38' change_2 './platforms/android/CordovaLib/build.gradle' '22'Copy the code