|
1 | 1 | buildscript {
|
2 |
| - ext.safeExtGet = {prop, fallback -> |
3 |
| - rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback |
4 |
| - } |
5 |
| - repositories { |
6 |
| - google() |
7 |
| - gradlePluginPortal() |
8 |
| - } |
9 |
| - dependencies { |
10 |
| - classpath("com.android.tools.build:gradle:7.0.4") |
11 |
| - } |
| 2 | + repositories { |
| 3 | + google() |
| 4 | + mavenCentral() |
| 5 | + } |
| 6 | + |
| 7 | + dependencies { |
| 8 | + classpath "com.android.tools.build:gradle:7.2.1" |
| 9 | + } |
| 10 | + |
| 11 | + // ext.safeExtGet = {prop, fallback -> |
| 12 | + // rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback |
| 13 | + // } |
12 | 14 | }
|
13 | 15 |
|
14 | 16 | def isNewArchitectureEnabled() {
|
15 |
| - return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true" |
| 17 | + return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true" |
16 | 18 | }
|
17 | 19 |
|
18 |
| -apply plugin: 'com.android.library' |
| 20 | +apply plugin: "com.android.library" |
| 21 | + |
19 | 22 | if (isNewArchitectureEnabled()) {
|
20 |
| - apply plugin: 'com.facebook.react' |
| 23 | + apply plugin: "com.facebook.react" |
| 24 | +} |
| 25 | + |
| 26 | +def getExtOrDefault(name) { |
| 27 | + return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["VectorIcons_" + name] |
| 28 | +} |
| 29 | + |
| 30 | +def getExtOrIntegerDefault(name) { |
| 31 | + return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["VectorIcons_" + name]).toInteger() |
| 32 | +} |
| 33 | + |
| 34 | +def supportsNamespace() { |
| 35 | + def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.') |
| 36 | + def major = parsed[0].toInteger() |
| 37 | + def minor = parsed[1].toInteger() |
| 38 | + |
| 39 | + // Namespace support was added in 7.3.0 |
| 40 | + return (major == 7 && minor >= 3) || major >= 8 |
21 | 41 | }
|
22 | 42 |
|
23 | 43 | android {
|
24 |
| - namespace = "com.oblador.vectoricons" |
25 |
| - compileSdkVersion safeExtGet('compileSdkVersion', 31) |
| 44 | + if (supportsNamespace()) { |
| 45 | + namespace "com.oblador.vectoricons" |
26 | 46 |
|
27 |
| - defaultConfig { |
28 |
| - minSdkVersion safeExtGet('minSdkVersion', 21) |
29 |
| - targetSdkVersion safeExtGet('targetSdkVersion', 31) |
30 |
| - buildConfigField("boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()) |
31 |
| - } |
32 | 47 | sourceSets {
|
33 |
| - main { |
34 |
| - if (isNewArchitectureEnabled()) { |
35 |
| - java.srcDirs += ['src/newarch'] |
36 |
| - } else { |
37 |
| - java.srcDirs += ['src/oldarch'] |
38 |
| - } |
39 |
| - } |
| 48 | + main { |
| 49 | + manifest.srcFile "src/main/AndroidManifestNew.xml" |
| 50 | + } |
40 | 51 | }
|
| 52 | + } |
| 53 | + |
| 54 | + compileSdkVersion getExtOrIntegerDefault("compileSdkVersion") |
| 55 | + |
| 56 | + defaultConfig { |
| 57 | + minSdkVersion getExtOrIntegerDefault("minSdkVersion") |
| 58 | + targetSdkVersion getExtOrIntegerDefault("targetSdkVersion") |
| 59 | + buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString() |
| 60 | + |
| 61 | + } |
| 62 | + |
| 63 | + buildFeatures { |
| 64 | + buildConfig true |
| 65 | + } |
| 66 | + |
| 67 | + buildTypes { |
| 68 | + release { |
| 69 | + minifyEnabled false |
| 70 | + } |
| 71 | + } |
| 72 | + |
| 73 | + lintOptions { |
| 74 | + disable "GradleCompatible" |
| 75 | + } |
| 76 | + |
| 77 | + compileOptions { |
| 78 | + sourceCompatibility JavaVersion.VERSION_1_8 |
| 79 | + targetCompatibility JavaVersion.VERSION_1_8 |
| 80 | + } |
| 81 | + |
| 82 | + sourceSets { |
| 83 | + main { |
| 84 | + if (isNewArchitectureEnabled()) { |
| 85 | + java.srcDirs += [ |
| 86 | + 'src/newarch', |
| 87 | + // This is needed to build Kotlin project with NewArch enabled |
| 88 | + "${project.buildDir}/generated/source/codegen/java" |
| 89 | + ] |
| 90 | + } else { |
| 91 | + java.srcDirs += ['src/oldarch'] |
| 92 | + } |
| 93 | + } |
| 94 | + } |
41 | 95 | }
|
42 | 96 |
|
43 | 97 | repositories {
|
44 |
| - maven { |
45 |
| - // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm |
46 |
| - url "$projectDir/../node_modules/react-native/android" |
47 |
| - } |
48 |
| - mavenCentral() |
49 |
| - google() |
| 98 | + mavenCentral() |
| 99 | + google() |
50 | 100 | }
|
51 | 101 |
|
| 102 | + |
52 | 103 | dependencies {
|
53 |
| - implementation 'com.facebook.react:react-native:+' |
| 104 | + // For < 0.71, this will be from the local maven repo |
| 105 | + // For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin |
| 106 | + //noinspection GradleDynamicVersion |
| 107 | + implementation "com.facebook.react:react-native:+" |
| 108 | +} |
| 109 | + |
| 110 | +if (isNewArchitectureEnabled()) { |
| 111 | + react { |
| 112 | + jsRootDir = file("../src/") |
| 113 | + libraryName = "VectorIcons" |
| 114 | + codegenJavaPackageName = "com.oblador.vectoricons" |
| 115 | + } |
54 | 116 | }
|
0 commit comments