skip to Main Content

I want to hide my AdMob App ID and Ad unit ID from the version control. I have tried making a separate file to store keys and then reading that file in java. But since I have to use App ID in Android Manifest, I can’t do that.
How do I achieve this?

2

Answers


  1. The simple answer is no you can’t. You have to store App Id somewhere in the string and set it in the manifest as you can’t change it on the run-time.

    The best thing you can do is, store ad ids in the native c++ and retrieve them on runtime.

    Someone can still find your ad ids, but it’s harder than finding them from the dex classes or string XML, as they show them as plain text.

    Login or Signup to reply.
  2. Old question, but I found a nice solution.

    You can use secrets gradle plugin for android develop by google, this plugin has been designed for google maps api key, but you can use with whatever key that you want to hide.

    There are some warning too:

    DISCLAIMER: This plugin is primarily for hiding your keys from version control. Since your key is part of the static binary, your API keys are still recoverable by decompiling an APK. So, securing your key using other measures like adding restrictions (if possible) are recommended.

    When you add the plugin you need write in local.properties the admob app id like this

    ADMOB_APP_ID="ca-app-pub-XXXXXX~XXXXX"
    

    Finally in the manifest put the variable with this format:

    <meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="${ADMOB_APP_ID}" />
    

    And that’s it’s all, the app working with hiding admob id

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search