Browse Source

fix(build.gradle): Move dropboxAppKey definition to defaultConfig

master
hristoterezov 6 years ago
parent
commit
39a22effb1
1 changed files with 52 additions and 38 deletions
  1. 52
    38
      android/app/build.gradle

+ 52
- 38
android/app/build.gradle View File

@@ -1,11 +1,5 @@
1 1
 apply plugin: 'com.android.application'
2 2
 
3
-def parser = new XmlSlurper(false, false, true)
4
-parser.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false)
5
-def plist = parser.parse('../ios/app/src/Info.plist')
6
-def dbScheme = plist.dict.array.dict.array.string.find{string-> string.text().startsWith('db-')}
7
-def dropboxAppKey = dbScheme?.text() - 'db-'
8
-
9 3
 android {
10 4
     compileSdkVersion rootProject.ext.compileSdkVersion
11 5
 
@@ -34,12 +28,10 @@ android {
34 28
 
35 29
     buildTypes {
36 30
         debug {
37
-            resValue("string", "dropbox_app_key", "${dropboxAppKey}")
38 31
             minifyEnabled true
39 32
             proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules-debug.pro'
40 33
         }
41 34
         release {
42
-            resValue("string", "dropbox_app_key", "${dropboxAppKey}")
43 35
             minifyEnabled true
44 36
             proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules-release.pro'
45 37
         }
@@ -49,36 +41,6 @@ android {
49 41
         sourceCompatibility JavaVersion.VERSION_1_8
50 42
         targetCompatibility JavaVersion.VERSION_1_8
51 43
     }
52
-
53
-    if (dropboxAppKey) {
54
-        def dropboxActivity = """<activity
55
-            android:name="com.dropbox.core.android.AuthActivity"
56
-            android:configChanges="orientation|keyboard"
57
-            android:launchMode="singleTask">
58
-          <intent-filter>
59
-            <data android:scheme="db-${dropboxAppKey}" />
60
-            <action android:name="android.intent.action.VIEW" />
61
-            <category android:name="android.intent.category.BROWSABLE" />
62
-            <category android:name="android.intent.category.DEFAULT" />
63
-          </intent-filter>
64
-        </activity>""";
65
-
66
-
67
-        applicationVariants.all { variant ->
68
-            variant.outputs.each { output ->
69
-                output.processManifest.doLast {
70
-                    File manifestOutFile = new File(output.processManifest.manifestOutputDirectory, "AndroidManifest.xml")
71
-                    if (!manifestOutFile.isFile()) {
72
-                        manifestOutFile = new File(new File(output.processManifest.manifestOutputDirectory, output.dirName),"AndroidManifest.xml")
73
-                    }
74
-                    if (manifestOutFile.exists()) {
75
-                        def newFileContents = manifestOutFile.getText('UTF-8').replace("</application>", "${dropboxActivity}</application>")
76
-                        manifestOutFile.write(newFileContents, 'UTF-8')
77
-                    }
78
-                }
79
-            }
80
-        }
81
-    }
82 44
 }
83 45
 
84 46
 dependencies {
@@ -92,6 +54,58 @@ dependencies {
92 54
     releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.6.1'
93 55
 }
94 56
 
57
+gradle.projectsEvaluated {
58
+    // Dropbox integration
59
+    //
60
+
61
+    def plistParser = new XmlSlurper(
62
+            /* validating */ false,
63
+            /* namespaceAware */ false,
64
+            /* allowDocTypeDeclaration */ true)
65
+    plistParser.setFeature(
66
+            'http://apache.org/xml/features/nonvalidating/load-external-dtd',
67
+            false)
68
+    def plist = plistParser.parse('../ios/app/src/Info.plist')
69
+    def dropboxScheme = plist.dict.array.dict.array.string.find { string ->
70
+        string.text().startsWith('db-')
71
+    }
72
+    def dropboxAppKey = dropboxScheme?.text() - 'db-'
73
+
74
+    if (dropboxAppKey) {
75
+        android.defaultConfig.resValue('string', 'dropbox_app_key', "${dropboxAppKey}")
76
+
77
+        def dropboxActivity = """
78
+          <activity
79
+              android:configChanges="keyboard|orientation"
80
+              android:launchMode="singleTask"
81
+              android:name="com.dropbox.core.android.AuthActivity">
82
+            <intent-filter>
83
+              <action android:name="android.intent.action.VIEW" />
84
+              <category android:name="android.intent.category.BROWSABLE" />
85
+              <category android:name="android.intent.category.DEFAULT" />
86
+              <data android:scheme="db-${dropboxAppKey}" />
87
+            </intent-filter>
88
+          </activity>""";
89
+
90
+        android.applicationVariants.all { variant ->
91
+            variant.outputs.each { output ->
92
+                output.processManifest.doLast {
93
+                    def f = new File(manifestOutputDirectory, 'AndroidManifest.xml')
94
+                    if (!f.isFile()) {
95
+                        f = new File(new File(manifestOutputDirectory, output.dirName), 'AndroidManifest.xml')
96
+                    }
97
+                    if (f.exists()) {
98
+                        def charset = 'UTF-8'
99
+                        def s = f.getText(charset)
100
+                        s = s.replace('</application>', "${dropboxActivity}</application>")
101
+                        f.write(s, charset)
102
+                    }
103
+                }
104
+            }
105
+        }
106
+    }
107
+}
108
+
95 109
 if (project.file('google-services.json').exists()) {
96 110
    apply plugin: 'com.google.gms.google-services'
97 111
 }

Loading…
Cancel
Save