From 13249857c7303d44b9a2ca92d2604a27e949bad9 Mon Sep 17 00:00:00 2001 From: Russell Wheatley Date: Wed, 10 Jun 2020 14:59:27 +0100 Subject: [PATCH] fix(android): generate version for ReactNativeFirebaseAppRegistrar.java (#3766) * build(android): script for version * chore(android): rm ReactNativeFirebaseAppRegistrar * build(android): create new version class * chore(android): update script file name * chore(app, android): formatting Co-authored-by: Mike Diarmid [publish] --- .gitignore | 3 +- .../app/ReactNativeFirebaseAppRegistrar.java | 14 ++++---- packages/app/package.json | 3 +- packages/app/scripts/genversion-android.js | 36 +++++++++++++++++++ 4 files changed, 46 insertions(+), 10 deletions(-) create mode 100644 packages/app/scripts/genversion-android.js diff --git a/.gitignore b/.gitignore index 55b847e6c7..8b89b8a527 100644 --- a/.gitignore +++ b/.gitignore @@ -549,8 +549,9 @@ tests/ios/resetXcode.sh google-services.json GoogleService-Info.plist -# generated file +# generated files RNFBVersion.m +ReactNativeFirebaseVersion.java appPlaygrounds/ app.playground.js diff --git a/packages/app/android/src/reactnative/java/io/invertase/firebase/app/ReactNativeFirebaseAppRegistrar.java b/packages/app/android/src/reactnative/java/io/invertase/firebase/app/ReactNativeFirebaseAppRegistrar.java index 521a2e036e..65f490bea5 100644 --- a/packages/app/android/src/reactnative/java/io/invertase/firebase/app/ReactNativeFirebaseAppRegistrar.java +++ b/packages/app/android/src/reactnative/java/io/invertase/firebase/app/ReactNativeFirebaseAppRegistrar.java @@ -26,17 +26,15 @@ import java.util.Collections; import java.util.List; -import io.invertase.firebase.BuildConfig; - @Keep public class ReactNativeFirebaseAppRegistrar implements ComponentRegistrar { @Override public List> getComponents() { - return Collections.singletonList( - LibraryVersionComponent.create( - "react-native-firebase", - BuildConfig.VERSION_NAME - ) - ); + return Collections + .singletonList( + LibraryVersionComponent.create( + "react-native-firebase", + ReactNativeFirebaseVersion.VERSION + )); } } diff --git a/packages/app/package.json b/packages/app/package.json index 10ab61e6c1..3ac64f9fa0 100644 --- a/packages/app/package.json +++ b/packages/app/package.json @@ -6,7 +6,8 @@ "main": "lib/index.js", "types": "lib/index.d.ts", "scripts": { - "build": "genversion --semi lib/version.js && node ./scripts/genversion-ios", + "build": "genversion --semi lib/version.js && npm run build:version", + "build:version": "node ./scripts/genversion-ios && node ./scripts/genversion-android", "build:clean": "rimraf android/build && rimraf ios/build", "prepare": "npm run build" }, diff --git a/packages/app/scripts/genversion-android.js b/packages/app/scripts/genversion-android.js new file mode 100644 index 0000000000..ccda19ed0a --- /dev/null +++ b/packages/app/scripts/genversion-android.js @@ -0,0 +1,36 @@ +const fs = require('fs'); +const path = require('path'); + +const version = require('../lib/version'); +const outputPath = path.resolve( + __dirname, + '..', + 'android', + 'src/reactnative/java/io/invertase/firebase/app', + 'ReactNativeFirebaseVersion.java', +); +const template = ` +package io.invertase.firebase.app; +/* + * Copyright (c) 2016-present Invertase Limited & Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this library except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +// generated file - do not modify or commit +public class ReactNativeFirebaseVersion { + public static String VERSION = "version_number"; +} +`; + +fs.writeFileSync(outputPath, template.replace('version_number', `${version}`), 'utf8');