arkana icon indicating copy to clipboard operation
arkana copied to clipboard

Guide to use Arkana for android

Open vatsaltanna-simformsolutions opened this issue 1 year ago • 2 comments

I'm trying to securely store google maps api key using Arkana for android. I have generated the necessary files for it. As google maps requires api key to be added in android manifest file, how can I access kotlin classes generated by the Arkana in the AndroidManifest.xml?

Same question here

emilianoschiavone avatar Apr 04 '25 15:04 emilianoschiavone

I honestly don't know enough about Android + Google Maps to be able to answer your question with assertion. So here's ChatGPT's answer on this topic:


You’re correct that Google Maps requires the API key to be added directly in the AndroidManifest.xml, which unfortunately limits your ability to use Arkana (or any other code-level secret manager) for this particular case.

The Android manifest doesn’t support referencing Kotlin classes or runtime values — it expects values to be hardcoded or injected at build time.

That said, here are a few alternative approaches you can consider:

🛠️ Option 1: Manifest Placeholder + Gradle Property

You can store the API key as a gradle.properties entry (or better yet, an environment variable) and inject it into your AndroidManifest.xml like this:

build.gradle:

android {
    defaultConfig {
        manifestPlaceholders = [
            googleMapsApiKey: System.getenv("GOOGLE_MAPS_API_KEY") ?: ""
        ]
    }
}

AndroidManifest.xml:

<meta-data
    android:name="com.google.android.geo.API_KEY"
    android:value="${googleMapsApiKey}" />

This way, the key is not committed to source control and you can manage it outside your app.

🔐 Option 2: Arkana + Maps SDK at Runtime (If You Use Maps Programmatically)

If you’re not relying on the approach, and instead programmatically initialize the Maps SDK, you can retrieve the secret from Arkana’s generated class at runtime:

MapsInitializer.initialize(context, MapsInitializer.Renderer.LATEST) {
    MapsInitializer.setApiKey(Secrets.GoogleMapsApiKey)
}

But again — this only works if you’re not depending on the manifest-based initialization.


Let me know if this works out for you! I'm also curious 🙏

rogerluan avatar Apr 09 '25 02:04 rogerluan