Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit 4e1c502

Browse files
App Freezes on SplashScreen when enabling facebook login #898
1 parent 61c14b6 commit 4e1c502

File tree

1 file changed

+12
-172
lines changed

1 file changed

+12
-172
lines changed

src/scripts/postinstall.js

Lines changed: 12 additions & 172 deletions
Original file line numberDiff line numberDiff line change
@@ -3391,7 +3391,7 @@ dependencies {
33913391
` + (isSelected(result.ml_kit_image_labeling) ? `` : `//`) + ` compile "com.google.firebase:firebase-ml-vision-image-label-model:15.0.0"
33923392
33933393
// Facebook Authentication
3394-
` + (isSelected(result.facebook_auth) ? `` : `//`) + ` compile ("com.facebook.android:facebook-android-sdk:4.+"){ exclude group: 'com.google.zxing' }
3394+
` + (isSelected(result.facebook_auth) ? `` : `//`) + ` compile ("com.facebook.android:facebook-android-sdk:4.35.0"){ exclude group: 'com.google.zxing' }
33953395
33963396
// Google Sign-In Authentication
33973397
` + (isSelected(result.google_auth) ? `` : `//`) + ` compile "com.google.android.gms:play-services-auth:$googlePlayServicesVersion"
@@ -3417,68 +3417,22 @@ apply plugin: "com.google.gms.google-services"
34173417

34183418
/**
34193419
* Installs an after-prepare build hook to copy the app/App_Resources/Android/google-services.json to platform/android on build.
3420-
* Installs before-checkForChange build hook to detect changes in environment and copy GoogleServices.plist on build
34213420
*/
34223421
function writeGoogleServiceCopyHook() {
3423-
3424-
/*
3425-
Install after-prepare hook
3426-
*/
3427-
3428-
console.log("Install google-service.json after-prepare copy hook.");
3422+
console.log("Install google-service.json copy hook.");
34293423
try {
3430-
var afterPrepareScriptContent =
3424+
var scriptContent =
34313425
`
34323426
var path = require("path");
34333427
var fs = require("fs");
34343428
34353429
module.exports = function($logger, $projectData, hookArgs) {
34363430
3437-
return new Promise(function(resolve, reject) {
3438-
3439-
/* Decide whether to prepare for dev or prod environment */
3440-
3441-
var isReleaseBuild = (hookArgs.appFilesUpdaterOptions && hookArgs.appFilesUpdaterOptions.release) ? true : false;
3442-
var validProdEnvs = ['prod','production'];
3443-
var isProdEnv = false; // building with --env.prod or --env.production flag
3444-
3445-
if (hookArgs.platformSpecificData.env) {
3446-
Object.keys(hookArgs.platformSpecificData.env).forEach((key) => {
3447-
if (validProdEnvs.indexOf(key)>-1) { isProdEnv=true; }
3448-
});
3449-
}
3450-
3451-
var buildType = isReleaseBuild || isProdEnv ? 'production' : 'development';
3452-
3453-
/* Create info file in platforms dir so we can detect changes in environment and force prepare if needed */
3454-
3455-
var npfInfoPath = path.join($projectData.platformsDir, hookArgs.platform.toLowerCase(), ".pluginfirebaseinfo");
3456-
var npfInfo = {
3457-
buildType: buildType,
3458-
};
3459-
3460-
try { fs.writeFileSync(npfInfoPath, JSON.stringify(npfInfo)); }
3461-
catch (err) {
3462-
$logger.info('nativescript-plugin-firebase: unable to create '+npfInfoPath+', prepare will be forced next time!');
3463-
}
3464-
3465-
3466-
/* Handle preparing of Google Services files */
3467-
3431+
return new Promise(function(resolve, reject) {
34683432
if (hookArgs.platform.toLowerCase() === 'android') {
3433+
var sourceGoogleJson = path.join($projectData.appResourcesDirectoryPath, "Android", "google-services.json");
34693434
var destinationGoogleJson = path.join($projectData.platformsDir, "android", "app", "google-services.json");
34703435
var destinationGoogleJsonAlt = path.join($projectData.platformsDir, "android", "google-services.json");
3471-
var sourceGoogleJson = path.join($projectData.appResourcesDirectoryPath, "Android", "google-services.json");
3472-
var sourceGoogleJsonProd = path.join($projectData.appResourcesDirectoryPath, "Android", "google-services.json.prod");
3473-
var sourceGoogleJsonDev = path.join($projectData.appResourcesDirectoryPath, "Android", "google-services.json.dev");
3474-
3475-
// ensure we have both dev/prod versions so we never overwrite singlular google-services.json
3476-
if (fs.existsSync(sourceGoogleJsonProd) && fs.existsSync(sourceGoogleJsonDev)) {
3477-
if (buildType==='production') { sourceGoogleJson = sourceGoogleJsonProd; } // use prod version
3478-
else { sourceGoogleJson = sourceGoogleJsonDev; } // use dev version
3479-
}
3480-
3481-
// copy correct version to destination
34823436
if (fs.existsSync(sourceGoogleJson) && fs.existsSync(path.dirname(destinationGoogleJson))) {
34833437
$logger.out("Copy " + sourceGoogleJson + " to " + destinationGoogleJson + ".");
34843438
fs.writeFileSync(destinationGoogleJson, fs.readFileSync(sourceGoogleJson));
@@ -3493,16 +3447,11 @@ return new Promise(function(resolve, reject) {
34933447
reject();
34943448
}
34953449
} else if (hookArgs.platform.toLowerCase() === 'ios') {
3496-
// we have copied our GoogleService-Info.plist during before-checkForChanges hook, here we delete it to avoid changes in git
3497-
var destinationGooglePlist = path.join($projectData.appResourcesDirectoryPath, "iOS", "GoogleService-Info.plist");
3498-
var sourceGooglePlistProd = path.join($projectData.appResourcesDirectoryPath, "iOS", "GoogleService-Info.plist.prod");
3499-
var sourceGooglePlistDev = path.join($projectData.appResourcesDirectoryPath, "iOS", "GoogleService-Info.plist.dev");
3500-
3501-
// if we have both dev/prod versions, let's remove GoogleService-Info.plist in destination dir
3502-
if (fs.existsSync(sourceGooglePlistProd) && fs.existsSync(sourceGooglePlistDev)) {
3503-
if (fs.existsSync(destinationGooglePlist)) { fs.unlinkSync(destinationGooglePlist); }
3504-
resolve();
3505-
} else { // single GoogleService-Info.plist modus
3450+
var sourceGooglePlist = path.join($projectData.appResourcesDirectoryPath, "iOS", "GoogleService-Info.plist");
3451+
if (!fs.existsSync(sourceGooglePlist)) {
3452+
$logger.warn(sourceGooglePlist + " does not exist. Please follow the installation instructions from the documentation");
3453+
return reject();
3454+
} else {
35063455
resolve();
35073456
}
35083457
} else {
@@ -3520,118 +3469,9 @@ return new Promise(function(resolve, reject) {
35203469
}
35213470
fs.mkdirSync(afterPrepareDirPath);
35223471
}
3523-
fs.writeFileSync(scriptPath, afterPrepareScriptContent);
3524-
} catch(e) {
3525-
console.log("Failed to install google-service.json after-prepare copy hook.");
3526-
console.log(e);
3527-
}
3528-
3529-
/*
3530-
Install before-checkForChanges hook
3531-
*/
3532-
3533-
console.log("Install google-service.json before-checkForChanges copy hook.");
3534-
try {
3535-
var beforeCheckForChangesContent =
3536-
`
3537-
var path = require("path");
3538-
var fs = require("fs");
3539-
3540-
module.exports = function($logger, $projectData, hookArgs) {
3541-
return new Promise(function(resolve, reject) {
3542-
3543-
/* Decide whether to prepare for dev or prod environment */
3544-
3545-
var isReleaseBuild = hookArgs['checkForChangesOpts']['projectData']['$options']['argv']['release'] || false;
3546-
var validProdEnvs = ['prod','production'];
3547-
var isProdEnv = false; // building with --env.prod or --env.production flag
3548-
3549-
var env = hookArgs['checkForChangesOpts']['projectData']['$options']['argv']['env'];
3550-
if (env) {
3551-
Object.keys(env).forEach((key) => {
3552-
if (validProdEnvs.indexOf(key)>-1) { isProdEnv=true; }
3553-
});
3554-
}
3555-
3556-
var buildType = isReleaseBuild || isProdEnv ? 'production' : 'development';
3557-
3558-
/*
3559-
Detect if we have nativescript-plugin-firebase temp file created during after-prepare hook, so we know
3560-
for which environment {development|prod} the project was prepared. If needed, we delete the NS .nsprepareinfo
3561-
file so we force a new prepare
3562-
*/
3563-
var platform = hookArgs['checkForChangesOpts']['platform'].toLowerCase(); // ios | android
3564-
var platformsDir = hookArgs['checkForChangesOpts']['projectData']['platformsDir'];
3565-
var appResourcesDirectoryPath = hookArgs['checkForChangesOpts']['projectData']['appResourcesDirectoryPath'];
3566-
var forcePrepare = true; // whether to force NS to run prepare
3567-
var npfInfoPath = path.join(platformsDir, platform, ".pluginfirebaseinfo");
3568-
var nsPrepareInfoPath = path.join(platformsDir, platform, ".nsprepareinfo");
3569-
var copyPlistOpts = { platform, appResourcesDirectoryPath, buildType, $logger }
3570-
3571-
if (fs.existsSync(npfInfoPath)) {
3572-
var npfInfo = undefined;
3573-
try { npfInfo = JSON.parse(fs.readFileSync(npfInfoPath, 'utf8')); }
3574-
catch (e) { $logger.info('nativescript-plugin-firebase: error reading '+npfInfoPath); }
3575-
3576-
if (npfInfo && npfInfo.hasOwnProperty('buildType') && npfInfo.buildType===buildType) {
3577-
$logger.info('nativescript-plugin-firebase: building for same environment, not forcing prepare.');
3578-
forcePrepare=false;
3579-
}
3580-
} else { $logger.info('nativescript-plugin-firebase: '+npfInfoPath+' not found, forcing prepare!'); }
3581-
3582-
if (forcePrepare && fs.existsSync(nsPrepareInfoPath)) {
3583-
$logger.info('nativescript-plugin-firebase: running release build or change in environment detected, forcing prepare!');
3584-
3585-
if (fs.existsSync(npfInfoPath)) { fs.unlinkSync(npfInfoPath); }
3586-
fs.unlinkSync(nsPrepareInfoPath);
3587-
3588-
if (copyPlist(copyPlistOpts)) { resolve(); } else { reject(); }
3589-
} else { if (copyPlist(copyPlistOpts)) { resolve(); } else { reject(); } }
3590-
});
3591-
};
3592-
3593-
/*
3594-
Handle preparing of Google Services files for iOS
3595-
*/
3596-
var copyPlist = function(copyPlistOpts) {
3597-
if (copyPlistOpts.platform === 'android') { return true; }
3598-
else if (copyPlistOpts.platform === 'ios') {
3599-
var sourceGooglePlistProd = path.join(copyPlistOpts.appResourcesDirectoryPath, "iOS", "GoogleService-Info.plist.prod");
3600-
var sourceGooglePlistDev = path.join(copyPlistOpts.appResourcesDirectoryPath, "iOS", "GoogleService-Info.plist.dev");
3601-
var destinationGooglePlist = path.join(copyPlistOpts.appResourcesDirectoryPath, "iOS", "GoogleService-Info.plist");
3602-
3603-
// if we have both dev/prod versions, we copy (or overwrite) GoogleService-Info.plist in destination dir
3604-
if (fs.existsSync(sourceGooglePlistProd) && fs.existsSync(sourceGooglePlistDev)) {
3605-
if (copyPlistOpts.buildType==='production') { // use prod version
3606-
copyPlistOpts.$logger.out("nativescript-plugin-firebase: copy " + sourceGooglePlistProd + " to " + destinationGooglePlist + ".");
3607-
fs.writeFileSync(destinationGooglePlist, fs.readFileSync(sourceGooglePlistProd));
3608-
return true;
3609-
} else { // use dev version
3610-
copyPlistOpts.$logger.out("nativescript-plugin-firebase: copy " + sourceGooglePlistDev + " to " + destinationGooglePlist + ".");
3611-
fs.writeFileSync(destinationGooglePlist, fs.readFileSync(sourceGooglePlistDev));
3612-
return true;
3613-
}
3614-
} else if (!fs.existsSync(sourceGooglePlist)) { // single GoogleService-Info.plist modus but missing
3615-
copyPlistOpts.$logger.warn("nativescript-plugin-firebase: " + sourceGooglePlist + " does not exist. Please follow the installation instructions from the documentation");
3616-
return false;
3617-
} else {
3618-
return true; // single GoogleService-Info.plist modus
3619-
}
3620-
} else { return true; }
3621-
}
3622-
`;
3623-
var scriptPath = path.join(appRoot, "hooks", "before-checkForChanges", "firebase-copy-google-services.js");
3624-
var afterPrepareDirPath = path.dirname(scriptPath);
3625-
var hooksDirPath = path.dirname(afterPrepareDirPath);
3626-
if (!fs.existsSync(afterPrepareDirPath)) {
3627-
if (!fs.existsSync(hooksDirPath)) {
3628-
fs.mkdirSync(hooksDirPath);
3629-
}
3630-
fs.mkdirSync(afterPrepareDirPath);
3631-
}
3632-
fs.writeFileSync(scriptPath, beforeCheckForChangesContent);
3472+
fs.writeFileSync(scriptPath, scriptContent);
36333473
} catch(e) {
3634-
console.log("Failed to install google-service.json before-checkForChanges copy hook.");
3474+
console.log("Failed to install google-service.json copy hook.");
36353475
console.log(e);
36363476
}
36373477
}

0 commit comments

Comments
 (0)