Android Question Two build configurations with different package names

Hamied Abou Hulaikah

Well-Known Member
Licensed User
Longtime User
Hi
According to this article ,I built two configurations NoAds and Ads with different package names, the icon copied and changed smoothly during compilation.
I have firebase google-services.json file, the package names are different, one build configuration work & the other no! because json file doesn't match second package name.
What is the approach now?
What is the command syntax?

Thanks
 

DonManfred

Expert
Licensed User
Longtime User
I have firebase google-services.json file, the package names are different, one build configuration work & the other no! because json file doesn't match second package name.
You can copy the content of the FirebaseAnalytics library (the file Firebase.b4x_excluded) and add them in case of the Macro to your App.

B4X:
#if app1  
CreateResourceFromFile("google-services", "google-services.json")
#end if
#if app2
CreateResourceFromFile("google-services", "google-services-app2.json")
#end if
AddPermission(android.permission.ACCESS_NETWORK_STATE)
AddPermission(android.permission.INTERNET)
AddPermission(android.permission.WAKE_LOCK)
AddPermission(com.google.android.c2dm.permission.RECEIVE)
AddPermission(${applicationId}.permission.C2D_MESSAGE)
AddPermission(com.google.android.finsky.permission.BIND_GET_INSTALL_REFERRER_SERVICE)
AddManifestText( <permission android:name="${applicationId}.permission.C2D_MESSAGE"
  android:protectionLevel="signature" />)
AddApplicationText(
 <receiver
            android:name="com.google.android.gms.measurement.AppMeasurementReceiver"
            android:enabled="true"
            android:exported="false" >
        </receiver>

  <service
            android:name="com.google.android.gms.measurement.AppMeasurementService"
            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.AppMeasurementJobService"
            android:enabled="true"
            android:exported="false"
            android:permission="android.permission.BIND_JOB_SERVICE" />

 <service android:name="com.google.firebase.components.ComponentDiscoveryService" >
            <meta-data
                android:name="com.google.firebase.components:com.google.firebase.analytics.connector.internal.AnalyticsConnectorRegistrar"
                android:value="com.google.firebase.components.ComponentRegistrar" />
             <meta-data
                android:name="com.google.firebase.components:com.google.firebase.iid.Registrar"
                android:value="com.google.firebase.components.ComponentRegistrar" />
             <meta-data
                android:name="com.google.firebase.components:com.google.firebase.auth.FirebaseAuthRegistrar"
                android:value="com.google.firebase.components.ComponentRegistrar" />
             <meta-data
                android:name="com.google.firebase.components:com.google.firebase.storage.StorageRegistrar"
                android:value="com.google.firebase.components.ComponentRegistrar" />
            <meta-data
                android:name="com.google.firebase.components:com.google.firebase.firestore.FirestoreRegistrar"
                android:value="com.google.firebase.components.ComponentRegistrar"/>

            <meta-data
                    android:name="com.google.firebase.components:com.google.firebase.database.DatabaseRegistrar"
                    android:value="com.google.firebase.components.ComponentRegistrar"/>
</service>
   <provider
  android:authorities="${applicationId}.firebaseinitprovider"
  android:name="com.google.firebase.provider.FirebaseInitProvider"
  android:exported="false"
  android:initOrder="100" />
 
   <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" />
  <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
  <category android:name="${applicationId}" />
  </intent-filter>
  </receiver>
    <receiver
  android:name="com.google.firebase.iid.FirebaseInstanceIdInternalReceiver"
  android:exported="false" />


  <service
  android:name="com.google.firebase.iid.FirebaseInstanceIdService"
  android:exported="true">
  <intent-filter android:priority="-500">
  <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
  </intent-filter>
  </service>
)

You can add conditional compiling line around the CreateResourceFromFile line to support different json files. I did it in the code above already.

Another solution would be to have the different packagenames in ONE Firebase project. This is what i am doing.
For my tests i am using a lot of packagenames for different firebase projects i have. But all of them are Grouped in ONE Firebaseproject. So, now when i download a json file from Firebase console i get one json file with all the different packagenames i have in this Firebaseproject.
The json file contains all infos about all apps and i do not need to use the solution above.
 
Upvote 0

Hamied Abou Hulaikah

Well-Known Member
Licensed User
Longtime User
Thank you @DonManfred
I solved it by another short approach.
I made folder called "googlejsons" inside the project root, then added the 2 jsons files inside it.
then added these commands:
B4X:
#If NoAds
   #CustomBuildAction: 1, c:\windows\system32\cmd.exe, /c copy ..\googlejsons\google-services-pro.json ..\google-services.json
    #End If
    #If Ads
   #CustomBuildAction: 1, c:\windows\system32\cmd.exe, /c copy ..\googlejsons\google-services.json ..\google-services.json
    #End If
 
Upvote 0
Top