How to tell Gradle to use a different AndroidManifest from the command line?

后端 未结 1 1552
攒了一身酷
攒了一身酷 2020-12-08 08:32

I have a multi-module project. From the root of my project (which contains multiple modules), I want to be able to call \'gradle build\' and have it use a different AndroidM

相关标签:
1条回答
  • 2020-12-08 09:05

    I solved this by using different build types.

    Here's my build.gradle:

    buildscript {
        repositories {
            mavenCentral()
        }
    
        dependencies {
            classpath 'com.android.tools.build:gradle:0.4.2'
       }
    }
    
    apply plugin: 'android'
    
    dependencies {
        compile project(':facebook-android-sdk-3.0.1:facebook')
        compile project(':google-play-services_lib')
        compile project(':nineoldandroids')
        compile project(':SlidingMenu-master:library')
        compile project(':ViewPagerIndicator')
        compile project(':volley')
        compile project(':windowed-seek-bar')
        compile files('compile-libs/androidannotations-2.7.1.jar', 'libs/Flurry_3.2.1.jar', 'libs/google-play-services.jar', 'libs/gson-2.2.4.jar', 'libs/picasso-1.1.1.jar', 'libs/crittercism_v3_0_11_sdkonly.jar', 'libs/gcm.jar', 'libs/apphance-library.jar')
    }
    
    android {
        buildToolsVersion "17.0"
        compileSdkVersion 17
    
        signingConfigs {
            debug {
                storeFile file('keystores/debug.keystore')
            }
        }
    
        buildTypes {
            debug {
                sourceSets {
                    main {
                        manifest.srcFile 'AndroidManifest.xml'
                        java.srcDirs = ['src']
                        resources.srcDirs = ['src']
                        aidl.srcDirs = ['src']
                        renderscript.srcDirs = ['src']
                        res.srcDirs = ['res']
                        assets.srcDirs = ['assets']
                    }
                }
            }
    
            release {
                zipAlign true
                sourceSets {
                    main {
                        manifest.srcFile 'AndroidManifest.xml'
                        java.srcDirs = ['src']
                        resources.srcDirs = ['src']
                        aidl.srcDirs = ['src']
                        renderscript.srcDirs = ['src']
                        res.srcDirs = ['res']
                        assets.srcDirs = ['assets']
                    }
                }
            }
    
            utest {
                debuggable true
                signingConfig signingConfigs.debug
    
                sourceSets {
                    main {
                        manifest.srcFile 'utest/AndroidManifest.xml'
                        java.srcDirs = ['src']
                        resources.srcDirs = ['src']
                        aidl.srcDirs = ['src']
                        renderscript.srcDirs = ['src']
                        res.srcDirs = ['res']
                        assets.srcDirs = ['assets']
                    }
                }
            }
        }
    }
    

    You can see that for my utest build, I'm specifying a manifest in a different directory. works.

    0 讨论(0)
提交回复
热议问题