From 39a22effb1688a8f36df1745e3f58d49292af637 Mon Sep 17 00:00:00 2001 From: hristoterezov Date: Wed, 26 Sep 2018 16:57:44 -0500 Subject: [PATCH] fix(build.gradle): Move dropboxAppKey definition to defaultConfig --- android/app/build.gradle | 90 +++++++++++++++++++++++----------------- 1 file changed, 52 insertions(+), 38 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index 6133ded2f..0e57acb79 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -1,11 +1,5 @@ apply plugin: 'com.android.application' -def parser = new XmlSlurper(false, false, true) -parser.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false) -def plist = parser.parse('../ios/app/src/Info.plist') -def dbScheme = plist.dict.array.dict.array.string.find{string-> string.text().startsWith('db-')} -def dropboxAppKey = dbScheme?.text() - 'db-' - android { compileSdkVersion rootProject.ext.compileSdkVersion @@ -34,12 +28,10 @@ android { buildTypes { debug { - resValue("string", "dropbox_app_key", "${dropboxAppKey}") minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules-debug.pro' } release { - resValue("string", "dropbox_app_key", "${dropboxAppKey}") minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules-release.pro' } @@ -49,36 +41,6 @@ android { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } - - if (dropboxAppKey) { - def dropboxActivity = """ - - - - - - - """; - - - applicationVariants.all { variant -> - variant.outputs.each { output -> - output.processManifest.doLast { - File manifestOutFile = new File(output.processManifest.manifestOutputDirectory, "AndroidManifest.xml") - if (!manifestOutFile.isFile()) { - manifestOutFile = new File(new File(output.processManifest.manifestOutputDirectory, output.dirName),"AndroidManifest.xml") - } - if (manifestOutFile.exists()) { - def newFileContents = manifestOutFile.getText('UTF-8').replace("", "${dropboxActivity}") - manifestOutFile.write(newFileContents, 'UTF-8') - } - } - } - } - } } dependencies { @@ -92,6 +54,58 @@ dependencies { releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.6.1' } +gradle.projectsEvaluated { + // Dropbox integration + // + + def plistParser = new XmlSlurper( + /* validating */ false, + /* namespaceAware */ false, + /* allowDocTypeDeclaration */ true) + plistParser.setFeature( + 'http://apache.org/xml/features/nonvalidating/load-external-dtd', + false) + def plist = plistParser.parse('../ios/app/src/Info.plist') + def dropboxScheme = plist.dict.array.dict.array.string.find { string -> + string.text().startsWith('db-') + } + def dropboxAppKey = dropboxScheme?.text() - 'db-' + + if (dropboxAppKey) { + android.defaultConfig.resValue('string', 'dropbox_app_key', "${dropboxAppKey}") + + def dropboxActivity = """ + + + + + + + + """; + + android.applicationVariants.all { variant -> + variant.outputs.each { output -> + output.processManifest.doLast { + def f = new File(manifestOutputDirectory, 'AndroidManifest.xml') + if (!f.isFile()) { + f = new File(new File(manifestOutputDirectory, output.dirName), 'AndroidManifest.xml') + } + if (f.exists()) { + def charset = 'UTF-8' + def s = f.getText(charset) + s = s.replace('', "${dropboxActivity}") + f.write(s, charset) + } + } + } + } + } +} + if (project.file('google-services.json').exists()) { apply plugin: 'com.google.gms.google-services' }