Android: automatically choose debug/release Maps v2 api key?

后端 未结 4 750
攒了一身酷
攒了一身酷 2020-11-27 14:43

I\'m using Google Maps v2 API in my project. In Google Maps v2 the debug/release API key is defined in AndroidManifest.xml. I have seen the link but in that map

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-27 15:21

    For organizations that need to maintain separate keys, you can place them in separate directories in Android Studio. Make sure the subdirectory of src you use matches a flavor or buildType

    From Building Your Project with Gradle:

    To build each version of your app, the build system combines source code and resources from:
    
    src/main/ - the main source directory (common to all variants)
    src// - the build type source directory
    src// - the flavor source directory
    

    In projectroot/yourapp/build.gradle:

    buildTypes {
        debug {
            runProguard false
            debuggable true
    
        }
        release {
            runProguard true
            debuggable false
            ...
        }
    

    In projectroot/yourapp/src/main/AndroidManifest.xml:

    ...
    
    
    ...
    

    In projectroot/yourapp/src/debug/AndroidManifest.xml, fully qualify the name of the app.

    
        
            
        
    
    

    In projectroot/yourapp/src/release/AndroidManifest.xml:

    
        
            
        
    
    

提交回复
热议问题