MapActivity: set APIKey programmatically

前端 未结 4 660
礼貌的吻别
礼貌的吻别 2020-12-16 11:54

I currently use a MapActivity in my application. I use it with 2 API Keys. One for debugging, and one for \"production\"

I am fed up with changing these values in th

4条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-16 12:00

    You should use Product Flavors.

    For example:

    android {
        ...
    
    
        defaultConfig {
            minSdkVersion 8
            versionCode 10
        }
    
    
        productFlavors {
            dev {
                resValue "string", "google_maps_api_key", "DEV_API_KEY"
             }
    
            prod {
                resValue "string", "google_maps_api_key", "PROD_API_KEY"
             }
        }
    }
    

提交回复
热议问题