Skip to content
This repository has been archived by the owner on May 17, 2022. It is now read-only.

A.4. Initialize Firebase in your app

MyFlashLabs edited this page Apr 5, 2020 · 18 revisions

Initialize Firebase in your app

Initializing Firebase in your AdobeAIR project is super easy. First you should import the core Firebase package:

import com.myflashlab.air.extensions.firebase.core.*;

Then, simply call:

Firebase.init();
  • Firebase must be initialized in your app as soon as possible. The best location for initializing the Firebase ANE, is in the constructor function of your app document-class.

  • The Firebase.init(); method returns a Boolean value which indicates if the ANE has been able to correctly locate the Firebase config files. If you have not yet added the config files to your project, make sure to read this Wiki.

  • If you are trying to enable DynamicLinks in your app, you need to pass true to the Firebase init method. Firebase.init(true);

  • FirebaseAuth ANE, has many APIs based on DynamicLinks ANE. To avoid unpredicted errors, implement DynamicLinks to your app prior to implementing the Auth ANE.

  • If you want to use the phone number authentcation with the FirebaseAuth ANE, you need to have activated the FCM ANE first.

  • Run your app on a real device not on a simulator.


Before running your app, you should make sure your AIR manifest .xml file is configured correctly. The firebaseCore.ane requires you to configure your manifest file as follow. Other Firebase features may need additional setups which will be explained in their own documentations.

<!--
FOR ANDROID:
-->
<manifest android:installLocation="auto">
	
	<uses-permission android:name="android.permission.INTERNET"/>
	<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.WAKE_LOCK"/>
	<uses-sdk android:targetSdkVersion="28"/>
	
	<!-- Required by the googlePlayServices_measurementBase.ane -->
    <uses-permission android:name="com.google.android.finsky.permission.BIND_GET_INSTALL_REFERRER_SERVICE"/>

    <!-- Required by firebase_iid.ane -->
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
	
    <!-- Activate multidex for older Android support -->
	<application android:name="android.support.multidex.MultiDexApplication">
		
		<activity>
			<intent-filter>
				<action android:name="android.intent.action.MAIN" />
				<category android:name="android.intent.category.LAUNCHER" />
			</intent-filter>
			<intent-filter>
				<action android:name="android.intent.action.VIEW" />
				<category android:name="android.intent.category.BROWSABLE" />
				<category android:name="android.intent.category.DEFAULT" />
				
				<!-- Change "[YOUR_APP_PACKAGE_NAME]" to your own app package name -->
				<data android:scheme="[YOUR_APP_PACKAGE_NAME]" />
			</intent-filter>
		</activity>

		<!-- Required by the googlePlayServices_measurementBase.ane -->
        <receiver
            android:name="com.google.android.gms.measurement.AppMeasurementReceiver"
            android:enabled="true"
            android:exported="false"/>
        <receiver
            android:name="com.google.android.gms.measurement.AppMeasurementInstallReferrerReceiver"
            android:enabled="true"
            android:exported="true"
            android:permission="android.permission.INSTALL_PACKAGES">
            <intent-filter>
                <action android:name="com.android.vending.INSTALL_REFERRER"/>
            </intent-filter>
        </receiver>
        <service
            android:name="com.google.android.gms.measurement.AppMeasurementService"
            android:enabled="true"
            android:exported="false"/>
        <service
            android:name="com.google.android.gms.measurement.AppMeasurementJobService"
            android:enabled="true"
            android:exported="false"
            android:permission="android.permission.BIND_JOB_SERVICE"/>
		
		<!-- Required by googlePlayServices_basement.ane -->
        <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"/>

        <!-- 
            Required by androidx_lifecycle.ane 
            Change "[YOUR_APP_PACKAGE_NAME]" to your own app package name
        -->
        <provider
            android:name="androidx.lifecycle.ProcessLifecycleOwnerInitializer"
            android:authorities="[YOUR_APP_PACKAGE_NAME].lifecycle-process"
            android:exported="false"
            android:multiprocess="true"/>

        <!-- 
			Required by the firebase_common.ane 
			Change "[YOUR_APP_PACKAGE_NAME]" to your own app package name
		-->
		<provider
			android:name="com.google.firebase.provider.FirebaseInitProvider"
			android:authorities="[YOUR_APP_PACKAGE_NAME].firebaseinitprovider"
			android:exported="false"
			android:initOrder="100" />
			
		<service android:name="com.google.firebase.components.ComponentDiscoveryService" android:exported="false">

            <!-- Required by firebase_iid.ane -->
            <meta-data
                android:name="com.google.firebase.components:com.google.firebase.iid.Registrar"
                android:value="com.google.firebase.components.ComponentRegistrar"/>

            <!-- Required by googlePlayServices_measurementBase.ane -->
            <meta-data
                android:name="com.google.firebase.components:com.google.firebase.analytics.connector.internal.AnalyticsConnectorRegistrar"
                android:value="com.google.firebase.components.ComponentRegistrar"/>

        </service>

        <!-- Required by firebase_iid.ane -->
        <receiver
            android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver"
            android:exported="true"
            android:permission="com.google.android.c2dm.permission.SEND">
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE"/>
            </intent-filter>
        </receiver>
        
		
		<!-- Required by googlePlayServices_base.ane -->
		<activity android:name="com.google.android.gms.common.api.GoogleApiActivity"
                  android:theme="@android:style/Theme.Translucent.NoTitleBar"
                  android:exported="false"/>
		
	</application>
</manifest>





<!--
FOR iOS:
-->
	<InfoAdditions>
		
		<!--iOS 10.0 or higher can support this ANE-->
		<key>MinimumOSVersion</key>
		<string>10.0</string>
		
	</InfoAdditions>
	
	
	
	
	
<!--
Embedding the ANE:
-->
  <extensions>
	
	<!-- FirebaseCore ANE -->
    <extensionID>com.myflashlab.air.extensions.firebase.core</extensionID>

    <!-- Dependency ANEs for FirebaseCore -->
    <extensionID>com.myflashlab.air.extensions.dependency.overrideAir</extensionID>
        <extensionID>com.myflashlab.air.extensions.dependency.androidx.arch</extensionID>
        <extensionID>com.myflashlab.air.extensions.dependency.androidx.core</extensionID>
        <extensionID>com.myflashlab.air.extensions.dependency.androidx.lifecycle</extensionID>
        <extensionID>com.myflashlab.air.extensions.dependency.firebase.analytics</extensionID>
        <extensionID>com.myflashlab.air.extensions.dependency.firebase.common</extensionID>
        <extensionID>com.myflashlab.air.extensions.dependency.firebase.iid</extensionID>
        <extensionID>com.myflashlab.air.extensions.dependency.firebase.measurement.connector</extensionID>
        <extensionID>com.myflashlab.air.extensions.dependency.googlePlayServices.base</extensionID>
        <extensionID>com.myflashlab.air.extensions.dependency.googlePlayServices.basement</extensionID>
        <extensionID>com.myflashlab.air.extensions.dependency.googlePlayServices.measurementBase</extensionID>
        <extensionID>com.myflashlab.air.extensions.dependency.googlePlayServices.ads</extensionID>
        <extensionID>com.myflashlab.air.extensions.dependency.googlePlayServices.stats</extensionID>
        <extensionID>com.myflashlab.air.extensions.dependency.googlePlayServices.tasks</extensionID>
	
  </extensions>
-->

Introduction to Firebase ANEs collection for Adobe Air apps


Get Started with Firebase Core in AIR

  1. Prerequisites
  2. Add Firebase to your app
  3. Add the Firebase SDK
  4. Init Firebase Core
  5. Available ANEs
  6. Managing Firebase iid

Get Started with Analytics

  1. Add Analytics ANE
  2. Init Analytics ANE
  3. Log Events
  4. Set User Properties

Get Started with Crashlytics

  1. Add Crashlytics ANE
  2. Test Your Implementation
  3. Customize Crash Reports
  4. Upload .dSYM for iOS apps

Get Started with DynamicLinks

  1. Add DynamicLinks ANE
  2. Init DynamicLinks ANE
  3. Create DynamicLinks
  4. Receive DynamicLinks
  5. View Analytics

Get Started with Authentication

  1. Add Authentication
  2. Init Authentication
  3. Manage Users
  4. Phone Number
  5. Custom Auth
  6. Anonymous Auth
  7. State in Email Actions
  8. Email Link Authentication

Get Started with FCM + OneSignal

  1. Add FCM ANE
  2. Init FCM ANE
  3. Send Your 1st Message
  4. Send Msg to Topics
  5. Understanding FCM Messages
  6. init OneSignal

Get Started with Firestore

  1. Add Firestore
  2. Init Firestore
  3. Add Data
  4. Transactions & Batches
  5. Delete Data
  6. Manage the Console
  7. Get Data
  8. Get Realtime Updates
  9. Simple and Compound
  10. Order and Limit Data
  11. Paginate Data
  12. Manage Indexes
  13. Secure Data
  14. Offline Data
  15. Where to Go From Here

Get Started with Realtime Database

  1. Add Realtime Database
  2. Init Realtime Database
  3. Structure Your Database
  4. Save Data
  5. Retrieve Data
  6. Enable Offline Capabilities

Get Started with Remote Config

  1. Parameters and Conditions
  2. Add Remote Config
  3. Init Remote Config

Get Started with Performance

  1. Add Performance ANE
  2. Init & Start Monitoring

Get Started with Storage

  1. Add Storage ANE
  2. Init Storage ANE
  3. Upload Files to Storage
  4. Download Files to Air
  5. Use File Metadata
  6. Delete Files

Get Started with Functions

  1. Write & Deploy Functions
  2. Add Functions ANE
  3. Init Functions
Clone this wiki locally