How to integrate the Google services JSON file into Android Studio?

Step 1: Create a new Android project

To begin integrating Google services into your Android app, you’ll need to create a new Android project in Android Studio. Follow these steps to create a new project:

  1. Download and install the latest version of Android Studio from the official website.
  2. Open Android Studio and click on "Create New Project".
  3. Select "Android" as the project type and click "Next".
  4. Choose a project name, company domain, and location for your project files. You can also select the minimum SDK version for your app.
  5. Click "Finish" to create the new project.

    Step 2: Add dependencies

    The next step in integrating Google services is to add the necessary dependencies to your project. You will need to add the following dependencies to your app-level build.gradle file:
    groovy
    dependencies {
    implementation ‘com.google.android.gms:play-services-ads:18.0.0’
    implementation ‘com.google.android.gms:play-services-auth:18.0.0’
    implementation ‘com.google.android.gms:play-services-location:18.0.0’
    implementation ‘com.google.android.gms:play-services-maps:17.0.1’
    }

These dependencies will provide you with access to various Google services, including ads, authentication, location, and maps. You can customize the list of dependencies based on your project requirements.

Step 3: Configure Google Services Console

The next step is to configure your Google Services Console account. Go to the console and create a new project or select an existing one that you want to integrate with your app. In the dashboard, go to APIs & Services > Credentials and create a new API key. This will be used to authenticate your application with the Google services you want to integrate.

Step 4: Add JSON file to Android Studio project

Step 4: Add JSON file to Android Studio project
Once you have configured the Google Services Console, it’s time to add the JSON file to your Android Studio project. The JSON file contains the configuration for your Google services, including the API key, client ID, and other settings. To add the JSON file to your project, follow these steps:

  1. Download the JSON file from your Google Services Console account.
  2. In Android Studio, go to File > Project Structure.
  3. Navigate to the src/main/res folder.
  4. Create a new folder named "values" and navigate to it.
  5. Create a new subfolder named "strings" and navigate to it.
  6. Right-click on the empty space and select "New" > "Value".
  7. Name the value "GoogleServices-Info.json" and click "Next".
  8. Drag the JSON file you downloaded in step 1 into the newly created value.

    Step 5: Initialize Google Services

    Now that you have added the JSON file to your project, it’s time to initialize the Google services in your code. To do this, add the following code snippet to your MainActivity.java file:
    java
    private static final String GOOGLE_TAGS_LIB_NAME "GoogleTagsLib";
    private static final String GOOGLE_TAGS_INITIALIZER "com.google.android.gms.ads.AdsInitializer";
    private static final String APPLICATION_ID "YOUR_APPLICATION_ID"; // Replace with your application ID
    private static final String MAPS_API_KEY "YOUR_MAPS_API_KEY"; // Replace with your Maps API key
    public class MainActivity extends AppCompatActivity {
    private TextView mTextView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mTextView  findViewById(R.id.textView);
    
    // Initialize Google Ads SDK
    MobileAds.initialize("YOUR_ADS_ID", new OnInitializationCompleteListener() {
        @Override
        public void onInitializationComplete(MobileAdsInitializationResult result) {
            mTextView.setText("Google Ads SDK initialized");
        }
    });
    
    // Initialize Google Maps SDK
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.API_17 &&
        Build.VERSION.SDK_INT < Build.VERSION_CODES.API_24) {
        mTextView.setText("Google Maps SDK initialized");
        MapsInitializer.initialize(MainActivity.this);
    } else if (Build.VERSION.SDK_INT > Build.VERSION_CODES.API_24) {
        MapFragment.showMap(getFragmentManager(), GOOGLE_TAGS_LIB_NAME,
                GOOGLE_TAGS_INITIALIZER, APPLICATION_ID, MAPS_API_KEY);
    } else {
        mTextView.setText("Google Maps SDK not available");
    }

    }
    }

Replace the placeholders with your actual application ID and API keys. This code initializes the Google Ads SDK and Google Maps SDK, based on the device’s operating system version.

Step 6: Configure Google Services

Now that you have initialized the Google services in your code, it’s time to configure them according to your project requirements. For example, you can configure the ads to display specific categories or target specific locations. You can also configure the maps to show a custom location or zoom level. To do this, follow these steps:

  1. Go to the Google Services Console and select an existing project or create a new one that you want to integrate with your app.
  2. In the dashboard, go to APIs & Services > Credentials and click on "Create credentials".
  3. Select "API key" as the credential type and click "Next".
  4. Enter a name for the API key and select the "HTTP referrers" option. You can add any URLs or domains that your app will use to access the Google services.
  5. Click "Create" to create the API key.
  6. In your Android Studio project, go to res/values/strings.xml and add the following code:
    xml
    <meta-data
    android:name="com.google.android.geo.API_KEY"
    android:value="YOUR_MAPS_API_KEY"/>

Replace the placeholders with your actual API key. This code sets the Google Maps API key in the AndroidManifest.xml file.

  1. Go to the Google Services Console and select your project. In the dashboard, go to APIs & Services > Dashboard.
  2. Click on "Select an application" and select your app.
  3. Click on "Configure APIs & Services" and click on "Google Maps JavaScript API".
  4. Select the desired map options and