Skip to content

Commit 31d864c

Browse files
committed
choose aliyun or official by geo ip.
1 parent 8894199 commit 31d864c

File tree

1 file changed

+32
-9
lines changed

1 file changed

+32
-9
lines changed

example/android/build.gradle

+32-9
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,30 @@
1+
import groovy.json.JsonSlurper
2+
3+
14
buildscript {
25
ext.kotlin_version = '1.3.61'
6+
7+
def connection = new URL('https://api.ip.sb/geoip').openConnection()
8+
connection.setRequestMethod('GET')
9+
def reader = new BufferedReader(new InputStreamReader(connection.inputStream))
10+
def text = reader.readLine()
11+
12+
def slurper = new JsonSlurper()
13+
def states = slurper.parseText(text)
14+
def country = states['country']
15+
16+
def isChina = country == 'China'
17+
18+
ext.isChina = isChina
19+
320
repositories {
4-
google()
5-
jcenter()
6-
maven { url 'https://maven.aliyun.com/repository/google' }
7-
maven { url 'https://maven.aliyun.com/repository/jcenter' }
21+
if (isChina) {
22+
maven { url 'https://maven.aliyun.com/repository/google' }
23+
maven { url 'https://maven.aliyun.com/repository/jcenter' }
24+
} else {
25+
google()
26+
jcenter()
27+
}
828
}
929

1030
dependencies {
@@ -15,10 +35,13 @@ buildscript {
1535

1636
allprojects {
1737
repositories {
18-
google()
19-
jcenter()
20-
maven { url 'https://maven.aliyun.com/repository/google' }
21-
maven { url 'https://maven.aliyun.com/repository/jcenter' }
38+
if (isChina) {
39+
maven { url 'https://maven.aliyun.com/repository/google' }
40+
maven { url 'https://maven.aliyun.com/repository/jcenter' }
41+
} else {
42+
google()
43+
jcenter()
44+
}
2245
}
2346
}
2447

@@ -43,4 +66,4 @@ subprojects {
4366
}
4467
}
4568
}
46-
}
69+
}

0 commit comments

Comments
 (0)