How to mock Gradle buildConfigField to build Travis CI?

I am trying to integrate an Android app with Travis CI. My application needs an api key that should not be sent to the repo. So, I put the api key in the global gradle properties file ~/.gradle/gradle.properties:

MY_SECRET_API_KEY="aaaabbbcccdddeeefff"

Then I read this value in the file app/build.gradle(which is in the open repository) and set it as the buildconfig field:

apply plugin: 'com.android.application'

android {

    // ...

    buildTypes.each {
        it.buildConfigField "String", "API_KEY", MY_SECRET_API_KEY
    }

    // ...
}

and use this api key in the application code by contacting BuildConfig.API_KEY.

I get the following error message from Travic CI: Could not find property "MY_SECRET_API_KEY" on com.android.build.gradle.AppExtension_Decorated.

+4
1

Travis; , . env Tavis gradle script System.getenv('key'). . gradle.properties, - :

hasProperty('secret_api_key') ? secret_api_key: System.getenv('secret_api_key')

envis Travis, . : enter image description here

+1

Source: https://habr.com/ru/post/1619675/


All Articles