Dilip Kumar
Dilip Kumar

Reputation: 51

Protect the hardcoded values (api key) in Java code of Android

I have hardcoded string (APIkey) in my Java code (APK) but it can be easily decompiled by many tools. I know I can protect by encryption. But what if the hacker decompile my Java and find out the encryption and decryption code? Is there any better way to do that?

Upvotes: 2

Views: 1182

Answers (1)

Damanpreet Singh
Damanpreet Singh

Reputation: 726

You should add your keys in build.gradle file. These files are not included in your apk. Infact these are just used to sign your application and create a release build.

signingConfigs {
    release {
      storeFile file("../myapp.jks")
      storePassword "mypassword"
      keyAlias "My_App"
      keyPassword "mykeypassword"
    }
    debug {
      storeFile file('../debug.keystore')
      storePassword 'android'
      keyAlias 'androiddebugkey'
      keyPassword 'android'
    }
  }
  buildTypes {
    release {
      minifyEnabled false
      debuggable false
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
      signingConfig signingConfigs.release
    }
    debug{
      debuggable true
      minifyEnabled false
      signingConfig signingConfigs.debug
    }
  }

Upvotes: 1

Related Questions