1

Experts,

for security reasons we decided not to use the google-services.json and set the FirebaseApp DEFAULT parameters manually. I'm following the blog post here. We're using firebase sdk versions 10.2.6.

Although I'm able to successfully set the FirebaseApp DEFAULT parameters, I still get an error message: Missing google_app_id. Firebase Analytics disabled.

As you can see from the code below, I'm checking the API key after I set it so it seems that part is correct.

Any ideas greatly appreciated!

In my AndroidManifest.xml:

<provider
    android:name="com.google.firebase.provider.FirebaseInitProvider"
    android:authorities="${applicationId}.firebaseinitprovider"
    tools:node="remove"
    />
<provider
    android:name="com.company.myapp.CustomFirebaseInitProvider"
    android:authorities="${applicationId}.firebaseinitprovider"
    />

My Custom Content Provider:

public class CustomFirebaseInitProvider extends ContentProvider{

    public CustomFirebaseInitProvider() {
    }

    public void attachInfo(Context var1, ProviderInfo var2) {
        super.attachInfo(var1, var2);
    }
    public boolean onCreate() {

        // Set custom options
        FirebaseOptions.Builder builder = new FirebaseOptions.Builder()
                .setApiKey("valid_key")
                .setApplicationId("valid_app_id")
                .setGcmSenderId("valid_sender_id")
                .setDatabaseUrl("valid_db_url")
                .setStorageBucket("valid_storage_bucket");


        if(FirebaseApp.initializeApp(this.getContext(), builder.build()) == null) {
            Log.i("FirebaseInitProvider", "FirebaseApp initialization unsuccessful");
        } else {
            Log.i("FirebaseInitProvider", "FirebaseApp initialization successful");
        }

        List<FirebaseApp> appList = FirebaseApp.getApps(this.getContext());
        for (int i=0; i< appList.size(); i++)
        {
            FirebaseApp app = appList.get(i);
            String apiKey = app.getOptions().getApiKey();
            Log.d("TAG",apiKey);
        }

        return false;
    }


    @Nullable
    public Cursor query(Uri var1, String[] var2, String var3, String[] var4, String var5) {
        return null;
    }

    @Nullable
    public String getType(Uri var1) {
        return null;
    }

    @Nullable
    public Uri insert(Uri var1, ContentValues var2) {
        return null;
    }

    public int delete(Uri var1, String var2, String[] var3) {
        return 0;
    }

    public int update(Uri var1, ContentValues var2, String var3, String[] var4) {
        return 0;
    }

}
checkmate711
  • 3,301
  • 2
  • 35
  • 45
  • Seems like the firebase sdk is still looking for the params in the string.xml. If I include valid key manually in my strings.xml, I get past the error. However, why doesn't it get the key from the FirebaseOptions.Builder? – checkmate711 Aug 08 '17 at 00:37
  • the error message is coming from a class under com.google.android.gms.internal, so a Google Play Services error. – checkmate711 Aug 08 '17 at 10:30
  • since it's `google_app_id` and not an api key, I would guess it's safe to add it manually to strings.xml. exposing the app id isn't as bad as exposing the api key. – Raphael C Dec 11 '22 at 12:39

1 Answers1

0

Here is a workaround that seems to work.

In the strings.xml define some placeholder values for the firebase/google keys you will be replacing at runtime. That way, you can get past the 'missing google_api_id' error. However, the google_app_id value needs to be valid.

<!-- Placeholder Values for Firebase. Will be replaced by decrypted keys at runtime -->
<string name="google_app_id">valid_app_id</string>
<string name="google_api_key">xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</string>
<string name="google_crash_reporting_api_key">xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</string>
<string name="google_storage_bucket">xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</string>
checkmate711
  • 3,301
  • 2
  • 35
  • 45
  • I don't understand how it will work. I tried your solution, but if I put google_app_id in string resource file, then that id won't be replaced at runtime. – rMozes Aug 09 '17 at 07:01
  • right. My solution is for protecting the google_api_key to pretect it from misuse. – checkmate711 Aug 09 '17 at 17:43