Skip to content

Confirm the iOS platform folder exists before attempting to pull in iOS file #1022

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
1a8cd4d
Some of plugin.xml is now handled by after_prepare
neil-spartan Feb 9, 2018
a2facdf
Correctly set config strings
neil-spartan Feb 9, 2018
2a97dec
Merge pull request #3 from neil-spartan/patch-3
callum-spartan Feb 9, 2018
a8e418c
Merge pull request #4 from neil-spartan/patch-4
callum-spartan Feb 9, 2018
30e9cb4
GoogleService-Info.plist must be included as a <resource-file>
neil-spartan Feb 9, 2018
cbc9650
Don't need to manually copy config file on iOS
neil-spartan Feb 9, 2018
43c9a01
Merge pull request #5 from neil-spartan/patch-5
callum-spartan Feb 9, 2018
3ac8e44
Merge pull request #6 from neil-spartan/patch-6
callum-spartan Feb 9, 2018
e358267
Adding hook to copy config into plugin
neil-spartan Feb 9, 2018
95292db
Hook for plugin install to copy config
neil-spartan Feb 9, 2018
d9c0543
Merge pull request #7 from neil-spartan/patch-7
callum-spartan Feb 9, 2018
5c8d50f
Merge pull request #8 from neil-spartan/patch-8
callum-spartan Feb 9, 2018
9a3b1e4
Call after_prepare script after plugin install.
neil-spartan Jul 5, 2018
e391900
Merge pull request #10 from neil-spartan/patch-9
callum-spartan Jul 5, 2018
1c5128b
Attempted to make after_plugin_install script work
neil-spartan Jul 6, 2018
dfbdf38
Merge pull request #11 from neil-spartan/patch-10
callum-spartan Jul 6, 2018
08d26dc
Get platforms from context
neil-spartan Jul 6, 2018
897ddbb
Merge pull request #12 from neil-spartan/patch-11
callum-spartan Jul 6, 2018
715b4bf
Removed console.log from after_plugin_install script
neil-spartan Jul 6, 2018
0d68246
Merge pull request #13 from neil-spartan/patch-12
callum-spartan Jul 6, 2018
ba62672
Fix: modified dependencies to include specific versions of firebase a…
neil-spartan Nov 13, 2018
f0cf9a9
Merge pull request #14 from neil-spartan/patch-13
callum-spartan Nov 13, 2018
68e18b9
Fix: further modified dependency versions to fix runtime exception. (…
neil-spartan Nov 16, 2018
afe9c2a
Fix: Checking if there is an iOS platform before attempting to pull i…
stevenmldn Mar 11, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 9 additions & 15 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ xmlns:android="http://schemas.android.com/apk/res/android">
<param name="onload" value="true" />
</feature>
</config-file>
<config-file parent="/resources" target="res/values/strings.xml">
<string name="google_app_id">@string/google_app_id</string>
</config-file>
<config-file parent="/resources" target="res/values/strings.xml">
<string name="google_api_key">@string/google_api_key</string>
</config-file>
<config-file target="AndroidManifest.xml" parent="/*">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Expand All @@ -47,21 +41,20 @@ xmlns:android="http://schemas.android.com/apk/res/android">
</service>
<receiver android:name="org.apache.cordova.firebase.OnNotificationOpenReceiver"></receiver>
</config-file>
<source-file src="src/android/google-services.json" target-dir="." />
<source-file src="src/android/FirebasePlugin.java" target-dir="src/org/apache/cordova/firebase" />
<source-file src="src/android/OnNotificationOpenReceiver.java" target-dir="src/org/apache/cordova/firebase" />
<source-file src="src/android/FirebasePluginInstanceIDService.java" target-dir="src/org/apache/cordova/firebase" />
<source-file src="src/android/FirebasePluginMessagingService.java" target-dir="src/org/apache/cordova/firebase" />
<source-file src="src/android/colors.xml" target-dir="res/values" />

<framework src="src/android/build.gradle" custom="true" type="gradleReference" />
<framework src="com.google.gms:google-services:+" />
<framework src="com.google.android.gms:play-services-tagmanager:+" />
<framework src="com.google.firebase:firebase-core:+" />
<framework src="com.google.firebase:firebase-messaging:+" />
<framework src="com.google.firebase:firebase-crash:+" />
<framework src="com.google.firebase:firebase-config:+" />
<framework src="com.google.firebase:firebase-perf:+" />
<framework src="com.google.gms:google-services:3.1.1" />
<framework src="com.google.android.gms:play-services-tagmanager:16.0.4" />
<framework src="com.google.firebase:firebase-core:16.0.4" />
<framework src="com.google.firebase:firebase-messaging:17.3.4" />
<framework src="com.google.firebase:firebase-crash:16.2.1" />
<framework src="com.google.firebase:firebase-config:16.1.0" />
<framework src="com.google.firebase:firebase-perf:16.2.0" />

</platform>

Expand All @@ -81,7 +74,7 @@ xmlns:android="http://schemas.android.com/apk/res/android">
<config-file parent="aps-environment" target="*/Entitlements-Release.plist">
<string>production</string>
</config-file>

<resource-file src="src/ios/GoogleService-Info.plist" />

<header-file src="src/ios/AppDelegate+FirebasePlugin.h" />
Expand Down Expand Up @@ -115,4 +108,5 @@ xmlns:android="http://schemas.android.com/apk/res/android">
</platform>

<hook src="scripts/after_prepare.js" type="after_prepare" />
<hook src="scripts/after_plugin_install.js" type="after_plugin_install" />
</plugin>
21 changes: 21 additions & 0 deletions scripts/after_plugin_install.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env node
'use strict';

var fs = require('fs');

function directoryExists(path) {
try {
return fs.statSync(path).isDirectory();
} catch (e) {
return false;
}
}

if (directoryExists('platforms/ios')) {
fs.unlinkSync('./plugins/cordova-plugin-firebase/src/ios/GoogleService-Info.plist');

fs.writeFileSync('./plugins/cordova-plugin-firebase/src/ios/GoogleService-Info.plist', fs.readFileSync('./GoogleService-Info.plist'));
}
module.exports = function (context) {
require('./after_prepare')(context);
};
26 changes: 11 additions & 15 deletions scripts/after_prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,16 @@ function updateStringsXml(contents) {
var json = JSON.parse(contents);
var strings = fs.readFileSync(PLATFORM.ANDROID.stringsXml).toString();

// strip non-default value
strings = strings.replace(new RegExp('<string name="google_app_id">([^\@<]+?)</string>', 'i'), '');

// strip non-default value
strings = strings.replace(new RegExp('<string name="google_api_key">([^\@<]+?)</string>', 'i'), '');

// strip empty lines
strings = strings.replace(new RegExp('(\r\n|\n|\r)[ \t]*(\r\n|\n|\r)', 'gm'), '$1');

// replace the default value
strings = strings.replace(new RegExp('<string name="google_app_id">([^<]+?)</string>', 'i'), '<string name="google_app_id">' + json.client[0].client_info.mobilesdk_app_id + '</string>');

// replace the default value
strings = strings.replace(new RegExp('<string name="google_api_key">([^<]+?)</string>', 'i'), '<string name="google_api_key">' + json.client[0].api_key[0].current_key + '</string>');
// after_prepare is run multiple times, and duplicate strings causes a build error
if (~strings.indexOf('google_app_id')) {
return;
}

// insert values from json
strings = strings.replace('</resources>', '<string name="google_app_id">' + json.client[0].client_info.mobilesdk_app_id + '</string><string name="google_api_key">' + json.client[0].api_key[0].current_key + '</string></resources>');

fs.writeFileSync(PLATFORM.ANDROID.stringsXml, strings);
}
Expand Down Expand Up @@ -128,14 +124,14 @@ function directoryExists(path) {

module.exports = function(context) {
//get platform from the context supplied by cordova
var platforms = context.opts.platforms;
var platforms = context.opts.platforms || context.opts.cordova.platforms;
// Copy key files to their platform specific folders
if (platforms.indexOf('ios') !== -1 && directoryExists(IOS_DIR)) {
console.log('Preparing Firebase on iOS');
copyKey(PLATFORM.IOS);
//console.log('Preparing Firebase on iOS');
//copyKey(PLATFORM.IOS);
}
if (platforms.indexOf('android') !== -1 && directoryExists(ANDROID_DIR)) {
console.log('Preparing Firebase on Android');
copyKey(PLATFORM.ANDROID, updateStringsXml)
}
};
};